Skip to content

Commit

Permalink
swiched to buildkit for multi-arch builds
Browse files Browse the repository at this point in the history
  • Loading branch information
groundnuty committed May 19, 2022
1 parent 6798df4 commit d6cda4c
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 22 deletions.
7 changes: 3 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ sudo: required
services:
- docker

arch:
- amd64
- arm64

script:
- make container

Expand All @@ -20,8 +16,11 @@ deploy:
on:
branch: master
tags: true

env:
global:
- TARGET=linux/arm64,linux/amd64 # multiple architectures build in one step
- BUILD_FLAGS=--no-cache # no --load flag, with multiple architectures
- secure: hs8m9KkJ+sBwQr4FF/ZGFDpK25n4K3q6R/KU0q++m27G0D2XtO+JeTQnRi8cV/8JGcYClBUIqkIXoKxpohuZ+LrTUGtPL/KUjsMshV59PTqvCrlkCmUfMrM0DowwVW1O7g2T+gPsr0rj++FUxTtk0s12sHZdxTDFrNTtdFD6Et6BXO6UIlDy2PhhLXNf7kxa7OpWPOWXosU6bBuj4NjaGXpYSWIJPnxMbmfGcmOpudPeRJGJsqDmHy3YKZ8IDWKOsDNOKmltOAzG3qhQP2DhHfjC4Tpmou3AOD2SdI5ekwPvQpa4cWo7LOw6l6PYtz7MhfchnQR5+KXvTu+JvGt3LDJeuE8PmFzefOxO2fUoEjNGFa3hRxGzJ4UyzxyXrqwPH4XBm4x1sqVFqMEwkY3AsuACGk4+1CSVkXORtE4GrhLBi52cJ7EI0Qq02+WjSKGppRg1OjIX0ZRG/mGOnt/qqHLSfxmRJGPIgtIALtsTbbHZwQN67se08p1+4JHgQ6G4tEV27Kmsu6tz2oAJrOuPrhCNltRFPhYw3A4U4jIO9ziMJHSMLtsHu48cOTtw2tVNW4mss6wadqpL4akX7uEiFoBrf0YFQ1cpImtpjRcAV8izBFiLYYLnQrnXUAPDFIEPEgyax8JATWVCS1qnfbdB3++6CUEMceTpBpY7dQVimKY=
- secure: eGI6porT74KMcar09zF6UQNpeQ28/2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6H0/ltCdHxnac5+tbN10tspdwCAfVu+g4Vgj3Yl4Uk3M5BbS03OIbVB3/dqMRmjBPANEJ267v7JXLcHSCAtONDGwWcGae0ZEUtiVMSPHTqgELPjpHsK0tTmGMFgT9hh27iHyGvBErB+ec7Fz7ayTQUbDK8ZoKwY+isAubUR+pAyB/5dcqwhYYNb041/ScRtfwdHjrheL2V0vFI7SPCavbeCMaY0ZGOySy5WhcvT6V/LayGjpedEj8SA=
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ MAINTAINER Michal Orzechowski <[email protected]>

ARG VCS_REF
ARG BUILD_DATE
ARG TARGET_PLATFORM
ARG TARGETARCH

# Metadata
LABEL org.label-schema.vcs-ref=$VCS_REF \
Expand All @@ -15,7 +15,7 @@ LABEL org.label-schema.vcs-ref=$VCS_REF \
ENV KUBE_LATEST_VERSION="v1.24.0"

RUN apk add --update --no-cache ca-certificates=20211220-r0 curl=7.80.0-r1 jq=1.6-r1 \
&& curl -L https://storage.googleapis.com/kubernetes-release/release/${KUBE_LATEST_VERSION}/bin/linux/$TARGET_PLATFORM/kubectl -o /usr/local/bin/kubectl \
&& curl -L https://storage.googleapis.com/kubernetes-release/release/${KUBE_LATEST_VERSION}/bin/linux/$TARGETARCH/kubectl -o /usr/local/bin/kubectl \
&& chmod +x /usr/local/bin/kubectl

