From d78e89811b4938756cd1f42fc7eccea706bebcf9 Mon Sep 17 00:00:00 2001 From: Athou Date: Fri, 17 Jan 2025 15:27:31 +0100 Subject: [PATCH] use github actions to build a native arm64 docker image --- .github/workflows/ci.yml | 108 ++++++++++-------- .../src/main/docker/Dockerfile.jvm | 2 +- .../src/main/docker/Dockerfile.native | 5 +- commafeed-server/src/main/docker/README.md | 3 +- 4 files changed, 65 insertions(+), 53 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3e737ee4e..1d5b52de8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,26 +7,24 @@ env: DOCKER_BUILD_SUMMARY: false jobs: - build-linux: - runs-on: ubuntu-latest + build: strategy: matrix: + os: [ "ubuntu-latest", "ubuntu-24.04-arm", "windows-latest" ] database: [ "h2", "postgresql", "mysql", "mariadb" ] + runs-on: ${{ matrix.os }} steps: # Checkout + - name: Configure git to checkout as-is + run: git config --global core.autocrlf false + - name: Checkout uses: actions/checkout@v4 with: fetch-depth: 0 # Setup - - name: Set up QEMU - uses: docker/setup-qemu-action@v3 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 - - name: Set up GraalVM uses: graalvm/setup-graalvm@v1 with: @@ -34,9 +32,13 @@ jobs: distribution: "graalvm" cache: "maven" + - name: Install Playwright dependencies + run: sudo apt-get install -y libgbm1 + if: matrix.os != 'windows-latest' + # Build & Test - name: Build with Maven - run: mvn --batch-mode --no-transfer-progress install -Pnative -P${{ matrix.database }} + run: mvn --batch-mode --no-transfer-progress install -Pnative -P${{ matrix.database }} -DskipTests=${{ matrix.os == 'windows-latest' && matrix.database != 'h2' }} # Upload artifacts - name: Upload cross-platform app @@ -44,12 +46,56 @@ jobs: with: name: commafeed-${{ matrix.database }}-jvm path: commafeed-server/target/commafeed-*.zip + overwrite: true - name: Upload native executable uses: actions/upload-artifact@v4 with: name: commafeed-${{ matrix.database }}-${{ runner.os }}-${{ runner.arch }} - path: commafeed-server/target/commafeed-*-runner + path: commafeed-server/target/commafeed-*-runner* + + docker: + needs: build + runs-on: ubuntu-latest + + strategy: + matrix: + database: [ "h2", "postgresql", "mysql", "mariadb" ] + + steps: + # Checkout + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + # Setup + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Install required packages + run: sudo apt-get install -y rename unzip + + # Prepare artifacts + - name: Download artifacts + uses: actions/download-artifact@v4 + with: + pattern: commafeed-${{ matrix.database }}-* + path: ./artifacts + merge-multiple: true + + - name: Rename native artifacts to match buildx TARGETARCH + run: | + rename 's/x86_64/amd64/g' artifacts/* + rename 's/aarch_64/arm64/g' artifacts/* + + - name: Unzip jvm package + run: | + unzip artifacts/*-jvm.zip -d artifacts/extracted-jvm-package + rename 's/commafeed-.*/quarkus-app/g' artifacts/extracted-jvm-package/* # Docker - name: Login to Container Registry @@ -67,7 +113,7 @@ jobs: context: . file: commafeed-server/src/main/docker/Dockerfile.native push: true - platforms: linux/amd64 + platforms: linux/amd64,linux/arm64/v8 tags: | athou/commafeed:latest-${{ matrix.database }} athou/commafeed:${{ github.ref_name }}-${{ matrix.database }} @@ -92,7 +138,7 @@ jobs: context: . file: commafeed-server/src/main/docker/Dockerfile.native push: true - platforms: linux/amd64 + platforms: linux/amd64,linux/arm64/v8 tags: athou/commafeed:master-${{ matrix.database }} - name: Docker build and push master - jvm @@ -105,46 +151,10 @@ jobs: platforms: linux/amd64,linux/arm64/v8 tags: athou/commafeed:master-${{ matrix.database }}-jvm - build-windows: - runs-on: windows-latest - strategy: - matrix: - database: [ "h2", "postgresql", "mysql", "mariadb" ] - - steps: - # Checkout - - name: Configure git to checkout as-is - run: git config --global core.autocrlf false - - - name: Checkout - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - # Setup - - name: Set up GraalVM - uses: graalvm/setup-graalvm@v1 - with: - java-version: ${{ env.JAVA_VERSION }} - distribution: "graalvm" - cache: "maven" - - # Build & Test - - name: Build with Maven - run: mvn --batch-mode --no-transfer-progress install -Pnative -P${{ matrix.database }} -DskipTests=${{ matrix.database != 'h2' }} - - # Upload artifacts - - name: Upload native executable - uses: actions/upload-artifact@v4 - with: - name: commafeed-${{ matrix.database }}-${{ runner.os }}-${{ runner.arch }} - path: commafeed-server/target/commafeed-*-runner.exe - release: runs-on: ubuntu-latest needs: - - build-linux - - build-windows + - build if: github.ref_type == 'tag' steps: diff --git a/commafeed-server/src/main/docker/Dockerfile.jvm b/commafeed-server/src/main/docker/Dockerfile.jvm index 7490e92ba..c6d8c5551 100644 --- a/commafeed-server/src/main/docker/Dockerfile.jvm +++ b/commafeed-server/src/main/docker/Dockerfile.jvm @@ -4,7 +4,7 @@ EXPOSE 8082 RUN mkdir -p /commafeed/data VOLUME /commafeed/data -COPY commafeed-server/target/quarkus-app/ /commafeed +COPY artifacts/extracted-jvm-package/quarkus-app/ /commafeed WORKDIR /commafeed CMD ["java", \ diff --git a/commafeed-server/src/main/docker/Dockerfile.native b/commafeed-server/src/main/docker/Dockerfile.native index 80118ad32..791b1831c 100644 --- a/commafeed-server/src/main/docker/Dockerfile.native +++ b/commafeed-server/src/main/docker/Dockerfile.native @@ -1,10 +1,13 @@ FROM debian:12.9 +ARG TARGETARCH + EXPOSE 8082 RUN mkdir -p /commafeed/data VOLUME /commafeed/data -COPY commafeed-server/target/commafeed-*-runner /commafeed/application +COPY artifacts/commafeed-*-${TARGETARCH}-runner /commafeed/application +RUN chmod +x /commafeed/application WORKDIR /commafeed CMD ["./application"] diff --git a/commafeed-server/src/main/docker/README.md b/commafeed-server/src/main/docker/README.md index 69f225760..74bce7d57 100644 --- a/commafeed-server/src/main/docker/README.md +++ b/commafeed-server/src/main/docker/README.md @@ -92,5 +92,4 @@ Tags are of the form `-[-jvm]` where: - `latest` (always points to the latest version) - `master` (always points to the latest git commit) - `` is the database to use (`h2`, `postgresql`, `mysql` or `mariadb`) -- `-jvm` is optional and indicates that CommaFeed is running on a JVM, and not compiled natively. This image supports - the arm64 platform which is not yet supported by the native image. \ No newline at end of file +- `-jvm` is optional and indicates that CommaFeed is running on a JVM, and not compiled natively.