Skip to content

Commit

Permalink
feat: add ARM build (#38)
Browse files Browse the repository at this point in the history
Fixes #37

ARM images cannot be statically linked, as there's no GraalVM for arm/v7, so the image is slightly bigger than the amd64 one.

Note: This only adds ARM docker containers, if you need a binary, use the `tgtg.jar` from the release
  • Loading branch information
hugo-vrijswijk authored Aug 17, 2023
1 parent 7da8c85 commit ce9b0aa
Show file tree
Hide file tree
Showing 3 changed files with 128 additions and 31 deletions.
142 changes: 114 additions & 28 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ permissions:
pull-requests: write
packages: write

env:
REGISTRY: ghcr.io
REGISTRY_IMAGE: ghcr.io/${{ github.repository }}

jobs:
release-please:
runs-on: ubuntu-latest
Expand All @@ -27,72 +31,113 @@ jobs:
needs: [release-please]
if: ${{ needs.release-please.outputs.release_created }}
runs-on: ${{ matrix.OS }}
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
strategy:
matrix:
OS: ["ubuntu-latest", "windows-latest", "macos-latest"]
OS: ["windows-latest", "macos-latest"]
include:
- os: macOS-latest
uploaded_filename: tgtg-x86_64-apple-darwin
local_path: artifacts/tgtg-x86_64-apple-darwin
- os: ubuntu-latest
uploaded_filename: tgtg-x86_64-pc-linux
local_path: artifacts/tgtg-x86_64-pc-linux
uploaded_filename: tgtg-macos-amd64
local_path: artifacts/tgtg-macos-amd64
- os: windows-latest
uploaded_filename: tgtg-x86_64-pc-win32.exe
local_path: artifacts/tgtg-x86_64-pc-win32.exe
uploaded_filename: tgtg-win-amd64.exe
local_path: artifacts/tgtg-win-amd64.exe
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: coursier/cache-action@v6
- uses: VirtusLab/scala-cli-setup@v1
with:
power: true
jvm: "temurin:17"
- name: Package app
run: scala-cli package . -o "${{ matrix.local_path }}" --native-image --graalvm-args -H:IncludeResources=version.txt
- uses: actions/upload-artifact@v3
with:
name: ${{ matrix.uploaded_filename }}
path: ${{ matrix.local_path }}
if-no-files-found: error
retention-days: 2
- name: Upload release artifacts
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: gh release upload ${{ needs.release-please.outputs.tag_name }} ${{ matrix.local_path }}
package-linux:
needs: [release-please]
if: ${{ needs.release-please.outputs.release_created }}
runs-on: ${{ matrix.OS }}
strategy:
matrix:
OS: ["ubuntu-latest"]
platforms:
- linux/amd64
- linux/arm/v7,linux/arm64/v8
include:
- platforms: linux/amd64
uploaded_filename: tgtg-linux-amd64
local_path: artifacts/tgtg-linux-amd64
- platforms: linux/arm/v7,linux/arm64/v8
uploaded_filename: tgtg.jar
local_path: artifacts/tgtg.jar
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Log in to the Container registry
if: matrix.OS == 'ubuntu-latest'
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Extract metadata (tags, labels) for Docker
if: matrix.OS == 'ubuntu-latest'
id: meta
uses: docker/metadata-action@v4
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=schedule
type=ref,event=branch
type=ref,event=tag
type=ref,event=pr
type=raw,value=${{ needs.release-please.outputs.tag_name }}
type=raw,value=latest
images: ${{ env.REGISTRY_IMAGE }}
- uses: coursier/cache-action@v6
- uses: VirtusLab/scala-cli-setup@v1
with:
power: true
jvm: "temurin:17"
- name: Package app
if: matrix.OS != 'ubuntu-latest'
run: scala-cli package . -o "${{ matrix.local_path }}" --native-image --graalvm-args -H:IncludeResources=version.txt
- name: Package app
if: matrix.OS == 'ubuntu-latest'
if: matrix.platforms == 'linux/amd64'
run: scala-cli package . -o "${{ matrix.local_path }}" --native-image -- -H:IncludeResources=version.txt --static
- name: Compress artifact
if: ${{ matrix.OS == 'ubuntu-latest' }}
if: matrix.platforms == 'linux/amd64'
uses: crazy-max/ghaction-upx@v2
with:
args: --best
files: ${{ matrix.local_path }}
- name: Package app
if: matrix.platforms != 'linux/amd64'
run: |
mkdir -p $(dirname "${{ matrix.local_path }}")
scala-cli package . -o "${{ matrix.local_path }}" --assembly
- name: Build and push Docker image
if: matrix.OS == 'ubuntu-latest'
uses: docker/build-push-action@v4
id: build
with:
file: ${{ matrix.platforms == 'linux/amd64' && './Dockerfile' || './arm.Dockerfile' }}
build-args: "LOCAL_PATH=${{ matrix.local_path }}"
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
platforms: ${{ matrix.platforms }}
outputs: type=image,name=${{ env.REGISTRY_IMAGE }},push-by-digest=true,name-canonical=true,push=true
- name: Export digest
run: |
mkdir -p /tmp/digests
digest="${{ steps.build.outputs.digest }}"
touch "/tmp/digests/${digest#sha256:}"
- name: Upload digest
uses: actions/upload-artifact@v3
with:
name: digests
path: /tmp/digests/*
if-no-files-found: error
retention-days: 1
- uses: actions/upload-artifact@v3
with:
name: ${{ matrix.uploaded_filename }}
Expand All @@ -103,3 +148,44 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: gh release upload ${{ needs.release-please.outputs.tag_name }} ${{ matrix.local_path }}
# https://docs.docker.com/build/ci/github-actions/multi-platform/
merge:
runs-on: ubuntu-latest
if: ${{ needs.release-please.outputs.release_created }}
needs:
- release-please
- package-linux
steps:
- name: Download digests
uses: actions/download-artifact@v3
with:
name: digests
path: /tmp/digests
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Docker meta
id: meta
uses: docker/metadata-action@v4
with:
images: ${{ env.REGISTRY_IMAGE }}
tags: |
type=schedule
type=ref,event=branch
type=ref,event=tag
type=ref,event=pr
type=raw,value=${{ needs.release-please.outputs.tag_name }}
type=raw,value=latest
- name: Log in to the Container registry
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Create manifest list and push
working-directory: /tmp/digests
run: |
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
$(printf '${{ env.REGISTRY_IMAGE }}@sha256:%s ' *)
- name: Inspect image
run: |
docker buildx imagetools inspect ${{ env.REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }}
8 changes: 5 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
FROM busybox

ARG LOCAL_PATH
WORKDIR /opt/app

ENV TINI_VERSION v0.19.0
ADD https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini /tini
RUN chmod +x /tini

COPY ${LOCAL_PATH} tgtg
ENTRYPOINT ["/tini", "--", "/tgtg"]
ARG LOCAL_PATH
COPY ${LOCAL_PATH} tgtg

ENTRYPOINT ["/tini", "--", "/opt/app/tgtg"]
9 changes: 9 additions & 0 deletions arm.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
ARG ARCH=
FROM ${ARCH}eclipse-temurin:17

WORKDIR /opt/app

ARG LOCAL_PATH
COPY ${LOCAL_PATH} tgtg.jar

ENTRYPOINT ["java", "-jar", "/opt/app/tgtg.jar"]

0 comments on commit ce9b0aa

Please sign in to comment.