Skip to content

Commit

Permalink
build: Build multi-arch (linux/amd64, linux/arm64) image using buildx
Browse files Browse the repository at this point in the history
  • Loading branch information
dlipovetsky committed Jun 7, 2023
1 parent 8ead4c9 commit 6e13aca
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 11 deletions.
16 changes: 5 additions & 11 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ jobs:
release:
name: Release
runs-on:
# For a list of pre-installed software, see https://github.com/actions/runner-images/blob/main/images/linux/Ubuntu2204-Readme.md
- ubuntu-22.04
steps:
- uses: actions/checkout@v3
Expand All @@ -31,29 +32,22 @@ jobs:
registry: ${{ env.registry }}
username: ${{ env.registry_username }}
password: ${{ env.registry_password }}
- name: Generate container image
- name: Build multi-arch container image, and push to container registry
# Note: We set make variables using positional arguments (to the right of the make command), not environment
# variables (to the left of the make command). While make converts environment variables to make variables, the
# conversion is not straightforward. For example, conditional assignments are not overriden by environment
# variables.
run: |
make generate-capvcd-image \
REGISTRY=${{ env.registry }} \
CAPVCD_IMG=${{ env.repository }} \
VERSION=${{ env.version }}
- name: Push container image to container registry
# See note on make variables, above.
run: |
make push-capvcd-image \
--makefile d2iq.Makefile \
REGISTRY=${{ env.registry }} \
CAPVCD_IMG=${{ env.repository }} \
VERSION=${{ env.version }}
- name: Generate GitHub release artifacts
# See note on make variables, above.
#
# We use our own Makefile to allow us to change the image in the manifest.
run: |
make -f d2iq.Makefile release-manifests \
make release-manifests \
--makefile d2iq.Makefile
REGISTRY=${{ env.registry }} \
CAPVCD_IMG=${{ env.repository }} \
VERSION=${{ env.version }}
Expand Down
3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# syntax=docker/dockerfile:1

# Build the manager binary
FROM golang:1.19 as builder

Expand All @@ -11,6 +13,7 @@ ADD . /go/src/github.com/vmware/cluster-api-provider-cloud-director
WORKDIR /go/src/github.com/vmware/cluster-api-provider-cloud-director

ENV GOPATH /go
ENV GOARCH $TARGETARCH
ARG VERSION
RUN make build-within-docker VERSION=$VERSION && \
chmod +x /build/vcloud/cluster-api-provider-cloud-director
Expand Down
20 changes: 20 additions & 0 deletions d2iq.Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
include Makefile

PLATFORMS := "linux/amd64,linux/arm64"

# The multi-platform build must push its output to a registry, because the Docker Engine image store does not support
# multi-platform images. This will be addressed when Docker Engine supports the containerd image store. See
# https://docs.docker.com/storage/containerd.
.PHONY: push-capvcd-image
push-capvcd-image: docker-buildx-builder generate fmt vet vendor
docker buildx build \
--builder capvcd \
--platform $(PLATFORMS) \
--output=type=registry \
--build-arg VERSION=$(VERSION) \
--tag $(REGISTRY)/$(CAPVCD_IMG):$(VERSION) \
--file Dockerfile \
.

.PHONY: docker-buildx-builder
docker-buildx-builder:
docker buildx inspect --bootstrap capvcd &>/dev/null || docker buildx create --name capvcd

# The upstream 'release-manifests' target does not correctly override the image.
# We work around this by using `kustomize edit set image`.
release-manifests: kustomize
Expand Down

0 comments on commit 6e13aca

Please sign in to comment.