From f2987f2a76014fe02ed2e76aa83e40fb96a2cd02 Mon Sep 17 00:00:00 2001 From: Florian Hussonnois Date: Fri, 30 Aug 2024 22:26:42 +0200 Subject: [PATCH] build: add docker image based on java binary add graalvm build arg -march=compatibility related-to: #482 --- .github/workflows/docker-build-push.yml | 105 ++++++++++++++---- docker/Dockerfile_java | 43 +++++++ .../{Dockerfile.ubuntu => Dockerfile_ubuntu} | 13 +-- 3 files changed, 131 insertions(+), 30 deletions(-) create mode 100644 docker/Dockerfile_java rename docker/{Dockerfile.ubuntu => Dockerfile_ubuntu} (63%) diff --git a/.github/workflows/docker-build-push.yml b/.github/workflows/docker-build-push.yml index 30bb36917..0a85c2582 100644 --- a/.github/workflows/docker-build-push.yml +++ b/.github/workflows/docker-build-push.yml @@ -17,7 +17,7 @@ env: GRAAL_VERSION: '21.0.1' GRAAL_DISTRIBUTION: 'graalvm-community' jobs: - build: + build-cli: if: github.repository == 'streamthoughts/jikkou' name: 'Build Docker Image' runs-on: ubuntu-latest @@ -51,10 +51,16 @@ jobs: - name: 'Build Native Executable (Jikkou CLI)' run: | chmod +x ./mvnw && \ - ./mvnw -ntp -B clean package -Pnative -Dgraalvm.build.arg="--static --libc=musl" -DskipTests && \ + ./mvnw -ntp -B clean package -Pnative -Dgraalvm.build.arg="--static --libc=musl --verbose -march=compatibility" -DskipTests && \ cp ./cli/target/jikkou-cli-${{ env.VERSION }}-runner ./docker/jikkou-cli-${{ env.VERSION }}-runner - - name: 'Build & Push to Docker Hub (Jikkou CLI)' + - name: 'Build Java Binary Executable (Jikkou CLI)' + run: | + chmod +x ./mvnw && \ + ./mvnw -ntp -B --file pom.xml -Pdist package -DskipTests && \ + cp -r ./dist/jikkou-${{ env.VERSION }}-java-binary ./docker + + - name: 'Build & Push to Docker Hub (Jikkou CLI Native)' if: github.ref_name == 'main' uses: docker/build-push-action@v6 with: @@ -70,7 +76,23 @@ jobs: BRANCH=${{ env.GIT_BRANCH }} CREATED=${{ env.CREATED }} - - name: 'Build & Push to Docker Hub (Jikkou CLI)' + - name: 'Build & Push to Docker Hub (Jikkou CLI Java)' + if: github.ref_name == 'main' + uses: docker/build-push-action@v6 + with: + context: docker + platforms: linux/amd64,linux/arm64 + file: docker/Dockerfile_java + no-cache: true + push: true + tags: streamthoughts/jikkou:main-java + build-args: | + VERSION=${{ env.VERSION }} + COMMIT=${{ env.GIT_COMMIT }} + BRANCH=${{ env.GIT_BRANCH }} + CREATED=${{ env.CREATED }} + + - name: 'Build & Push to Docker Hub (Jikkou CLI Native)' if: startsWith(github.ref, 'refs/tags/v') uses: docker/build-push-action@v6 with: @@ -86,21 +108,64 @@ jobs: BRANCH=${{ env.GIT_BRANCH }} CREATED=${{ env.CREATED }} - - name: 'Build & Push to Docker Hub (Jikkou API Server)' + - name: 'Build & Push to Docker Hub (Jikkou CLI Java)' if: github.ref_name == 'main' - run: | - ./mvnw -ntp -B install -DskipTests && \ - ./mvnw -ntp -B package -DskipTests -f ./server/jikkou-api-server/pom.xml \ - -Dpackaging=docker \ - -Djib.to.image=streamthoughts/jikkou-api-server:main - docker image push --all-tags streamthoughts/jikkou-api-server + uses: docker/build-push-action@v6 + with: + context: docker + platforms: linux/amd64,linux/arm64 + file: docker/Dockerfile_java + no-cache: true + push: true + tags: streamthoughts/jikkou:${{ env.VERSION }}-java,streamthoughts/jikkou:latest-java + build-args: | + VERSION=${{ env.VERSION }} + COMMIT=${{ env.GIT_COMMIT }} + BRANCH=${{ env.GIT_BRANCH }} + CREATED=${{ env.CREATED }} - - name: 'Build & Push to Docker Hub (Jikkou API Server)' - if: startsWith(github.ref, 'refs/tags/v') - run: | - ./mvnw -ntp -B install -DskipTests && \ - ./mvnw -ntp -B package -DskipTests -f ./server/jikkou-api-server/pom.xml \ - -Dpackaging=docker \ - -Djib.to.image=streamthoughts/jikkou-api-server:${{ env.VERSION }} \ - -Djib.to.tags=latest - docker image push --all-tags streamthoughts/jikkou-api-server + build-server: + if: github.repository == 'streamthoughts/jikkou' + name: 'Build Docker Image' + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: docker/setup-buildx-action@v3 + + - name: 'Set up Java' + - uses: actions/setup-java@v4 + with: + distribution: ${{ env.JAVA_DISTRO }} + java-version: ${{ env.JAVA_VERSION }} + + - name: 'Login to DockerHub' + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: 'Set Docker Image Build-Args' + run: | + + VERSION=$(./mvnw org.apache.maven.plugins:maven-help-plugin:3.1.0:evaluate -Dexpression=project.version -q -DforceStdout) + echo "VERSION=${VERSION}" >> $GITHUB_ENV + echo "GIT_BRANCH=${GITHUB_REF#refs/heads/}" >> $GITHUB_ENV + echo "GIT_COMMIT=$(git rev-parse --short "$GITHUB_SHA")" >> $GITHUB_ENV + echo "CREATED=$(date --rfc-3339=seconds)" >> $GITHUB_ENV + + GIT_BRANCH=${GITHUB_REF#refs/*/} + if [[ $GIT_BRANCH == v* ]]; then + TAGS="$VERSION,latest" + else + TAGS="main" + fi + echo "TAGS=$TAGS" >> $GITHUB_ENV + + - name: 'Build & Push to Docker Hub (Jikkou API Server)' + run: | + ./mvnw -ntp -B install -DskipTests && \ + ./mvnw -ntp -B package -DskipTests -f ./server/jikkou-api-server/pom.xml \ + -Dpackaging=docker \ + -Djib.to.image=streamthoughts/jikkou-api-server \ + -Djib.to.tags=${{ env.TAGS }} + docker image push --all-tags streamthoughts/jikkou-api-server diff --git a/docker/Dockerfile_java b/docker/Dockerfile_java new file mode 100644 index 000000000..4d1b1f735 --- /dev/null +++ b/docker/Dockerfile_java @@ -0,0 +1,43 @@ +# +# SPDX-License-Identifier: Apache-2.0 +# Copyright (c) The original authors +# +# Licensed under the Apache Software License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 +# +FROM eclipse-temurin:21.0.4_7-jdk-ubi9-minimal + +LABEL org.opencontainers.image.title=jikkou \ + org.opencontainers.image.licenses=Apache-2.0 \ + org.opencontainers.image.url=https://streamthoughts.github.io/jikkou/ \ + org.opencontainers.image.documentation=https://streamthoughts.github.io/jikkou/ \ + org.opencontainers.image.source=https://github.com/streamthoughts/jikkou + +ARG VERSION +ARG CREATED +ARG COMMIT + +ENV USER_ID=10000 \ + GROUP_ID=10001 \ + USER_NAME="appuser" \ + GROUP_NAME="appuser" \ + JIKKOUCONFIG="/etc/jikkou/config" + +RUN mkdir -p /etc/jikkou/ + +WORKDIR /app + +RUN groupadd -g $GROUP_ID $GROUP_NAME && \ + useradd -r -s /bin/false -u $USER_ID -g $USER_NAME $GROUP_NAME && \ + chown $USER_NAME:$GROUP_NAME /app + +USER $USER_NAME + +COPY --chmod=0755 ./jikkou-${VERSION}-java-binary/* . + +LABEL org.opencontainers.image.created=$CREATED \ + org.opencontainers.image.version=$VERSION \ + org.opencontainers.image.revision=$COMMIT + +ENTRYPOINT ["./bin/jikkou"] + + diff --git a/docker/Dockerfile.ubuntu b/docker/Dockerfile_ubuntu similarity index 63% rename from docker/Dockerfile.ubuntu rename to docker/Dockerfile_ubuntu index 01dddc5cd..2f1b8e2f0 100644 --- a/docker/Dockerfile.ubuntu +++ b/docker/Dockerfile_ubuntu @@ -1,16 +1,9 @@ -# Copyright 2023 The original authors # -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at +# SPDX-License-Identifier: Apache-2.0 +# Copyright (c) The original authors # -# http://www.apache.org/licenses/LICENSE-2.0 +# Licensed under the Apache Software License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 # -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. FROM ubuntu:20.04 LABEL org.opencontainers.image.title=jikkou \