Skip to content

Fix arm64 docker fill-station image build #80

Fix arm64 docker fill-station image build

Fix arm64 docker fill-station image build #80

name: Create and publish the Fill Station Docker image
# Configures this workflow to run every time a change is pushed to the branch called `main` or a pull request to `main` is created
on:
push:
branches: ['main']
pull_request:
# Defines two custom environment variables for the workflow. These are used for the Container registry domain, and a name for the Docker image that this workflow builds.
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository_owner }}/fill-station
jobs:
build-and-test:
runs-on: ubuntu-latest
strategy:
matrix:
arch: [amd64, arm64]
steps:
- name: Prepare
run: |
platform=linux/${{ matrix.arch }}
echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
# Checks-out your repository under $GITHUB_WORKSPACE, which is the CWD for
# the rest of the steps
- name: Checkout code
uses: actions/checkout@v4
- uses: bazel-contrib/setup-bazel@0.8.5
with:
# Avoid downloading Bazel every time.
bazelisk-cache: true
# Store build cache per workflow.
disk-cache: ${{ github.workflow }}-${{ matrix.arch }}
# Share repository cache between workflows.
repository-cache: true
# test for amd64 (can't test for arm64)
- name: Build and Test with Bazel
run: |
if [[ "${{ matrix.arch }}" == "amd64" ]]; then
bazel test //fill:all
elif [[ "${{ matrix.arch }}" == "arm64" ]]; then
sudo apt-get install g++-11-arm-linux-gnueabihf
sudo apt install gcc-11-arm-linux-gnueabihf
bazel build //fill:all --platforms=platform:rpi4 --cpu="aarch64"
fi
sudo mkdir -p ./fill/output
sudo cp bazel-bin/fill/fill_station ./fill/output
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
with:
platforms: all
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
# Uses the `docker/login-action` action to log in to the Container registry registry using the account and password that will publish the packages. Once published, the packages are scoped to the account defined here.
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# This step uses [docker/metadata-action](https://github.com/docker/metadata-action#about) to extract tags and labels that will be applied to the specified image. The `id` "meta" allows the output of this step to be referenced in a subsequent step. The `images` value provides the base name for the tags and labels.
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-${{ matrix.arch }}
tags: |
type=raw,value=latest,enable={{is_default_branch}}
type=ref,event=branch,enable=${{ github.ref != 'refs/heads/main' }}
type=ref,event=pr
- name: Build and push Fill Station Docker image by digest
id: build
uses: docker/build-push-action@v6
with:
context: .
file: fill/GithubDockerfile
platforms: linux/${{ matrix.arch }}
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
build-args: |
TARGETARCH=${{ matrix.arch }}
merge:
needs: build-and-test
runs-on: ubuntu-latest
steps:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
# Uses the `docker/login-action` action to log in to the Container registry registry using the account and password that will publish the packages. Once published, the packages are scoped to the account defined here.
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# This step uses [docker/metadata-action](https://github.com/docker/metadata-action#about) to extract tags and labels that will be applied to the specified image. The `id` "meta" allows the output of this step to be referenced in a subsequent step. The `images` value provides the base name for the tags and labels.
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
tags: |
type=raw,value=latest,enable={{is_default_branch}}
type=ref,event=branch,enable=${{ github.ref != 'refs/heads/main' }}
type=ref,event=pr
- name: Create manifest list and push
run: |
docker buildx imagetools create --tag ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.meta.outputs.tags }} ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-amd64:${{ steps.meta.outputs.tags }} ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-arm64:${{ steps.meta.outputs.tags }}
- name: Inspect image
run: |
docker buildx imagetools inspect ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.meta.outputs.tags }}