|
15 | 15 | all: build |
16 | 16 |
|
17 | 17 | PROJ=gcr.io/k8s-cri-containerd |
18 | | -VERSION=2.0 |
| 18 | +VERSION=2.1 |
19 | 19 | IMAGE=$(PROJ)/volume-copy-up:$(VERSION) |
20 | | -PLATFORMS?=linux/amd64,linux/arm64 |
| 20 | + |
| 21 | +# Operating systems supported: linux, windows |
| 22 | +OS ?= linux |
| 23 | +# Architectures supported: amd64, arm64 |
| 24 | +ARCH ?= amd64 |
| 25 | +# OS Version for the Windows images: 1809, 2004, 20H2 |
| 26 | +OSVERSION ?= 1809 |
| 27 | + |
| 28 | +# The output type could either be docker (local), or registry. |
| 29 | +# If it is registry, it will also allow us to push the Windows images. |
| 30 | +OUTPUT_TYPE ?= docker |
| 31 | + |
| 32 | +ALL_OS = linux windows |
| 33 | +ALL_ARCH.linux = amd64 arm64 |
| 34 | +ALL_OS_ARCH.linux = $(foreach arch, ${ALL_ARCH.linux}, linux-$(arch)) |
| 35 | +ALL_OSVERSIONS.windows := 1809 2004 20H2 |
| 36 | +ALL_OS_ARCH.windows = $(foreach osversion, ${ALL_OSVERSIONS.windows}, windows-amd64-${osversion}) |
| 37 | +ALL_OS_ARCH = $(foreach os, $(ALL_OS), ${ALL_OS_ARCH.${os}}) |
| 38 | + |
| 39 | +BASE.linux.amd64 := busybox |
| 40 | +BASE.linux.arm64 := arm64v8/busybox |
| 41 | +BASE.linux := ${BASE.linux.${ARCH}} |
| 42 | +BASE.windows := mcr.microsoft.com/windows/nanoserver |
| 43 | +BASE := ${BASE.${OS}} |
21 | 44 |
|
22 | 45 | configure-docker: |
23 | 46 | gcloud auth configure-docker |
24 | 47 |
|
25 | | -build: |
26 | | - docker buildx build \ |
27 | | - $(OUTPUT) \ |
28 | | - --platform=${PLATFORMS} \ |
29 | | - --tag $(IMAGE) . |
| 48 | +setup-buildx: |
| 49 | + docker buildx use img-builder || docker buildx create --name img-builder --use |
| 50 | + |
| 51 | +build: setup-buildx build-local |
| 52 | + |
| 53 | +push: configure-docker setup-buildx build-registry push-manifest |
| 54 | + |
| 55 | +build-local: $(addprefix sub-container-docker-,$(ALL_OS_ARCH.linux)) |
| 56 | +build-registry: $(addprefix sub-container-registry-,$(ALL_OS_ARCH)) |
| 57 | + |
| 58 | +# split words on hyphen, access by 1-index |
| 59 | +word-hyphen = $(word $2,$(subst -, ,$1)) |
| 60 | +sub-container-%: |
| 61 | + $(MAKE) OUTPUT_TYPE=$(call word-hyphen,$*,1) OS=$(call word-hyphen,$*,2) ARCH=$(call word-hyphen,$*,3) OSVERSION=$(call word-hyphen,$*,4) container |
| 62 | + |
| 63 | +container: .container-${OS}-$(ARCH) |
| 64 | + |
| 65 | +.container-linux-$(ARCH): |
| 66 | + docker buildx build --pull --output=type=${OUTPUT_TYPE} --platform ${OS}/${ARCH} \ |
| 67 | + -t $(IMAGE)-${OS}-${ARCH} --build-arg BASE=${BASE} . |
| 68 | + |
| 69 | +.container-windows-$(ARCH): |
| 70 | + docker buildx build --pull --output=type=${OUTPUT_TYPE} --platform ${OS}/${ARCH} \ |
| 71 | + -t $(IMAGE)-${OS}-${ARCH}-${OSVERSION} --build-arg BASE=${BASE}:${OSVERSION} \ |
| 72 | + -f Dockerfile_windows . |
30 | 73 |
|
31 | | -push: OUTPUT=--push |
32 | | -push: configure-docker build |
| 74 | +# For Windows images, we also need to include the "os.version" in the manifest list images, |
| 75 | +# so the Windows node can pull the proper image it needs. |
| 76 | +push-manifest: |
| 77 | + docker manifest create --amend $(IMAGE) $(shell echo $(ALL_OS_ARCH) | sed -e "s~[^ ]*~$(IMAGE)\-&~g") |
| 78 | + set -x; for arch in $(ALL_ARCH.linux); do docker manifest annotate --os linux --arch $${arch} ${IMAGE} ${IMAGE}-linux-$${arch}; done |
| 79 | + # we use awk to also trim the quotes around the OS version string. |
| 80 | + set -x; \ |
| 81 | + for osversion in ${ALL_OSVERSIONS.windows}; do \ |
| 82 | + full_version=`docker manifest inspect ${BASE.windows}:$${osversion} | grep "os.version" | head -n 1 | awk -F\" '{print $$4}'` || true; \ |
| 83 | + docker manifest annotate --os windows --arch amd64 --os-version $${full_version} ${IMAGE} ${IMAGE}-windows-amd64-$${osversion}; \ |
| 84 | + done |
| 85 | + docker manifest push --purge ${IMAGE} |
33 | 86 |
|
34 | | -.PHONY: configure-docker build push |
| 87 | +.PHONY: configure-docker setup-buildx build push build-local build-registry container push-manifest |
0 commit comments