Skip to content

Commit

Permalink
build: add docker image based on java binary
Browse files Browse the repository at this point in the history
add graalvm build arg -march=compatibility

related-to: #482
  • Loading branch information
fhussonnois committed Aug 30, 2024
1 parent 95b105f commit 194f4dd
Show file tree
Hide file tree
Showing 3 changed files with 224 additions and 94 deletions.
262 changes: 178 additions & 84 deletions .github/workflows/docker-build-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,90 +17,184 @@ env:
GRAAL_VERSION: '21.0.1'
GRAAL_DISTRIBUTION: 'graalvm-community'
jobs:
build:
build-cli:
if: github.repository == 'streamthoughts/jikkou'
name: 'Build Docker Image'
name: 'Build Docker Image (CLI Native)'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: docker/setup-buildx-action@v3

- name: 'Set up GraalVM'
uses: graalvm/setup-graalvm@v1
with:
# version: ${{ env.GRAAL_VERSION }}
java-version: ${{ env.JAVA_VERSION }}
github-token: ${{ secrets.GITHUB_TOKEN }}
components: 'native-image'
native-image-job-reports: 'true'
native-image-musl: 'true'

- 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: |
echo "VERSION=$(./mvnw org.apache.maven.plugins:maven-help-plugin:3.1.0:evaluate -Dexpression=project.version -q -DforceStdout)" >> $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
- name: 'Build Native Executable (Jikkou CLI)'
run: |
chmod +x ./mvnw && \
./mvnw -ntp -B clean package -Pnative -Dgraalvm.build.arg="--static --libc=musl" -DskipTests && \
cp ./cli/target/jikkou-cli-${{ env.VERSION }}-runner ./docker/jikkou-cli-${{ env.VERSION }}-runner
- name: 'Build & Push to Docker Hub (Jikkou CLI)'
if: github.ref_name == 'main'
uses: docker/build-push-action@v6
with:
context: docker
platforms: linux/amd64,linux/arm64
file: docker/Dockerfile
no-cache: true
push: true
tags: streamthoughts/jikkou:main
build-args: |
VERSION=${{ env.VERSION }}
COMMIT=${{ env.GIT_COMMIT }}
BRANCH=${{ env.GIT_BRANCH }}
CREATED=${{ env.CREATED }}
- name: 'Build & Push to Docker Hub (Jikkou CLI)'
if: startsWith(github.ref, 'refs/tags/v')
uses: docker/build-push-action@v6
with:
context: docker
platforms: linux/amd64,linux/arm64
file: docker/Dockerfile
no-cache: true
push: true
tags: streamthoughts/jikkou:${{ env.VERSION }},streamthoughts/jikkou:latest
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: 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
- 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
- uses: actions/checkout@v4
- uses: docker/setup-buildx-action@v3

- name: 'Set up GraalVM'
uses: graalvm/setup-graalvm@v1
with:
# version: ${{ env.GRAAL_VERSION }}
java-version: ${{ env.JAVA_VERSION }}
github-token: ${{ secrets.GITHUB_TOKEN }}
components: 'native-image'
native-image-job-reports: 'true'
native-image-musl: 'true'

- 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: |
echo "VERSION=$(./mvnw org.apache.maven.plugins:maven-help-plugin:3.1.0:evaluate -Dexpression=project.version -q -DforceStdout)" >> $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
- name: 'Build Native Executable'
run: |
chmod +x ./mvnw && \
./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'
if: github.ref_name == 'main'
uses: docker/build-push-action@v6
with:
context: docker
platforms: linux/amd64,linux/arm64
file: docker/Dockerfile
no-cache: true
push: true
tags: streamthoughts/jikkou:main
build-args: |
VERSION=${{ env.VERSION }}
COMMIT=${{ env.GIT_COMMIT }}
BRANCH=${{ env.GIT_BRANCH }}
CREATED=${{ env.CREATED }}
- name: 'Build & Push to Docker Hub'
if: startsWith(github.ref, 'refs/tags/v')
uses: docker/build-push-action@v6
with:
context: docker
platforms: linux/amd64,linux/arm64
file: docker/Dockerfile
no-cache: true
push: true
tags: streamthoughts/jikkou:${{ env.VERSION }},streamthoughts/jikkou:latest
build-args: |
VERSION=${{ env.VERSION }}
COMMIT=${{ env.GIT_COMMIT }}
BRANCH=${{ env.GIT_BRANCH }}
CREATED=${{ env.CREATED }}
build-cli-java:
if: github.repository == 'streamthoughts/jikkou'
name: 'Build Docker Image (CLI Java Binary)'
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: |
echo "VERSION=$(./mvnw org.apache.maven.plugins:maven-help-plugin:3.1.0:evaluate -Dexpression=project.version -q -DforceStdout)" >> $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
- name: 'Build Java Binary Executable'
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'
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'
if: startsWith(github.ref, 'refs/tags/v')
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 }}
build-server:
if: github.repository == 'streamthoughts/jikkou'
name: 'Build Docker Image (Server)'
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
IMAGE="streamthoughts/jikkou-api-server:latest"
TAGS="$VERSION"
else
IMAGE="streamthoughts/jikkou-api-server:main"
TAGS=""
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="${{ env.IMAGE }}" \
-Djib.to.tags="${{ env.TAGS }}"
docker image push --all-tags streamthoughts/jikkou-api-server
43 changes: 43 additions & 0 deletions docker/Dockerfile_java
Original file line number Diff line number Diff line change
@@ -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"]


13 changes: 3 additions & 10 deletions docker/Dockerfile.ubuntu → docker/Dockerfile_ubuntu
Original file line number Diff line number Diff line change
@@ -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 \
Expand Down

0 comments on commit 194f4dd

Please sign in to comment.