-
Notifications
You must be signed in to change notification settings - Fork 505
/
Makefile
93 lines (72 loc) · 2.76 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# Copyright 2017 The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Build the hyperkube base image. This image is used to build the hyperkube image.
#
# Usage:
# [ARCH=amd64] [REGISTRY="staging-k8s.gcr.io"] make (build|push)
REGISTRY?=gcr.io/k8s-staging-build-image
IMAGE?=$(REGISTRY)/debian-hyperkube-base
TAG?=buster-v1.4.0
ARCH?=amd64
ALL_ARCH = amd64 arm arm64 ppc64le s390x
BASE_REGISTRY?=k8s.gcr.io/build-image
BASEIMAGE?=$(BASE_REGISTRY)/debian-iptables-$(ARCH):buster-v1.5.0
CNI_VERSION?=v0.8.7
TEMP_DIR:=$(shell mktemp -d)
CNI_TARBALL=cni-plugins-linux-$(ARCH)-$(CNI_VERSION).tgz
QEMUVERSION=5.2.0-2
# This option is for running docker manifest command
export DOCKER_CLI_EXPERIMENTAL := enabled
SUDO=$(if $(filter 0,$(shell id -u)),,sudo)
.PHONY: all build push clean all-build all-push-images all-push push-manifest
all: all-push
sub-build-%:
$(MAKE) ARCH=$* build
all-build: $(addprefix sub-build-,$(ALL_ARCH))
sub-push-image-%:
$(MAKE) ARCH=$* push
all-push-images: $(addprefix sub-push-image-,$(ALL_ARCH))
all-push: all-push-images push-manifest
push-manifest:
docker manifest create --amend $(IMAGE):$(TAG) $(shell echo $(ALL_ARCH) | sed -e "s~[^ ]*~$(IMAGE)\-&:$(TAG)~g")
@for arch in $(ALL_ARCH); do docker manifest annotate --arch $${arch} ${IMAGE}:${TAG} ${IMAGE}-$${arch}:${TAG}; done
docker manifest push --purge ${IMAGE}:${TAG}
cni-tars/$(CNI_TARBALL):
mkdir -p cni-tars/
cd cni-tars/ && curl -sSLO --retry 5 https://storage.googleapis.com/k8s-artifacts-cni/release/${CNI_VERSION}/${CNI_TARBALL}
clean:
rm -rf cni-tars/
build: cni-tars/$(CNI_TARBALL)
cp Dockerfile $(TEMP_DIR)
cd $(TEMP_DIR) && sed -i "s|BASEIMAGE|$(BASEIMAGE)|g" Dockerfile
mkdir -p ${TEMP_DIR}/cni-bin/bin
tar -xz -C ${TEMP_DIR}/cni-bin/bin -f "cni-tars/${CNI_TARBALL}"
ifneq ($(ARCH),amd64)
# Register /usr/bin/qemu-ARCH-static as the handler for non-x86 binaries in the kernel
docker run --rm --privileged multiarch/qemu-user-static:$(QEMUVERSION) --reset -p yes
docker buildx version
BUILDER=$(shell docker buildx create --use)
endif
docker buildx build \
--pull \
--load \
--platform linux/$(ARCH) \
-t $(IMAGE)-$(ARCH):$(TAG) \
$(TEMP_DIR)
rm -rf $(TEMP_DIR)
ifneq ($(ARCH),amd64)
docker buildx rm $$BUILDER
endif
push: build
docker push $(IMAGE)-$(ARCH):$(TAG)