Skip to content

Commit

Permalink
Merge pull request #311 from entur/github-workflow-publish
Browse files Browse the repository at this point in the history
Add github workflow to build and deploy docker image to public registry
  • Loading branch information
testower authored May 23, 2024
2 parents 07df1c9 + dedea00 commit 447f9ea
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 0 deletions.
62 changes: 62 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: CI Build

on:
push:
branches:
- master
pull_request:
branches:
- master

jobs:
tests:
runs-on: ubuntu-latest
env:
TZ: Europe/Oslo
steps:
- uses: actions/checkout@v4

# nodejs is needed because the dynamic download of it via the prettier maven plugin often
# times out
# Example: https://github.com/opentripplanner/OpenTripPlanner/actions/runs/4490450225/jobs/7897533439
- uses: actions/setup-node@v4
with:
node-version: 18

- name: Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: 21
distribution: temurin
cache: maven

- name: Run tests
run: |
sudo timedatectl set-timezone "Europe/Oslo"
mvn --batch-mode jacoco:prepare-agent test jacoco:report -Dprettier.nodePath=node -Dprettier.npmPath=npm
mvn --batch-mode jib:dockerBuild -Dmaven.test.skip -P prettierSkip
image:
# only build and push the image when it's a commit to master in Entur's repository
if: github.repository_owner == 'entur' && github.event_name == 'push'
runs-on: ubuntu-latest
needs: [ tests ]
env:
CONTAINER_REPO: docker.io/entur/uttu
CONTAINER_REGISTRY_USER: ${{ secrets.DOCKERHUB_LOGIN }}
CONTAINER_REGISTRY_PASSWORD: ${{ secrets.DOCKERHUB_PASSWORD }}
steps:
- uses: actions/checkout@v4

- name: Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: 21
distribution: temurin
cache: maven

- name: Build container image with Jib, push to container repo
run: |
image_date=`date +%Y-%m-%dT%H-%M`
mvn --batch-mode compile com.google.cloud.tools:jib-maven-plugin:build -Djib.to.tags=latest,$image_date -Dmaven.test.skip -P prettierSkip
36 changes: 36 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,42 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.google.cloud.tools</groupId>
<artifactId>jib-maven-plugin</artifactId>
<version>3.4.2</version>
<dependencies>
<!-- Include jib-spring-boot-extension-maven to prevent spring-boot-devtools from being packaged.-->
<dependency>
<groupId>com.google.cloud.tools</groupId>
<artifactId>jib-spring-boot-extension-maven</artifactId>
<version>0.1.0</version>
</dependency>
</dependencies>
<configuration>
<from>
<image>bellsoft/liberica-openjdk-alpine:21.0.3-10</image>
</from>
<to>
<image>${env.CONTAINER_REPO}</image>
<auth>
<username>${env.CONTAINER_REGISTRY_USER}</username>
<password>${env.CONTAINER_REGISTRY_PASSWORD}</password>
</auth>
</to>
<container>
<!-- Same as EXPOSE, doesn't actually publish the ports but acts as documentation -->
<ports>
<port>8080</port>
</ports>
</container>
<pluginExtensions>
<pluginExtension>
<implementation>com.google.cloud.tools.jib.maven.extension.springboot.JibSpringBootExtension</implementation>
</pluginExtension>
</pluginExtensions>
</configuration>
</plugin>
</plugins>
</build>
<profiles>
Expand Down

0 comments on commit 447f9ea

Please sign in to comment.