Skip to content

Commit 2e98d01

Browse files
authored
F OpenNebula/cluster-api-provider-opennebula#44: Use multiarch docker build in the release pipeline (#11)
1 parent e563c6b commit 2e98d01

File tree

3 files changed

+22
-40
lines changed

3 files changed

+22
-40
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: Create release
3930
env: { GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" }

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: 19 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,21 @@ else
1313
GOBIN := $(shell go env GOBIN)
1414
endif
1515

16+
ENVSUBST_VERSION ?= 1.4.2
17+
KUBECTL_VERSION ?= 1.31.4
18+
KUSTOMIZE_VERSION ?= 5.6.0
19+
1620
ENVSUBST := $(SELF)/bin/envsubst
1721
KUBECTL := $(SELF)/bin/kubectl
1822
KUSTOMIZE := $(SELF)/bin/kustomize
1923

20-
ENVSUBST_VERSION ?= 1.4.2
21-
KUBECTL_VERSION ?= 1.31.4
22-
KUSTOMIZE_VERSION ?= 5.6.0
24+
CLOSEST_TAG ?= $(shell git -C $(SELF) describe --tags --abbrev=0)
2325

2426
# Local image URL used for building/pushing image targets
2527
CCM_IMG ?= localhost:5005/cloud-provider-opennebula:latest
2628

27-
# Image tag/URL used for publising the provider
28-
RELEASE_TAG ?= latest
29-
RELEASE_IMG ?= ghcr.io/opennebula/cloud-provider-opennebula:$(RELEASE_TAG)
29+
# Image URL to use for building/pushing image targets
30+
IMG_URL ?= ghcr.io/opennebula/cloud-provider-opennebula
3031

3132
# CONTAINER_TOOL defines the container tool to be used for building images.
3233
# Be aware that the target commands are only tested with Docker which is
@@ -59,7 +60,7 @@ test:
5960

6061
# Build
6162

62-
.PHONY: build docker-build docker-push docker-publish
63+
.PHONY: build docker-build docker-push docker-release
6364

6465
build: fmt vet
6566
go build -o bin/opennebula-cloud-controller-manager cmd/opennebula-cloud-controller-manager/main.go
@@ -70,28 +71,18 @@ docker-build:
7071
docker-push:
7172
$(CONTAINER_TOOL) push $(CCM_IMG)
7273

73-
docker-publish: docker-build
74-
$(CONTAINER_TOOL) tag $(CCM_IMG) $(RELEASE_IMG)
75-
$(CONTAINER_TOOL) push $(RELEASE_IMG)
76-
77-
# _PLATFORMS defines the target platforms for the manager image be built to provide support to multiple
78-
# architectures. (i.e. make docker-buildx IMG=myregistry/mypoperator:0.0.1). To use this option you need to:
79-
# - be able to use docker buildx. More info: https://docs.docker.com/reference/cli/docker/buildx/
80-
# - have enabled BuildKit. More info:h ttps://docs.docker.com/build/buildkit/
81-
# - 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)
82-
# To adequately provide solutions that are compatible with multiple platforms, you should consider using this option.
83-
# 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).
84-
# More info: https://docs.docker.com/build/building/multi-platform/#automatic-platform-args-in-the-global-scope
85-
_PLATFORMS ?= linux/arm64,linux/amd64
86-
.PHONY: docker-multiarch-build-and-push
87-
docker-multiarch-build-and-push: ## Build and push docker image for the manager for cross-platform support)
88-
# 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)
89-
sed -e '1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' Dockerfile > Dockerfile.cross
90-
- $(CONTAINER_TOOL) buildx create --name cloud-provider-opennebula-builder
74+
# _PLATFORMS defines the target platforms for the manager image be built to provide support to multiple architectures.
75+
# To use this option you need to:
76+
# - be able to use docker buildx (https://docs.docker.com/reference/cli/docker/buildx/)
77+
# - have enabled BuildKit (https://docs.docker.com/build/buildkit/)
78+
# - be able to push the image to your registry
79+
_PLATFORMS ?= linux/amd64,linux/arm64
80+
81+
docker-release:
82+
-$(CONTAINER_TOOL) buildx create --name cloud-provider-opennebula-builder
9183
$(CONTAINER_TOOL) buildx use cloud-provider-opennebula-builder
92-
- $(CONTAINER_TOOL) buildx build --push --platform=$(_PLATFORMS) --tag ${CCM_IMG} -f Dockerfile.cross .
93-
- $(CONTAINER_TOOL) buildx rm cloud-provider-opennebula-builder
94-
rm Dockerfile.cross
84+
$(CONTAINER_TOOL) buildx build --push --platform=$(_PLATFORMS) -t $(IMG_URL):$(CLOSEST_TAG) -t $(IMG_URL):latest -f Dockerfile .
85+
-$(CONTAINER_TOOL) buildx rm cloud-provider-opennebula-builder
9586

9687
# Deployment
9788

0 commit comments

Comments
 (0)