diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000..e93df56f --- /dev/null +++ b/.github/workflows/ci.yml @@ -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 diff --git a/pom.xml b/pom.xml index 0d6d4ce8..89cbdaf4 100644 --- a/pom.xml +++ b/pom.xml @@ -501,6 +501,42 @@ + + com.google.cloud.tools + jib-maven-plugin + 3.4.2 + + + + com.google.cloud.tools + jib-spring-boot-extension-maven + 0.1.0 + + + + + bellsoft/liberica-openjdk-alpine:21.0.3-10 + + + ${env.CONTAINER_REPO} + + ${env.CONTAINER_REGISTRY_USER} + ${env.CONTAINER_REGISTRY_PASSWORD} + + + + + + 8080 + + + + + com.google.cloud.tools.jib.maven.extension.springboot.JibSpringBootExtension + + + +