Skip to content

Commit b9f3731

Browse files
Support multiarch images (arm64 and amd64) (#15)
1 parent 9621d2f commit b9f3731

File tree

2 files changed

+72
-25
lines changed

2 files changed

+72
-25
lines changed

.github/workflows/build-publish.yaml

Lines changed: 67 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,41 @@ on:
44
workflow_dispatch:
55
push:
66
tags:
7-
- "*"
7+
- "v*"
8+
pull_request:
9+
branches:
10+
- "main"
811

912
env:
1013
REGISTRY: ghcr.io
11-
IMAGE_NAMES: "beegfs-all\nbeegfs-mgmtd\nbeegfs-meta\nbeegfs-storage"
14+
NAMESPACE: thinkparq
15+
DOCKER_BUILDX_BUILD_PLATFORMS: "linux/amd64,linux/arm64"
1216

1317
jobs:
1418
publish-images:
1519
runs-on: ubuntu-22.04
1620
timeout-minutes: 10
21+
strategy:
22+
matrix:
23+
include:
24+
- image_name: beegfs-all
25+
- image_name: beegfs-mgmtd
26+
- image_name: beegfs-meta
27+
- image_name: beegfs-storage
1728
permissions:
1829
packages: write
1930
contents: read
2031
steps:
2132
- uses: actions/checkout@v3
33+
with:
34+
fetch-tags: true
35+
fetch-depth: 0
2236

2337
- name: Set up Docker Buildx
24-
uses: docker/setup-buildx-action@v2
38+
uses: docker/setup-buildx-action@v3
2539

2640
- name: Log in to the GitHub Container Registry
27-
uses: docker/login-action@v2
41+
uses: docker/login-action@v3
2842
with:
2943
registry: ${{ env.REGISTRY }}
3044
username: ${{ github.actor }}
@@ -35,27 +49,60 @@ jobs:
3549
with:
3650
cosign-release: "v2.1.1"
3751

38-
- name: Build, tag, sign, and push the container images to GitHub Container Registry
52+
- name: Determine what version of BeeGFS to build images for based on the last tag
53+
id: determine_beegfs_version
3954
run: |
40-
beegfs_version=$(git describe --tags --match '*.*' --abbrev=10)
41-
names=$(echo "${{ env.IMAGE_NAMES }}" | tr '\n' ' ')
42-
43-
for name in $names; do
44-
image=ghcr.io/thinkparq/${name}:${beegfs_version}
45-
docker build -t $image --build-arg BEEGFS_VERSION=${beegfs_version} --target ${name} .
46-
docker push $image
55+
last_version=$(git describe --tags --abbrev=0)
56+
echo "LAST_VERSION=$last_version" >> $GITHUB_OUTPUT
4757
48-
DIGEST=$(docker image inspect $image --format '{{index .RepoDigests 0}}')
49-
cosign sign --yes --key env://COSIGN_PRIVATE_KEY \
50-
-a "repo=${{ github.repository }}" \
51-
-a "run=${{ github.run_id }}" \
52-
-a "ref=${{ github.sha }}" \
53-
$DIGEST
58+
- name: Determine metadata for BeeGFS image
59+
id: meta
60+
uses: docker/[email protected]
61+
with:
62+
images: ${{ env.REGISTRY }}/${{ env.NAMESPACE }}/${{ matrix.image_name }}
63+
tags: |
64+
type=ref,event=branch
65+
type=ref,event=pr
66+
type=semver,pattern={{version}},prefix=
67+
type=semver,pattern={{major}}.{{minor}},prefix=
5468
55-
docker tag $image ghcr.io/thinkparq/${name}:latest
56-
docker push ghcr.io/thinkparq/${name}:latest
69+
- name: Build and push image for each supported platform
70+
uses: docker/[email protected]
71+
id: build_and_push
72+
with:
73+
context: .
74+
platforms: "${{ env.DOCKER_BUILDX_BUILD_PLATFORMS }}"
75+
push: true
76+
tags: ${{ steps.meta.outputs.tags }}
77+
labels: ${{ steps.meta.outputs.labels }}
78+
# If provenance is not set to false then the manifest list will contain unknown platform
79+
# entries that are also displayed in GitHub. Some detail on why this is needed in:
80+
# https://github.com/docker/buildx/issues/1509 and
81+
# https://github.com/docker/build-push-action/issues/755#issuecomment-1607792956.
82+
provenance: false
83+
# Reference: https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-container-registry#adding-a-description-to-multi-arch-images
84+
outputs: type=image,name=target,annotation-index.org.opencontainers.image.description=Container images for the BeeGFS server services allowing fully containerized BeeGFS deployments
85+
build-args: |
86+
BEEGFS_VERSION=${{ steps.determine_beegfs_version.outputs.LAST_VERSION }}
87+
target: ${{ matrix.image_name }}
5788

89+
# Adapted from:
90+
# https://github.blog/2021-12-06-safeguard-container-signing-capability-actions/
91+
# https://github.com/sigstore/cosign-installer#usage
92+
# Note we only sign the multi-platform image manifest, not the individual platform specific images.
93+
- name: Sign container image with Cosign
94+
run: |
95+
images=""
96+
for tag in ${TAGS}; do
97+
images+="${tag}@${DIGEST} "
5898
done
99+
cosign sign --yes --key env://COSIGN_PRIVATE_KEY \
100+
-a "repo=${{ github.repository }}" \
101+
-a "run=${{ github.run_id }}" \
102+
-a "ref=${{ github.sha }}" \
103+
${images}
59104
env:
105+
TAGS: ${{ steps.meta.outputs.tags }}
60106
COSIGN_PRIVATE_KEY: ${{ secrets.COSIGN_PRIVATE_KEY }}
61107
COSIGN_PASSWORD: ${{ secrets.COSIGN_PASSWORD }}
108+
DIGEST: ${{ steps.build_and_push.outputs.digest }}

Dockerfile

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
# Using multi-stage docker with the same base image for all daemons.
1616

17-
FROM debian:10.12-slim AS base
17+
FROM --platform=$TARGETPLATFORM debian:10.12-slim AS base
1818
ARG DEBIAN_FRONTEND=noninteractive
1919
ENV PATH="/opt/beegfs/sbin/:${PATH}"
2020
# Note this is the default used when no version is specified.
@@ -50,15 +50,15 @@ RUN mkdir -p /data/beegfs
5050

5151

5252
# Build beegfs-mgmtd docker image with `docker build -t repo/image-name --target beegfs-mgmtd .`
53-
FROM base AS beegfs-mgmtd
53+
FROM --platform=$TARGETPLATFORM base AS beegfs-mgmtd
5454
ARG BEEGFS_SERVICE="beegfs-mgmtd"
5555
ENV BEEGFS_SERVICE=$BEEGFS_SERVICE
5656
RUN apt-get update && apt-get install $BEEGFS_SERVICE libbeegfs-ib -y && rm -rf /var/lib/apt/lists/*
5757
ENTRYPOINT ["/root/start.sh"]
5858

5959

6060
# Build beegfs-meta docker image with `docker build -t repo/image-name --target beegfs-meta .`
61-
FROM base AS beegfs-meta
61+
FROM --platform=$TARGETPLATFORM base AS beegfs-meta
6262
ARG BEEGFS_SERVICE="beegfs-meta"
6363
ENV BEEGFS_SERVICE=$BEEGFS_SERVICE
6464
RUN apt-get update && apt-get install $BEEGFS_SERVICE libbeegfs-ib -y && rm -rf /var/lib/apt/lists/*
@@ -67,7 +67,7 @@ ENTRYPOINT ["/root/start.sh"]
6767

6868

6969
# Build beegfs-storage docker image with `docker build -t repo/image-name --target beegfs-storage .`
70-
FROM base AS beegfs-storage
70+
FROM --platform=$TARGETPLATFORM base AS beegfs-storage
7171
ARG BEEGFS_SERVICE="beegfs-storage"
7272
ENV BEEGFS_SERVICE=$BEEGFS_SERVICE
7373
RUN apt-get update && apt-get install $BEEGFS_SERVICE libbeegfs-ib -y && rm -rf /var/lib/apt/lists/*
@@ -76,7 +76,7 @@ ENTRYPOINT ["/root/start.sh"]
7676

7777

7878
# Build beegfs-all docker image with `docker build -t repo/image-name --target beegfs-all .`
79-
FROM base AS beegfs-all
79+
FROM --platform=$TARGETPLATFORM base AS beegfs-all
8080
ARG BEEGFS_SERVICE="beegfs-all"
8181
RUN apt-get update && apt-get install libbeegfs-ib beegfs-mgmtd beegfs-meta beegfs-storage -y && rm -rf /var/lib/apt/lists/*
8282
RUN rm -rf /etc/beegfs/*conf

0 commit comments

Comments
 (0)