Skip to content

Commit eefd2f6

Browse files
Build multiarch images on native GitHub runners
This commit makes the following changes: 1. Builds multiarch images for non-release commits/PRs, in addition to released versions. 2. Runs the docker build for an arch on the respective GitHub runner (e.g. a linux/amd64 docker image will be built on a linux/amd64 runner). This native build reduces build times due to not requiring emulation. 3. Removes explicit use of buildx for docker build. Buildx is now the default builder in Docker. Also removes the related QEMU setup. Signed-off-by: Rajath Agasthya <[email protected]>
1 parent d101e4a commit eefd2f6

File tree

4 files changed

+51
-15
lines changed

4 files changed

+51
-15
lines changed

.github/workflows/images.yaml

Lines changed: 48 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,12 @@ on:
3030

3131
jobs:
3232
build:
33-
runs-on: ubuntu-latest
33+
strategy:
34+
matrix:
35+
arch:
36+
- amd64
37+
- arm64
38+
runs-on: linux-${{ matrix.arch }}-cpu4
3439
steps:
3540
- uses: actions/checkout@v4
3641
name: Check out code
@@ -52,11 +57,6 @@ jobs:
5257
GENERATE_ARTIFACTS="true"
5358
fi
5459
echo "PUSH_ON_BUILD=${GENERATE_ARTIFACTS}" >> $GITHUB_ENV
55-
echo "BUILD_MULTI_ARCH_IMAGES=${GENERATE_ARTIFACTS}" >> $GITHUB_ENV
56-
- name: Set up QEMU
57-
uses: docker/setup-qemu-action@v3
58-
- name: Set up Docker Buildx
59-
uses: docker/setup-buildx-action@v3
6060
- name: Login to GitHub Container Registry
6161
uses: docker/login-action@v3
6262
with:
@@ -66,7 +66,48 @@ jobs:
6666
- name: Build image
6767
env:
6868
IMAGE_NAME: ghcr.io/${LOWERCASE_REPO_OWNER}/k8s-kata-manager
69-
VERSION: ${COMMIT_SHORT_SHA}
69+
VERSION: ${COMMIT_SHORT_SHA}-${{ matrix.arch }}
70+
DOCKER_BUILD_PLATFORM_OPTIONS: "--platform=linux/${{ matrix.arch }}"
7071
run: |
7172
echo "${VERSION}"
7273
make -f deployments/container/Makefile build-image
74+
75+
create-manifest:
76+
needs: [ build ]
77+
runs-on: ubuntu-latest
78+
steps:
79+
- uses: actions/checkout@v4
80+
name: Check out code
81+
- name: Calculate build vars
82+
id: vars
83+
run: |
84+
echo "COMMIT_SHORT_SHA=${GITHUB_SHA:0:8}" >> $GITHUB_ENV
85+
echo "LOWERCASE_REPO_OWNER=$(echo "${GITHUB_REPOSITORY_OWNER}" | awk '{print tolower($0)}')" >> $GITHUB_ENV
86+
87+
GENERATE_ARTIFACTS="false"
88+
if [[ "${{ github.actor }}" == "dependabot[bot]" ]]; then
89+
GENERATE_ARTIFACTS="false"
90+
elif [[ "${{ github.event_name }}" == "pull_request" && "${{ github.event.pull_request.head.repo.full_name }}" == "${{ github.repository }}" ]]; then
91+
GENERATE_ARTIFACTS="true"
92+
elif [[ "${{ github.event_name }}" == "push" ]]; then
93+
GENERATE_ARTIFACTS="true"
94+
fi
95+
96+
echo "GENERATE_ARTIFACTS=${GENERATE_ARTIFACTS}" >> $GITHUB_ENV
97+
- name: Login to GitHub Container Registry
98+
if: ${{ env.GENERATE_ARTIFACTS == 'true' }}
99+
uses: docker/login-action@v3
100+
with:
101+
registry: ghcr.io
102+
username: ${{ github.actor }}
103+
password: ${{ secrets.GITHUB_TOKEN }}
104+
- name: Build Manifest
105+
if: ${{ env.GENERATE_ARTIFACTS == 'true' }}
106+
env:
107+
MULTIARCH_IMAGE: ghcr.io/${{ env.LOWERCASE_REPO_OWNER }}/k8s-kata-manager:${{ env.COMMIT_SHORT_SHA }}
108+
run: |
109+
docker manifest create \
110+
${MULTIARCH_IMAGE} \
111+
ghcr.io/${{ env.LOWERCASE_REPO_OWNER }}/k8s-kata-manager:${{ env.COMMIT_SHORT_SHA }}-amd64 \
112+
ghcr.io/${{ env.LOWERCASE_REPO_OWNER }}/k8s-kata-manager:${{ env.COMMIT_SHORT_SHA }}-arm64
113+
docker manifest push ${MULTIARCH_IMAGE}

deployments/container/Makefile

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@
1414

1515
BUILD_MULTI_ARCH_IMAGES ?= no
1616
DOCKER ?= docker
17-
BUILDX =
18-
ifeq ($(BUILD_MULTI_ARCH_IMAGES),true)
19-
BUILDX = buildx
20-
endif
2117
MKDIR ?= mkdir
2218

2319
##### Global variables #####
@@ -53,8 +49,7 @@ build-image: DOCKERFILE = $(CURDIR)/deployments/container/Dockerfile
5349

5450
# Use a generic build target to build the relevant images
5551
$(IMAGE_TARGETS):
56-
DOCKER_BUILDKIT=1 \
57-
$(DOCKER) $(BUILDX) build --pull \
52+
$(DOCKER) build --pull \
5853
$(DOCKER_BUILD_OPTIONS) \
5954
$(DOCKER_BUILD_PLATFORM_OPTIONS) \
6055
--tag $(IMAGE) \

deployments/container/multi-arch.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@
1515
PUSH_ON_BUILD ?= false
1616
ATTACH_ATTESTATIONS ?= false
1717
DOCKER_BUILD_OPTIONS = --output=type=image,push=$(PUSH_ON_BUILD) --provenance=$(ATTACH_ATTESTATIONS) --sbom=$(ATTACH_ATTESTATIONS)
18-
DOCKER_BUILD_PLATFORM_OPTIONS = --platform=linux/amd64,linux/arm64
18+
DOCKER_BUILD_PLATFORM_OPTIONS ?= --platform=linux/amd64,linux/arm64
1919

2020
$(BUILD_TARGETS): image

deployments/container/native-only.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# limitations under the License.
1414

1515
PUSH_ON_BUILD ?= false
16-
DOCKER_BUILD_PLATFORM_OPTIONS = --platform=linux/amd64
16+
DOCKER_BUILD_PLATFORM_OPTIONS ?= --platform=linux/amd64
1717

1818
ifeq ($(PUSH_ON_BUILD),true)
1919
$(BUILD_TARGETS): image

0 commit comments

Comments
 (0)