Skip to content

Commit ff88c24

Browse files
authored
Multiarch build support (#5)
* initial multiarch build support * fix optional version_number check * fetch arch / instruction_set in run step * login to ghcr before push * push to correct package registry * fix docker download order
1 parent d280e93 commit ff88c24

6 files changed

Lines changed: 76 additions & 129 deletions

File tree

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: Build and push linux images
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
version_number:
7+
required: false
8+
type: string
9+
10+
defaults:
11+
run:
12+
shell: bash
13+
14+
jobs:
15+
build-push-linux:
16+
runs-on: [self-hosted, linux]
17+
permissions:
18+
contents: read
19+
packages: write
20+
steps:
21+
- uses: actions/checkout@v3
22+
- name: Set up QEMU
23+
uses: docker/setup-qemu-action@v3
24+
- name: Set up Docker Buildx
25+
uses: docker/setup-buildx-action@v3
26+
- name: lowercase github.repository
27+
run: |
28+
echo "IMAGE_NAME=`echo ${{github.repository}} | tr '[:upper:]' '[:lower:]'`" >>${GITHUB_ENV}
29+
- name: Docker meta
30+
uses: docker/metadata-action@v5
31+
id: meta
32+
with:
33+
images: |
34+
ghcr.io/${{ env.IMAGE_NAME }}
35+
tags: |
36+
# always release image under 'dev-ubuntu' tag
37+
type=raw,value=dev-ubuntu
38+
# release under 'latest-ubuntu' tag if set
39+
type=raw,value=latest-ubuntu,enable=${{ github.event.inputs.version_number != '' }}
40+
# release under version tag
41+
type=raw,value=${{ github.event.inputs.version_number }}-ubuntu,enable=${{ github.event.inputs.version_number != '' }}
42+
labels: |
43+
org.opencontainers.image.authors=Ableytner
44+
- name: Login to GitHub Container Registry
45+
uses: docker/login-action@v3
46+
with:
47+
registry: ghcr.io
48+
username: ${{ github.repository_owner }}
49+
password: ${{ secrets.GITHUB_TOKEN }}
50+
- name: Build and push
51+
uses: docker/build-push-action@v6
52+
with:
53+
context: ./linux
54+
platforms: linux/amd64,linux/arm64
55+
pull: true
56+
push: true
57+
tags: ${{ steps.meta.outputs.tags }}
58+
labels: ${{ steps.meta.outputs.labels }}

.github/workflows/define-build-linux-image.yaml

Lines changed: 0 additions & 28 deletions
This file was deleted.

.github/workflows/release-tagged-images.yaml

Lines changed: 5 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -11,66 +11,14 @@ defaults:
1111
shell: bash
1212

1313
jobs:
14-
build-linux:
15-
uses: ./.github/workflows/define-build-linux-image.yaml
14+
build-push-linux:
15+
uses: ./.github/workflows/build-push-linux.yaml
1616
secrets: inherit
17-
18-
tag:
19-
runs-on: self-hosted
20-
steps:
21-
- uses: mukunku/tag-exists-action@v1.6.0
22-
id: check-tag
23-
with:
24-
tag: ${{ github.event.inputs.version_number }}
25-
- name: Fail if tag exists
26-
if: steps.check-tag.outputs.exists == 'true'
27-
run: |
28-
echo "Tag ${{ github.event.inputs.version_number }} exists!"
29-
exit 1
30-
- name: Print tag if it doesn't exist
31-
if: steps.check-tag.outputs.exists == 'false'
32-
run: |
33-
echo "Tag ${{ github.event.inputs.version_number }} doesn't yet exist and can be created"
34-
35-
push-linux:
36-
needs: [tag, build-linux]
37-
runs-on: [self-hosted, linux]
38-
permissions:
39-
contents: read
40-
packages: write
41-
steps:
42-
- name: Login to GitHub Container Registry
43-
uses: docker/login-action@v3
44-
with:
45-
registry: ghcr.io
46-
username: ${{ github.repository_owner }}
47-
password: ${{ secrets.GITHUB_TOKEN }}
48-
- name: lowercase github.repository
49-
run: |
50-
echo "IMAGE_NAME=`echo ${{github.repository}} | tr '[:upper:]' '[:lower:]'`" >>${GITHUB_ENV}
51-
- name: Download cached docker image
52-
run: |
53-
curl -X GET http://192.168.0.11:25000/attachments/gha-runner/1/image_ubuntu.tar -o /tmp/image_ubuntu.tar
54-
- name: Load image
55-
run: |
56-
docker load --input /tmp/image_ubuntu.tar
57-
- name: Push
58-
run: |
59-
docker tag ${{ env.IMAGE_NAME }}:latest-ubuntu ghcr.io/${{ env.IMAGE_NAME }}:${{ github.event.inputs.version_number }}-ubuntu
60-
docker push ghcr.io/${{ env.IMAGE_NAME }}:${{ github.event.inputs.version_number }}-ubuntu
61-
docker tag ghcr.io/${{ env.IMAGE_NAME }}:${{ github.event.inputs.version_number }}-ubuntu ghcr.io/${{ env.IMAGE_NAME }}:latest-ubuntu
62-
docker push ghcr.io/${{ env.IMAGE_NAME }}:latest-ubuntu
63-
- name: Remove local image
64-
if: always()
65-
run: |
66-
docker image rm ${{ env.IMAGE_NAME }}:latest-ubuntu
67-
- name: Remove cached docker image
68-
if: always()
69-
run: |
70-
curl -X DELETE http://192.168.0.11:25000/attachments/gha-runner/1/image_ubuntu.tar
17+
with:
18+
version_number: ${{ github.event.inputs.version_number }}
7119

7220
release:
73-
needs: [tag, build-linux, push-linux]
21+
needs: [build-push-linux]
7422
runs-on: [self-hosted, linux]
7523
permissions:
7624
contents: write

.github/workflows/run-build-images.yaml

Lines changed: 2 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -7,41 +7,6 @@ on:
77
workflow_dispatch:
88

99
jobs:
10-
build-linux:
11-
uses: ./.github/workflows/define-build-linux-image.yaml
10+
build-push-linux:
11+
uses: ./.github/workflows/build-push-linux.yaml
1212
secrets: inherit
13-
14-
push:
15-
needs: [build-linux]
16-
runs-on: [self-hosted, linux]
17-
permissions:
18-
contents: read
19-
packages: write
20-
steps:
21-
- name: Login to GitHub Container Registry
22-
uses: docker/login-action@v3
23-
with:
24-
registry: ghcr.io
25-
username: ${{ github.repository_owner }}
26-
password: ${{ secrets.GITHUB_TOKEN }}
27-
- name: lowercase github.repository
28-
run: |
29-
echo "IMAGE_NAME=`echo ${{github.repository}} | tr '[:upper:]' '[:lower:]'`" >>${GITHUB_ENV}
30-
- name: Download cached docker image
31-
run: |
32-
curl -X GET http://192.168.0.11:25000/attachments/gha-runner/1/image_ubuntu.tar -o /tmp/image_ubuntu.tar
33-
- name: Load image
34-
run: |
35-
docker load --input /tmp/image_ubuntu.tar
36-
- name: Push
37-
run: |
38-
docker tag ${{ env.IMAGE_NAME }}:latest-ubuntu ghcr.io/${{ env.IMAGE_NAME }}:dev
39-
docker push ghcr.io/${{ env.IMAGE_NAME }}:dev
40-
- name: Remove local image
41-
if: always()
42-
run: |
43-
docker image rm ${{ env.IMAGE_NAME }}:latest-ubuntu
44-
- name: Remove cached docker image
45-
if: always()
46-
run: |
47-
curl -X DELETE http://192.168.0.11:25000/attachments/gha-runner/1/image_ubuntu.tar

linux/Dockerfile

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
FROM ubuntu:24.04
22

3+
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
4+
35
# NOTE: CONTAINERD_VERSION needs to stay at 1.7.28 due to:
46
# https://github.com/nestybox/sysbox/issues/973
57
ARG RUNNER_VERSION="2.331.0" \
68
CONTAINERD_VERSION="1.7.28" \
79
DOCKER_VERSION="29.1.5" \
810
BUILDX_VERSION="0.30.1" \
9-
COMPOSE_VERSION="2.40.3" \
10-
ARCH="amd64" \
11-
INSTRUCTION_SET="x64"
11+
COMPOSE_VERSION="2.40.3"
1212

1313
ARG DEBIAN_FRONTEND=noninteractive
1414

@@ -21,7 +21,8 @@ RUN apt-get update \
2121
&& chmod 777 /opt/hostedtoolcache
2222

2323
# install github actions runner
24-
RUN mkdir -p /home/runner/actions-runner \
24+
RUN INSTRUCTION_SET="$(arch | sed s/aarch64/arm64/ | sed s/x86_64/x64/)" \
25+
&& mkdir -p /home/runner/actions-runner \
2526
&& curl -L https://github.com/actions/runner/releases/download/v${RUNNER_VERSION}/actions-runner-linux-${INSTRUCTION_SET}-${RUNNER_VERSION}.tar.gz -o /home/runner/actions-runner/actions.tar.gz \
2627
&& cd /home/runner/actions-runner \
2728
&& tar -xzf actions.tar.gz \
@@ -42,7 +43,8 @@ RUN apt-get update \
4243
wget
4344

4445
# install gh cli
45-
RUN curl -L -H "Accept: application/vnd.github+json" https://api.github.com/repos/cli/cli/releases/latest \
46+
RUN ARCH="$(arch | sed s/aarch64/arm64/ | sed s/x86_64/amd64/)" \
47+
&& curl -L -H "Accept: application/vnd.github+json" https://api.github.com/repos/cli/cli/releases/latest \
4648
| jq -r '.tag_name' \
4749
| sed 's/^v//g' \
4850
> /tmp/ghcli_vers.txt \
@@ -55,9 +57,10 @@ RUN curl -L -H "Accept: application/vnd.github+json" https://api.github.com/repo
5557
&& rm /tmp/ghcli.deb
5658

5759
# install docker
58-
RUN mkdir -p /home/runner/tmp \
59-
&& cd /home/runner/tmp \
60+
RUN ARCH="$(arch | sed s/aarch64/arm64/ | sed s/x86_64/amd64/)" \
6061
&& BASE_URL="https://download.docker.com/linux/ubuntu/dists/noble/pool/stable/${ARCH}" \
62+
&& mkdir -p /home/runner/tmp \
63+
&& cd /home/runner/tmp \
6164
&& curl -L ${BASE_URL}/containerd.io_${CONTAINERD_VERSION}-1~ubuntu.24.04~noble_${ARCH}.deb -o ./containerd.io.deb \
6265
&& curl -L ${BASE_URL}/docker-ce_${DOCKER_VERSION}-1~ubuntu.24.04~noble_${ARCH}.deb -o ./docker-ce.deb \
6366
&& curl -L ${BASE_URL}/docker-ce-cli_${DOCKER_VERSION}-1~ubuntu.24.04~noble_${ARCH}.deb -o ./docker-ce-cli.deb \

linux/scripts/entrypoint.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ rm token_resp.txt
6060
--token "${REG_TOKEN}" \
6161
--name "${RUNNER_NAME:-"runner-ubuntu"}-${HOSTNAME}" \
6262
--unattended \
63+
--disableupdate \
6364
--labels "${EXTRA_LABELS:-}"
6465

6566
cleanup() {

0 commit comments

Comments
 (0)