Skip to content

Commit

Permalink
chore: use TARGETARCH for image build and makefile update
Browse files Browse the repository at this point in the history
Signed-off-by: Anish Ramasekar <[email protected]>
  • Loading branch information
aramase committed Nov 1, 2021
1 parent ba364e1 commit 6069215
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 16 deletions.
25 changes: 12 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ ARCH ?= amd64
OSVERSION ?= 1809
# Output type of docker buildx build
OUTPUT_TYPE ?= registry
QEMUVERSION ?= 5.2.0-2
BUILDX_BUILDER_NAME ?= img-builder
QEMU_VERSION ?= 5.2.0-2

# Binaries
GOLANGCI_LINT := $(TOOLS_BIN_DIR)/golangci-lint
Expand Down Expand Up @@ -286,20 +287,20 @@ endif

.PHONY: e2e-provider-container
e2e-provider-container:
docker build --no-cache -t $(E2E_PROVIDER_IMAGE_TAG) -f test/e2eprovider/Dockerfile .
docker buildx build --no-cache -t $(E2E_PROVIDER_IMAGE_TAG) -f test/e2eprovider/Dockerfile --progress=plain .

.PHONY: container
container: crd-container
docker build --no-cache --build-arg IMAGE_VERSION=$(IMAGE_VERSION) -t $(IMAGE_TAG) -f docker/Dockerfile .
docker buildx build --no-cache --build-arg IMAGE_VERSION=$(IMAGE_VERSION) -t $(IMAGE_TAG) -f docker/Dockerfile --progress=plain .

.PHONY: crd-container
crd-container: build-crds
docker build --no-cache --build-arg ARCH=$(ARCH) -t $(CRD_IMAGE_TAG) -f docker/crd.Dockerfile _output/crds/
docker buildx build --no-cache -t $(CRD_IMAGE_TAG) -f docker/crd.Dockerfile --progress=plain _output/crds/

.PHONY: crd-container-linux
crd-container-linux: build-crds docker-buildx-builder
docker buildx build --no-cache --output=type=$(OUTPUT_TYPE) --platform="linux/$(ARCH)" \
--build-arg ARCH=$(ARCH) -t $(CRD_IMAGE_TAG)-linux-$(ARCH) -f docker/crd.Dockerfile _output/crds/
-t $(CRD_IMAGE_TAG)-linux-$(ARCH) -f docker/crd.Dockerfile _output/crds/

.PHONY: container-linux
container-linux: docker-buildx-builder
Expand All @@ -315,15 +316,14 @@ container-windows: docker-buildx-builder

.PHONY: docker-buildx-builder
docker-buildx-builder:
@if ! docker buildx ls | grep -q container-builder; then\
DOCKER_CLI_EXPERIMENTAL=enabled docker buildx create --name container-builder --use;\
@if ! docker buildx ls | grep $(BUILDX_BUILDER_NAME); then \
docker run --rm --privileged multiarch/qemu-user-static:$(QEMU_VERSION) --reset -p yes; \
docker buildx create --name $(BUILDX_BUILDER_NAME) --use; \
docker buildx inspect $(BUILDX_BUILDER_NAME) --bootstrap; \
fi

.PHONY: container-all
container-all:
# Enable execution of multi-architecture containers
docker run --rm --privileged multiarch/qemu-user-static:$(QEMUVERSION) --reset -p yes

container-all: docker-buildx-builder
for arch in $(ALL_ARCH.linux); do \
ARCH=$${arch} $(MAKE) container-linux; \
ARCH=$${arch} $(MAKE) crd-container-linux; \
Expand Down Expand Up @@ -378,8 +378,7 @@ ifdef TEST_WINDOWS
$(MAKE) container-all push-manifest
else
$(MAKE) container
kind load docker-image --name kind $(IMAGE_TAG)
kind load docker-image --name kind $(CRD_IMAGE_TAG)
kind load docker-image --name kind $(IMAGE_TAG) $(CRD_IMAGE_TAG)
endif

.PHONY: e2e-mock-provider-container
Expand Down
2 changes: 1 addition & 1 deletion docker/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ build_and_push() {
# charts to prod dir. So we can use manifest_staging charts for the image build.
if find ../manifest_staging/charts/secrets-store-csi-driver/crds -mindepth 1 -maxdepth 1 | read -r; then
if [[ "$os_name" != "windows" ]]; then
docker buildx build --no-cache --pull --push --platform "${os_name}/${arch}" --build-arg ARCH="${arch}" -t "${CRD_IMAGE_TAG}-${suffix}" \
docker buildx build --no-cache --pull --push --platform "${os_name}/${arch}" -t "${CRD_IMAGE_TAG}-${suffix}" \
-f crd.Dockerfile ../manifest_staging/charts/secrets-store-csi-driver/crds
fi
fi
Expand Down
4 changes: 2 additions & 2 deletions docker/crd.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@

FROM alpine as builder
ARG KUBE_VERSION=v1.21.2
ARG ARCH
ARG TARGETARCH

RUN apk add --no-cache curl && \
curl -LO https://storage.googleapis.com/kubernetes-release/release/${KUBE_VERSION}/bin/linux/${ARCH}/kubectl && \
curl -LO https://storage.googleapis.com/kubernetes-release/release/${KUBE_VERSION}/bin/linux/${TARGETARCH}/kubectl && \
chmod +x kubectl

FROM gcr.io/distroless/static
Expand Down

0 comments on commit 6069215

Please sign in to comment.