ADD wait_for.sh /usr/local/bin/wait_for.sh
Expand Down
36 changes: 21 additions & 15 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,27 +1,33 @@
TAG = $(shell git describe --tags --always)
PREFIX = $(shell git config --get remote.origin.url | tr ':.' '/' | rev | cut -d '/' -f 3 | rev)
REPO_NAME = $(shell git config --get remote.origin.url | tr ':.' '/' | rev | cut -d '/' -f 2 | rev)
TARGET = $(shell ./evaluate_platform.sh)
TARGET := $(if $(TARGET),$(TARGET),$(shell ./evaluate_platform.sh))
VCS_REF = $(shell git rev-parse --short HEAD)
BUILD_DATE = $(shell date -u +'%Y-%m-%dT%H:%M:%SZ')
BUILD_FLAGS := $(if $(BUILD_FLAGS),$(BUILD_FLAGS),--load --no-cache)
BUILDER_NAME = k8s-wait-for-builder
DOCKER_TAGS= $(PREFIX)/$(REPO_NAME):latest $(PREFIX)/$(REPO_NAME):$(TAG) ghcr.io/$(PREFIX)/$(REPO_NAME):latest ghcr.io/$(PREFIX)/$(REPO_NAME):$(TAG)

all: push

container: image

image:
@echo TARGET IS $(TARGET)
docker build --no-cache -t $(PREFIX)/$(REPO_NAME):latest . --build-arg TARGET_PLATFORM=$(TARGET) # Build new image and automatically tag it as latest
docker tag $(PREFIX)/$(REPO_NAME) $(PREFIX)/$(REPO_NAME):$(TAG) # Add the version tag to the latest image
docker tag $(PREFIX)/$(REPO_NAME) ghcr.io/$(PREFIX)/$(REPO_NAME):latest # Tag latest for ghcr repository
docker tag $(PREFIX)/$(REPO_NAME) ghcr.io/$(PREFIX)/$(REPO_NAME):$(TAG) # Tag the version tag for ghcr repository
if ! docker buildx inspect $(BUILDER_NAME) 2> /dev/null ; then docker buildx create --name $(BUILDER_NAME) ; fi
docker buildx build \
--builder=$(BUILDER_NAME) \
--platform=$(TARGET) \
--build-arg VCS_REF=$(VCS_REF) \
--build-arg BUILD_DATE=$(BUILD_DATE) \
$(BUILD_FLAGS) \
$(foreach TAG,$(DOCKER_TAGS),--tag $(TAG)) \
.

push: push-docker-hub push-ghcr
push: BUILD_FLAGS:=$(BUILD_FLAGS:--load=)
push: BUILD_FLAGS+=--push
push: image

push-docker-hub: image
docker push $(PREFIX)/$(REPO_NAME):latest # Push image tagged as latest to docker hub repository
docker push $(PREFIX)/$(REPO_NAME):$(TAG) # Push version tagged image to docker hub repository (since this image is already pushed it will simply create or update version tag)

push-ghcr: image
docker push ghcr.io/$(PREFIX)/$(REPO_NAME):latest # Push image tagged as latest to ghcr repository
docker push ghcr.io/$(PREFIX)/$(REPO_NAME):$(TAG) # Push version tagged image to ghcr repository (since this image is already pushed it will simply create or update version tag)

clean:
clean:
if docker buildx inspect $(BUILDER_NAME) 2> /dev/null ; then docker buildx rm $(BUILDER_NAME) ; fi
$(foreach TAG,$(DOCKER_TAGS),docker rmi -f $(TAG); )
2 changes: 1 addition & 1 deletion evaluate_platform.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ if [ -z $PLATFORM ]; then
exit 1
fi

echo "$PLATFORM"
echo "linux/$PLATFORM"

0 comments on commit d6cda4c

Please sign in to comment.