Skip to content

Commit

Permalink
use github actions to build a native arm64 docker image
Browse files Browse the repository at this point in the history
  • Loading branch information
Athou committed Jan 17, 2025
1 parent 3623dc8 commit 045baba
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 53 deletions.
114 changes: 65 additions & 49 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,49 +7,98 @@ 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:
java-version: ${{ env.JAVA_VERSION }}
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
uses: actions/upload-artifact@v4
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: Set the exec flag on the native executables
run: chmod +x artifacts/*-runner

- name: Rename native executables 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
Expand All @@ -67,7 +116,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 }}
Expand All @@ -92,7 +141,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
Expand All @@ -105,46 +154,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:
Expand All @@ -160,6 +173,9 @@ jobs:
path: ./artifacts
merge-multiple: true

- name: Set the exec flag on the native executables
run: chmod +x artifacts/*-runner

- name: Extract Changelog Entry
uses: mindsers/changelog-reader-action@v2
id: changelog_reader
Expand Down
2 changes: 1 addition & 1 deletion commafeed-server/src/main/docker/Dockerfile.jvm
Original file line number Diff line number Diff line change
Expand Up @@ -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", \
Expand Down
4 changes: 3 additions & 1 deletion commafeed-server/src/main/docker/Dockerfile.native
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
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
WORKDIR /commafeed

CMD ["./application"]
3 changes: 1 addition & 2 deletions commafeed-server/src/main/docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,5 +92,4 @@ Tags are of the form `<version>-<database>[-jvm]` where:
- `latest` (always points to the latest version)
- `master` (always points to the latest git commit)
- `<database>` 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.
- `-jvm` is optional and indicates that CommaFeed is running on a JVM, and not compiled natively.

0 comments on commit 045baba

Please sign in to comment.