From 4d8a6d5d8ee3092112e0b8b51c6a7a776a0a241d Mon Sep 17 00:00:00 2001 From: Daniel Meier Date: Wed, 3 Apr 2024 00:26:18 +0200 Subject: [PATCH] Publish JVM Based Docker Images As a quick-fix for native ARM64 Support for Apple Silicon, JVM based Images are now published for both x86 and ARM. --- .github/workflows/check.yml | 14 +++--------- .github/workflows/publish.yml | 35 +++++++++++++++++++++++------- README.md | 4 ++++ app/build.gradle.kts | 9 ++++++-- app/src/main/docker/Dockerfile.jvm | 23 ++++++++++++++++++++ 5 files changed, 64 insertions(+), 21 deletions(-) create mode 100644 app/src/main/docker/Dockerfile.jvm diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 778483a..4982619 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -15,24 +15,16 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Set up JDK - uses: actions/setup-java@v3 + uses: actions/setup-java@v4 with: distribution: 'temurin' java-version: '21' - name: Setup Gradle - uses: gradle/gradle-build-action@v2 + uses: gradle/actions/setup-gradle@v3 - name: Run Gradle 'build' Task run: ./gradlew build - - #- name: Copy OpenAPI Specification - # run: ./gradlew copyOpenApiSpec - - #- name: Build Svelte App - # uses: docker/build-push-action@v4 - #with: - #context: web \ No newline at end of file diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 9ecb5f4..b9c7c33 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -1,25 +1,31 @@ -name: Publish Docker image +name: Publish Artifacts on: release: types: [ released, prereleased ] jobs: - push_to_registry: - name: Push Docker images to Docker Hub + publish_artifacts: + name: Publish Artifacts runs-on: ubuntu-latest steps: - name: Check out - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Set up JDK - uses: actions/setup-java@v3 + uses: actions/setup-java@v4 with: distribution: 'temurin' java-version: '21' - name: Setup Gradle - uses: gradle/gradle-build-action@v2 + uses: gradle/actions/setup-gradle@v3 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 - name: Log in to Docker Hub uses: docker/login-action@v3 @@ -27,8 +33,13 @@ jobs: username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_PASSWORD }} - - name: Build and Push Backend Image - run: ./gradlew build -Dquarkus.native.compression.level=9 -Dquarkus.container-image.push=true + - name: Build and Push Native Image + env: + QUARKUS_CONTAINER_IMAGE_BUILD: true + QUARKUS_CONTAINER_IMAGE_PUSH: true + QUARKUS_PACKAGE_TYPE: native + QUARKUS_NATIVE_COMPRESSION_LEVEL: 9 + run: ./gradlew clean build - name: Copy Linux Binary to Temporary Folder run: cp app/build/tsa-*-runner $RUNNER_TEMP/tsa-linux-amd64 @@ -43,6 +54,14 @@ jobs: asset_name: tsa-linux-amd64 asset_content_type: application/octet-stream + - name: Build and Push JVM Images + env: + QUARKUS_CONTAINER_IMAGE_BUILD: true + QUARKUS_CONTAINER_IMAGE_PUSH: true + QUARKUS_PACKAGE_TYPE: jar + QUARKUS_DOCKER_BUILDX_PLATFORM: linux/amd64,linux/arm64 + run: ./gradlew clean build -PimageTagSuffix=jvm + - name: Update Docker Hub description if: ${{ github.event.action == 'released' }} uses: peter-evans/dockerhub-description@v3 diff --git a/README.md b/README.md index 3d3f250..5e954fc 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,10 @@ volume to the `/work/data` will make the DB data persistent. The keystore containing the certificate and private key used to sign the requests with is loaded from `/work/keystore.p12` by default. +There are two Docker Image variants: _Native_ and _JVM_. +Native Images (e.g. `dnl50/tsa-server:3.1.0`) are only available for `x86-64`. The JVM variant +(e.g. `dnl50/tsa-server:3.1.0-jvm`) is available for `x86-64` and `arm64`. + ## Features ### Time Stamping diff --git a/app/build.gradle.kts b/app/build.gradle.kts index bb68b61..cb00094 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -84,9 +84,14 @@ spotless { quarkus { set("native.container-build", "true") - set("container-image.build", "true") set("container-image.group", "dnl50") set("container-image.name", "tsa-server") - set("package.type", "native") + set("container-image.tag", objects.property().value(provider { + if (project.hasProperty("imageTagSuffix")) { + "${project.version}-${project.property("imageTagSuffix")}" + } else { + project.version.toString() + } + })) finalName.set("tsa-${project.version}") } diff --git a/app/src/main/docker/Dockerfile.jvm b/app/src/main/docker/Dockerfile.jvm new file mode 100644 index 0000000..1a81c6c --- /dev/null +++ b/app/src/main/docker/Dockerfile.jvm @@ -0,0 +1,23 @@ +# Based on Quarkus' Dockerfile.jvm template for Gradle +FROM registry.access.redhat.com/ubi8/openjdk-21-runtime:1.19 + +ENV LANGUAGE='en_US:en' + +# We make four distinct layers so if there are application changes the library layers can be re-used +COPY --chown=185 build/quarkus-app/lib/ /deployments/lib/ +COPY --chown=185 build/quarkus-app/*.jar /deployments/ +COPY --chown=185 build/quarkus-app/app/ /deployments/app/ +COPY --chown=185 build/quarkus-app/quarkus/ /deployments/quarkus/ + +USER root +RUN mkdir -p /work/data \ + && chown -R 185:root /work + +EXPOSE 8080 +USER 185 +ENV JAVA_OPTS_APPEND="-Dquarkus.http.host=0.0.0.0 -Djava.util.logging.manager=org.jboss.logmanager.LogManager" +ENV JAVA_APP_JAR="/deployments/quarkus-run.jar" + +VOLUME ["/work/data"] + +ENTRYPOINT [ "/opt/jboss/container/java/run/run-java.sh" ] \ No newline at end of file