From a4cd58e52445c8598a5d2a13eeb4c805d7efbd2b Mon Sep 17 00:00:00 2001 From: Merlin Unterfinger Date: Wed, 29 May 2024 13:34:52 +0200 Subject: [PATCH 1/3] ENH: NAV-72 - Add Dockerfile - Build image of the Spring service. - Use a two stage build. --- Dockerfile | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..d1fa08ad --- /dev/null +++ b/Dockerfile @@ -0,0 +1,13 @@ +FROM openjdk:21-jdk-slim AS build +WORKDIR /app +COPY .mvn/ .mvn +COPY mvnw pom.xml ./ +RUN ./mvnw dependency:go-offline -B +COPY src ./src +RUN ./mvnw clean package -DskipTests + +FROM openjdk:21-jdk-slim +WORKDIR /app +COPY --from=build /app/target/*.jar app.jar +EXPOSE 8080 +ENTRYPOINT ["java", "-jar", "app.jar"] From c751e833021789dba6d1d094875ae4f01ba15821 Mon Sep 17 00:00:00 2001 From: Merlin Unterfinger Date: Wed, 29 May 2024 17:23:20 +0200 Subject: [PATCH 2/3] ORG: NAV-72 - Add and update GitHub actions - Maven build and publish on semver tags. - Docker build and publish on semver tags. - Set version to already tagged v0.1.0 Closes #11 --- .github/workflows/docker-ci.yml | 19 ++++++++++++++++ .github/workflows/docker-publish.yml | 30 +++++++++++++++++++++++++ .github/workflows/maven-ci.yml | 29 ++++++++---------------- .github/workflows/maven-publish.yml | 33 ++++++++++++++++++++++++++++ pom.xml | 10 ++++++++- 5 files changed, 100 insertions(+), 21 deletions(-) create mode 100644 .github/workflows/docker-ci.yml create mode 100644 .github/workflows/docker-publish.yml create mode 100644 .github/workflows/maven-publish.yml diff --git a/.github/workflows/docker-ci.yml b/.github/workflows/docker-ci.yml new file mode 100644 index 00000000..823af29e --- /dev/null +++ b/.github/workflows/docker-ci.yml @@ -0,0 +1,19 @@ +name: Docker CI + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + - name: Build image + run: | + COMMIT_HASH=$(git rev-parse --short HEAD) + IMAGE_TAG=ghcr.io/${{ github.repository_owner }}/${{ github.repository }}:${COMMIT_HASH} + docker build . --file Dockerfile --tag $IMAGE_TAG diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml new file mode 100644 index 00000000..e8f59400 --- /dev/null +++ b/.github/workflows/docker-publish.yml @@ -0,0 +1,30 @@ +name: Docker publish + +on: + push: + branches: [ "main" ] + tags: + - 'v[0-9]+\.[0-9]+\.[0-9]+(-.*)?' + +jobs: + publish: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + + steps: + - uses: actions/checkout@v4 + - name: Set up environment variables + run: echo "IMAGE_TAG=ghcr.io/${{ github.repository_owner }}/${{ github.repository }}:${{ github.event.release.tag_name }}" >> $GITHUB_ENV + + - name: Login to ghcr + run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin + + - name: Build image + run: | + docker build . --file Dockerfile --tag $IMAGE_TAG + + - name: Push image to ghcr + run: | + docker push $IMAGE_TAG diff --git a/.github/workflows/maven-ci.yml b/.github/workflows/maven-ci.yml index 86a37869..f26e03af 100644 --- a/.github/workflows/maven-ci.yml +++ b/.github/workflows/maven-ci.yml @@ -1,12 +1,4 @@ -# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time -# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-maven - -# This workflow uses actions that are not certified by GitHub. -# They are provided by a third-party and are governed by -# separate terms of service, privacy policy, and support -# documentation. - -name: Java CI with Maven +name: Maven CI on: push: @@ -16,20 +8,17 @@ on: jobs: build: - runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - name: Set up JDK 21 - uses: actions/setup-java@v3 + - uses: actions/checkout@v4 + - name: Setup + uses: actions/setup-java@v4 with: + distribution: 'openjdk' java-version: '21' - distribution: 'temurin' - cache: maven - - name: Build with Maven - run: mvn -B verify --file pom.xml + cache: 'maven' - # Optional: Uploads the full dependency graph to GitHub to improve the quality of Dependabot alerts this repository can receive - # - name: Update dependency graph - # uses: advanced-security/maven-dependency-submission-action@571e99aab1055c2e71a1e2309b9691de18d6b7d6 + - name: Build + # use verify instead of package to include integration tests + run: mvn -B verify --file pom.xml diff --git a/.github/workflows/maven-publish.yml b/.github/workflows/maven-publish.yml new file mode 100644 index 00000000..0206de09 --- /dev/null +++ b/.github/workflows/maven-publish.yml @@ -0,0 +1,33 @@ +name: Maven publish + +on: + push: + branches: [ "main" ] + tags: + - 'v[0-9]+\.[0-9]+\.[0-9]+(-.*)?' + +jobs: + publish: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + + steps: + - uses: actions/checkout@v4 + - name: Setup + uses: actions/setup-java@v4 + with: + distribution: 'openjdk' + java-version: '21' + cache: 'maven' + server-id: github # Value of the distributionManagement/repository/id field of the pom.xml + settings-path: ${{ github.workspace }} # location for the settings.xml file + + - name: Build + run: mvn -B package --file pom.xml + + - name: Publish + run: mvn deploy -s $GITHUB_WORKSPACE/settings.xml + env: + GITHUB_TOKEN: ${{ github.token }} diff --git a/pom.xml b/pom.xml index f21054b9..9f796cd3 100644 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,7 @@ ch.naviqore public-transit-service - 1.0.0-SNAPSHOT + 0.1.0 Public Transit Service @@ -47,6 +47,14 @@ https://github.com/naviqore/public-transit-service + + + github + GitHub Packages + https://maven.pkg.github.com/naviqore/public-transit-service + + + UTF-8 21 From 8fff7393c841b888b16c4710bc20333224c0729d Mon Sep 17 00:00:00 2001 From: Merlin Unterfinger Date: Wed, 29 May 2024 17:29:25 +0200 Subject: [PATCH 3/3] FIX: NAV-72 - Set distribution to temurin and change docker image name --- .github/workflows/docker-ci.yml | 2 +- .github/workflows/maven-ci.yml | 2 +- .github/workflows/maven-publish.yml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/docker-ci.yml b/.github/workflows/docker-ci.yml index 823af29e..ac3895d2 100644 --- a/.github/workflows/docker-ci.yml +++ b/.github/workflows/docker-ci.yml @@ -15,5 +15,5 @@ jobs: - name: Build image run: | COMMIT_HASH=$(git rev-parse --short HEAD) - IMAGE_TAG=ghcr.io/${{ github.repository_owner }}/${{ github.repository }}:${COMMIT_HASH} + IMAGE_TAG=ghcr.io/${{ github.repository }}:${COMMIT_HASH} docker build . --file Dockerfile --tag $IMAGE_TAG diff --git a/.github/workflows/maven-ci.yml b/.github/workflows/maven-ci.yml index f26e03af..f2bd0149 100644 --- a/.github/workflows/maven-ci.yml +++ b/.github/workflows/maven-ci.yml @@ -15,7 +15,7 @@ jobs: - name: Setup uses: actions/setup-java@v4 with: - distribution: 'openjdk' + distribution: 'temurin' java-version: '21' cache: 'maven' diff --git a/.github/workflows/maven-publish.yml b/.github/workflows/maven-publish.yml index 0206de09..4af18b3e 100644 --- a/.github/workflows/maven-publish.yml +++ b/.github/workflows/maven-publish.yml @@ -18,7 +18,7 @@ jobs: - name: Setup uses: actions/setup-java@v4 with: - distribution: 'openjdk' + distribution: 'temurin' java-version: '21' cache: 'maven' server-id: github # Value of the distributionManagement/repository/id field of the pom.xml