From bc4a5f85a2a411b750d0a89d39c1d8d8836c78f4 Mon Sep 17 00:00:00 2001 From: Haim Gelfenbeyn Date: Tue, 9 Jan 2024 13:34:27 -0500 Subject: [PATCH] Initial fixes to support multi-arch container building (#2524) * Do not constrain the architecture in the Docker debian repo: Docker debian repo has AMD64 and ARM64 images both. Do not contstrain it, so that a multi-platform build image can be built. * Support building AMD64 and ARM64 images: 1. Pass architecture from the Makefile and override the hardcoded AMD64 in the goreleaser file. 2. AMD64 artifacts have a _v1 suffix, ARM64 artifacts don't: relas the "cp" source glob to support both. * License extractor architecture does not have to be the same as the built image architecture: It's perfectly fine to use the native license extractor arch even when building a non-native architecture image. * Use current container's arch when downloading Kind into build container * Use TARGETPLATFORM argument in the build container * Build the build container for Intel and ARM architectures --------- Co-authored-by: Daniil Fedotov --- .github/workflows/kanister-image-build.yaml | 3 +++ Makefile | 4 ++-- build/package.sh | 1 - docker/build/Dockerfile | 7 +++++-- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/.github/workflows/kanister-image-build.yaml b/.github/workflows/kanister-image-build.yaml index cd1db55d67..f49e58552a 100644 --- a/.github/workflows/kanister-image-build.yaml +++ b/.github/workflows/kanister-image-build.yaml @@ -38,6 +38,8 @@ jobs: # needs: check-files # if: needs.check-files.outputs.changed == 'true' steps: + - name: Set up QEMU + uses: docker/setup-qemu-action@68827325e0b33c7199eb31dd4e31fbe9023e06e3 # v3.0.0 - name: Set up Docker Buildx uses: docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226 # v3.0.0 - name: Image metadata @@ -60,6 +62,7 @@ jobs: uses: docker/build-push-action@4a13e500e55cf31b7a5d59a38ab2040ab0f42f56 # v5.1.0 with: context: "{{defaultContext}}:docker/build" + platforms: linux/amd64,linux/arm64 push: true tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} diff --git a/Makefile b/Makefile index 4d922beb10..3972f55530 100644 --- a/Makefile +++ b/Makefile @@ -94,8 +94,8 @@ build: bin/$(ARCH)/$(BIN) build-controller: @$(MAKE) run CMD=" \ - goreleaser build --id $(BIN) --rm-dist --debug --snapshot \ - && cp dist/$(BIN)_linux_$(ARCH)_*/$(BIN) bin/$(ARCH)/$(BIN) \ + GOOS=linux GOARCH=$(ARCH) goreleaser build --id $(BIN) --rm-dist --debug --snapshot --single-target \ + && cp dist/$(BIN)_linux_$(ARCH)*/$(BIN) bin/$(ARCH)/$(BIN) \ " bin/$(ARCH)/$(BIN): diff --git a/build/package.sh b/build/package.sh index f7c0de2f80..a4f096c980 100755 --- a/build/package.sh +++ b/build/package.sh @@ -35,7 +35,6 @@ build_licenses_info_image() { exit 1 fi docker run --rm ${mount_cmd} \ - --platform linux/${ARCH}\ "ghcr.io/kanisterio/license-extractor:4e0a91a" \ --mode merge \ --source ${src_dir} \ diff --git a/docker/build/Dockerfile b/docker/build/Dockerfile index f81b22f327..43e3e839a9 100644 --- a/docker/build/Dockerfile +++ b/docker/build/Dockerfile @@ -1,11 +1,13 @@ FROM golang:1.21-bullseye LABEL maintainer="Tom Manville" +ARG TARGETPLATFORM + RUN apt-get update && apt-get -y install apt-transport-https ca-certificates bash git gnupg2 software-properties-common curl jq wget \ && update-ca-certificates RUN curl -fsSL https://download.docker.com/linux/debian/gpg | gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg \ - && echo "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/debian $(lsb_release -cs) stable" | tee /etc/apt/sources.list.d/docker.list + && echo "deb [signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/debian $(lsb_release -cs) stable" | tee /etc/apt/sources.list.d/docker.list RUN apt update && apt install -y docker-ce docker-ce-cli containerd.io \ && apt-get clean @@ -18,7 +20,8 @@ COPY --from=alpine/helm:3.12.2 /usr/bin/helm /usr/local/bin/ COPY --from=golangci/golangci-lint:v1.55 /usr/bin/golangci-lint /usr/local/bin/ -RUN wget -O /usr/local/bin/kind https://github.com/kubernetes-sigs/kind/releases/download/v0.18.0/kind-linux-amd64 \ +RUN wget -O /usr/local/bin/kind \ + https://github.com/kubernetes-sigs/kind/releases/download/v0.18.0/kind-$(echo $TARGETPLATFORM | tr / -) \ && chmod +x /usr/local/bin/kind RUN git config --global --add safe.directory /go/src/github.com/kanisterio/kanister