Skip to content

Commit

Permalink
Initial fixes to support multi-arch container building (#2524)
Browse files Browse the repository at this point in the history
* 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 <daniil.fedotov@kasten.io>
  • Loading branch information
haimgel and hairyhum committed Jan 9, 2024
1 parent 2968f6a commit bc4a5f8
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 5 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/kanister-image-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 }}
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
1 change: 0 additions & 1 deletion build/package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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} \
Expand Down
7 changes: 5 additions & 2 deletions docker/build/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
FROM golang:1.21-bullseye
LABEL maintainer="Tom Manville<tom@kasten.io>"

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
Expand All @@ -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
Expand Down

0 comments on commit bc4a5f8

Please sign in to comment.