Skip to content

Commit 7665637

Browse files
authored
add multi-arch support to the build (#93)
* Added multi-arch build option so that arm64 images etc can be created / pushed * refactor image build out into common workflow
1 parent f0cb7b2 commit 7665637

File tree

6 files changed

+95
-112
lines changed

6 files changed

+95
-112
lines changed

.github/workflows/build-image.yaml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: Build and Push Docker Image
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
image_tags:
7+
description: 'Comma-separated list of image tags to push'
8+
required: true
9+
type: string
10+
labels:
11+
description: 'Optional comma-separated list of labels'
12+
required: false
13+
type: string
14+
build_args:
15+
description: 'Optional newline-separated build args'
16+
required: false
17+
type: string
18+
19+
jobs:
20+
build-image:
21+
runs-on: ubuntu-latest
22+
steps:
23+
- uses: actions/checkout@v4
24+
25+
- name: Install Go
26+
uses: actions/setup-go@v5
27+
with:
28+
go-version: '^1.24'
29+
30+
- name: Create Licenses Report
31+
run: make licenses-report
32+
33+
- name: Login to GitHub Container Registry
34+
uses: docker/[email protected]
35+
with:
36+
registry: ghcr.io
37+
username: ${{ github.actor }}
38+
password: ${{ secrets.GITHUB_TOKEN }}
39+
40+
- name: Set up Docker Buildx
41+
uses: docker/[email protected]
42+
43+
- name: Build and Push Docker Image
44+
uses: docker/[email protected]
45+
with:
46+
platforms: linux/amd64,linux/arm64
47+
context: .
48+
push: true
49+
tags: ${{ inputs.image_tags }}
50+
labels: ${{ inputs.labels }}
51+
build-args: ${{ inputs.build_args }}

.github/workflows/container-image-manual.yaml

Lines changed: 15 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -4,45 +4,26 @@ on:
44
workflow_dispatch:
55
inputs:
66
tag:
7-
description: 'Custom tag for the image. Set to empty string to use an auto-generated tag.'
7+
description: 'Custom tag for the image. Empty = auto-generated tag'
88
required: false
99
default: ''
1010
type: string
1111

1212
jobs:
13-
build-container-image:
14-
name: build container image
15-
runs-on: "ubuntu-latest"
13+
sanitize-tag:
14+
runs-on: ubuntu-latest
15+
outputs:
16+
tag: ${{ steps.sanitize.outputs.tag }}
1617
steps:
17-
- uses: actions/checkout@v4
18-
19-
- name: Install Go
20-
uses: actions/setup-go@v5
21-
with:
22-
go-version: '^1.24'
23-
24-
- name: "Sanitize Branch name"
25-
id: sanitize-tag
26-
shell: bash
18+
- name: Sanitize tag
19+
id: sanitize
2720
run: |
28-
SANITIZED_TAG=$(echo -n ${{ inputs.tag != '' && inputs.tag || format('{0}-{1}', github.ref_name, github.sha) }} | tr "/" "-")
29-
echo "Sanitized tag: $SANITIZED_TAG"
30-
echo "sanitized-tag=$SANITIZED_TAG" >> $GITHUB_OUTPUT;
31-
32-
- name: Create Licenses Report
33-
run: |
34-
make licenses-report
35-
36-
- name: Login to GitHub Container Registry
37-
uses: docker/[email protected]
38-
with:
39-
registry: ghcr.io
40-
username: ${{ github.actor }}
41-
password: ${{ secrets.GITHUB_TOKEN }}
21+
RAW_TAG="${{ inputs.tag != '' && inputs.tag || format('{0}-{1}', github.ref_name, github.sha) }}"
22+
SANITIZED=$(echo "$RAW_TAG" | tr "/" "-")
23+
echo "tag=$SANITIZED" >> $GITHUB_OUTPUT
4224
43-
- name: Build and push Docker image
44-
uses: docker/[email protected]
45-
with:
46-
context: .
47-
push: true
48-
tags: ghcr.io/telekom/cluster-api-ipam-provider-infoblox:${{ steps.sanitize-tag.outputs.sanitized-tag }}
25+
build-image:
26+
needs: sanitize-tag
27+
uses: ./.github/workflows/build-image.yaml
28+
with:
29+
image_tags: ghcr.io/telekom/cluster-api-ipam-provider-infoblox:${{ needs.sanitize-tag.outputs.tag }}

.github/workflows/container-image.yaml

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,30 +7,6 @@ on:
77

88
jobs:
99
main-image:
10-
name: build "main" image
11-
runs-on: "ubuntu-latest"
12-
steps:
13-
- uses: actions/checkout@v4
14-
15-
- name: Install Go
16-
uses: actions/setup-go@v5
17-
with:
18-
go-version: '^1.24'
19-
20-
- name: Create Licenses Report
21-
run: |
22-
make licenses-report
23-
24-
- name: Login to GitHub Container Registry
25-
uses: docker/[email protected]
26-
with:
27-
registry: ghcr.io
28-
username: ${{ github.actor }}
29-
password: ${{ secrets.GITHUB_TOKEN }}
30-
31-
- name: Build and push Docker image
32-
uses: docker/[email protected]
33-
with:
34-
context: .
35-
push: true
36-
tags: ghcr.io/telekom/cluster-api-ipam-provider-infoblox:main
10+
uses: ./.github/workflows/build-image.yaml
11+
with:
12+
image_tags: ghcr.io/telekom/cluster-api-ipam-provider-infoblox:main

.github/workflows/draft_release.yaml

Lines changed: 20 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -3,76 +3,47 @@ name: Create Draft Release
33
on:
44
push:
55
tags:
6-
- 'v*'
6+
- 'v*'
77

88
jobs:
99
draft_release:
10-
name: Create Draft Release
1110
runs-on: ubuntu-latest
1211
steps:
13-
# - name: Set env
14-
# run: echo "RELEASE_TAG=${GITHUB_REF:10}" >> $GITHUB_ENV
15-
- name: Checkout the Repository
16-
uses: actions/checkout@v4
12+
- uses: actions/checkout@v4
1713
with:
1814
fetch-depth: 0
1915
- name: Install Go
2016
uses: actions/setup-go@v5
2117
with:
2218
go-version: '^1.24'
23-
# - name: generate release notes
24-
# run: |
25-
# make release-notes
2619
- name: Create Release Artifacts
27-
run: |
28-
make release
20+
run: make release
2921
- name: Create Release
3022
uses: softprops/action-gh-release@v2
3123
with:
3224
draft: true
3325
files: out/*.*
34-
# body_path: _releasenotes/${{ env.RELEASE_TAG }}.md
3526

36-
release_image:
37-
name: Build and Push Release Image
27+
extract-meta:
3828
runs-on: ubuntu-latest
29+
outputs:
30+
tags: ${{ steps.meta.outputs.tags }}
31+
labels: ${{ steps.meta.outputs.labels }}
32+
ldflags: ${{ steps.version_info.outputs.LDFLAGS }}
3933
steps:
40-
- name: Check out the repo
41-
uses: actions/checkout@v4
42-
43-
- name: Install Go
44-
uses: actions/setup-go@v5
45-
with:
46-
go-version: '^1.24'
47-
48-
- name: Create Licenses Report
49-
run: |
50-
make licenses-report
51-
52-
- name: Login to GitHub Container Registry
53-
uses: docker/[email protected]
54-
with:
55-
registry: ghcr.io
56-
username: ${{ github.actor }}
57-
password: ${{ secrets.GITHUB_TOKEN }}
58-
59-
- name: Extract Metadata (tags, labels) for Docker
34+
- uses: actions/checkout@v4
35+
- uses: docker/[email protected]
6036
id: meta
61-
uses: docker/[email protected]
6237
with:
6338
images: ghcr.io/telekom/cluster-api-ipam-provider-infoblox
64-
65-
- name: Get Version Information
66-
id: version_info
67-
run: |
68-
echo "LDFLAGS=$(hack/version.sh)" >> $GITHUB_OUTPUT
39+
- id: version_info
40+
run: echo "LDFLAGS=$(hack/version.sh)" >> $GITHUB_OUTPUT
6941

70-
- name: Build and Push Docker Image
71-
uses: docker/[email protected]
72-
with:
73-
context: .
74-
push: true
75-
tags: ${{ steps.meta.outputs.tags }}
76-
labels: ${{ steps.meta.outputs.labels }}
77-
build-args: |
78-
ldflags=${{ steps.version_info.outputs.LDFLAGS }}
42+
release_image:
43+
needs: extract-meta
44+
uses: ./.github/workflows/build-image.yaml
45+
with:
46+
image_tags: ${{ needs.extract-meta.outputs.tags }}
47+
labels: ${{ needs.extract-meta.outputs.labels }}
48+
build_args: |
49+
ldflags=${{ needs.extract-meta.outputs.ldflags }}

Dockerfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@ COPY internal/ internal/
1717
COPY pkg/ pkg/
1818

1919
ARG ldflags
20+
ARG TARGETOS
21+
ARG TARGETARCH
2022

2123
# Build
22-
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 \
24+
RUN CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH \
2325
go build -trimpath -ldflags "${ldflags}" -a -o manager main.go
2426

2527
# Use distroless as minimal base image to package the manager binary

Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Image URL to use all building/pushing image targets
22
IMG ?= ghcr.io/telekom/cluster-api-ipam-provider-infoblox
3+
TARGETPLATFORM ?= linux/amd64
4+
35
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
46
ENVTEST_K8S_VERSION = 1.27
57
CONTROLLER_GEN_VERSION= 0.16.3
@@ -81,7 +83,7 @@ run: manifests generate fmt vet ## Run a controller from your host.
8183

8284
.PHONY: docker-build
8385
docker-build: test licenses-report ## Build docker image with the manager.
84-
docker build -t ${IMG} .
86+
docker build --platform ${TARGETPLATFORM} -t ${IMG} .
8587

8688
.PHONY: docker-push
8789
docker-push: ## Push docker image with the manager.

0 commit comments

Comments
 (0)