Skip to content

Commit cd63a83

Browse files
authored
F #44: Use multiarch docker build in the release pipeline (#46)
1 parent 55ac794 commit cd63a83

File tree

3 files changed

+16
-32
lines changed

3 files changed

+16
-32
lines changed

.github/workflows/release.yml

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,8 @@ jobs:
2323
username: "${{ github.actor }}"
2424
password: "${{ secrets.GITHUB_TOKEN }}"
2525

26-
- name: Build image
27-
run: docker build . --tag "ghcr.io/${GITHUB_REPOSITORY,,}:$GITHUB_REF_NAME"
28-
29-
- name: Push image
30-
run: docker push "ghcr.io/${GITHUB_REPOSITORY,,}:$GITHUB_REF_NAME"
31-
32-
- name: Tag image (latest)
33-
run: docker tag "ghcr.io/${GITHUB_REPOSITORY,,}:$GITHUB_REF_NAME" "ghcr.io/${GITHUB_REPOSITORY,,}:latest"
34-
35-
- name: Push image (latest)
36-
run: docker push "ghcr.io/${GITHUB_REPOSITORY,,}:latest"
26+
- name: Build and push images
27+
run: make docker-release "CLOSEST_TAG:=$GITHUB_REF_NAME" BUILDX_NO_DEFAULT_ATTESTATIONS=1
3728

3829
- name: Generate manifests and charts
3930
run: make release "CLOSEST_TAG:=$GITHUB_REF_NAME"

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Build the manager binary
2-
FROM golang:1.22 AS builder
2+
FROM --platform=$BUILDPLATFORM golang:1.22 AS builder
33
ARG TARGETOS
44
ARG TARGETARCH
55

Makefile

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ KUSTOMIZE := $(SELF)/bin/kustomize
4040

4141
CLOSEST_TAG ?= $(shell git -C $(SELF) describe --tags --abbrev=0)
4242

43-
# Image URL to use all building/pushing image targets
43+
# Image URL to use for building/pushing image targets
4444
IMG_URL ?= ghcr.io/opennebula/cluster-api-provider-opennebula
4545
IMG ?= $(IMG_URL):latest
4646
E2E_IMG ?= $(IMG_URL):e2e
@@ -130,7 +130,7 @@ lint-fix: $(GOLANGCI_LINT)
130130

131131
# Build
132132

133-
.PHONY: build run docker-build docker-push docker-build-e2e
133+
.PHONY: build run docker-build docker-push docker-build-e2e docker-release
134134

135135
build: manifests generate fmt vet
136136
go build -o bin/manager cmd/main.go
@@ -147,25 +147,18 @@ docker-push: docker-build
147147
docker-build-e2e:
148148
$(CONTAINER_TOOL) build -t $(E2E_IMG) .
149149

150-
# _PLATFORMS defines the target platforms for the manager image be built to provide support to multiple
151-
# architectures. (i.e. make docker-buildx IMG=myregistry/mypoperator:0.0.1). To use this option you need to:
152-
# - be able to use docker buildx. More info: https://docs.docker.com/reference/cli/docker/buildx/
153-
# - have enabled BuildKit. More info:h ttps://docs.docker.com/build/buildkit/
154-
# - be able to push the image to your registry (i.e. if you do not set a valid value via IMG=<myregistry/image:<tag>> then the export will fail)
155-
# To adequately provide solutions that are compatible with multiple platforms, you should consider using this option.
156-
# NOTE: BUILDPLATFORM is a Docker BuildKit build-time variable that represents the platform (architecture/OS) on which the build is running (for example, linux/amd64).
157-
# More info: https://docs.docker.com/build/building/multi-platform/#automatic-platform-args-in-the-global-scope
158-
_PLATFORMS ?= linux/arm64,linux/amd64
159-
.PHONY: docker-multiarch-build-and-push
160-
docker-multiarch-build-and-push: ## Build and push docker image for the manager for cross-platform support)
161-
# copy existing Dockerfile and insert --platform=${BUILDPLATFORM} into Dockerfile.cross, and preserve the original Dockerfile (https://docs.docker.com/build/building/multi-platform/#cross-compilation)
162-
sed -e '1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' Dockerfile > Dockerfile.cross
163-
- $(CONTAINER_TOOL) buildx create --name cluster-api-provider-opennebula-builder
164-
$(CONTAINER_TOOL) buildx use cluster-api-provider-opennebula-builder
165-
- $(CONTAINER_TOOL) buildx build --push --platform=$(_PLATFORMS) --tag ${IMG} -f Dockerfile.cross .
166-
- $(CONTAINER_TOOL) buildx rm cluster-api-provider-opennebula-builder
167-
rm Dockerfile.cross
150+
# _PLATFORMS defines the target platforms for the manager image be built to provide support to multiple architectures.
151+
# To use this option you need to:
152+
# - be able to use docker buildx (https://docs.docker.com/reference/cli/docker/buildx/)
153+
# - have enabled BuildKit (https://docs.docker.com/build/buildkit/)
154+
# - be able to push the image to your registry
155+
_PLATFORMS ?= linux/amd64,linux/arm64
168156

157+
docker-release:
158+
-$(CONTAINER_TOOL) buildx create --name cluster-api-provider-opennebula-builder
159+
$(CONTAINER_TOOL) buildx use cluster-api-provider-opennebula-builder
160+
$(CONTAINER_TOOL) buildx build --push --platform=$(_PLATFORMS) -t $(IMG_URL):$(CLOSEST_TAG) -t $(IMG_URL):latest -f Dockerfile .
161+
-$(CONTAINER_TOOL) buildx rm cluster-api-provider-opennebula-builder
169162

170163
# Release
171164

0 commit comments

Comments
 (0)