Skip to content

Commit fa38667

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 1c11b4b commit fa38667

File tree

5 files changed

+53
-26
lines changed

5 files changed

+53
-26
lines changed

.github/workflows/golang.yaml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,10 @@
1515
name: Golang
1616

1717
on:
18-
pull_request:
19-
branches:
20-
- main
21-
- release-*
2218
push:
2319
branches:
2420
- main
21+
- "pull-request/[0-9]+"
2522
- release-*
2623

2724
jobs:

.github/workflows/images.yaml

Lines changed: 49 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,20 @@
1616
name: Image
1717

1818
on:
19-
pull_request:
20-
types:
21-
- opened
22-
- synchronize
23-
branches:
24-
- main
25-
- release-*
2619
push:
2720
branches:
2821
- main
22+
- "pull-request/[0-9]+"
2923
- release-*
3024

3125
jobs:
3226
build:
33-
runs-on: ubuntu-latest
27+
strategy:
28+
matrix:
29+
arch:
30+
- amd64
31+
- arm64
32+
runs-on: linux-${{ matrix.arch }}-cpu4
3433
steps:
3534
- uses: actions/checkout@v4
3635
name: Check out code
@@ -52,11 +51,6 @@ jobs:
5251
GENERATE_ARTIFACTS="true"
5352
fi
5453
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
6054
- name: Login to GitHub Container Registry
6155
uses: docker/login-action@v3
6256
with:
@@ -66,7 +60,48 @@ jobs:
6660
- name: Build image
6761
env:
6862
IMAGE_NAME: ghcr.io/${LOWERCASE_REPO_OWNER}/k8s-kata-manager
69-
VERSION: ${COMMIT_SHORT_SHA}
63+
VERSION: ${COMMIT_SHORT_SHA}-${{ matrix.arch }}
64+
DOCKER_BUILD_PLATFORM_OPTIONS: "--platform=linux/${{ matrix.arch }}"
7065
run: |
7166
echo "${VERSION}"
7267
make -f deployments/container/Makefile build-image
68+
69+
create-manifest:
70+
needs: [ build ]
71+
runs-on: ubuntu-latest
72+
steps:
73+
- uses: actions/checkout@v4
74+
name: Check out code
75+
- name: Calculate build vars
76+
id: vars
77+
run: |
78+
echo "COMMIT_SHORT_SHA=${GITHUB_SHA:0:8}" >> $GITHUB_ENV
79+
echo "LOWERCASE_REPO_OWNER=$(echo "${GITHUB_REPOSITORY_OWNER}" | awk '{print tolower($0)}')" >> $GITHUB_ENV
80+
81+
GENERATE_ARTIFACTS="false"
82+
if [[ "${{ github.actor }}" == "dependabot[bot]" ]]; then
83+
GENERATE_ARTIFACTS="false"
84+
elif [[ "${{ github.event_name }}" == "pull_request" && "${{ github.event.pull_request.head.repo.full_name }}" == "${{ github.repository }}" ]]; then
85+
GENERATE_ARTIFACTS="true"
86+
elif [[ "${{ github.event_name }}" == "push" ]]; then
87+
GENERATE_ARTIFACTS="true"
88+
fi
89+
90+
echo "GENERATE_ARTIFACTS=${GENERATE_ARTIFACTS}" >> $GITHUB_ENV
91+
- name: Login to GitHub Container Registry
92+
if: ${{ env.GENERATE_ARTIFACTS == 'true' }}
93+
uses: docker/login-action@v3
94+
with:
95+
registry: ghcr.io
96+
username: ${{ github.actor }}
97+
password: ${{ secrets.GITHUB_TOKEN }}
98+
- name: Build Manifest
99+
if: ${{ env.GENERATE_ARTIFACTS == 'true' }}
100+
env:
101+
MULTIARCH_IMAGE: ghcr.io/${{ env.LOWERCASE_REPO_OWNER }}/k8s-kata-manager:${{ env.COMMIT_SHORT_SHA }}
102+
run: |
103+
docker manifest create \
104+
${MULTIARCH_IMAGE} \
105+
ghcr.io/${{ env.LOWERCASE_REPO_OWNER }}/k8s-kata-manager:${{ env.COMMIT_SHORT_SHA }}-amd64 \
106+
ghcr.io/${{ env.LOWERCASE_REPO_OWNER }}/k8s-kata-manager:${{ env.COMMIT_SHORT_SHA }}-arm64
107+
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)