-
Notifications
You must be signed in to change notification settings - Fork 502
/
Makefile
87 lines (67 loc) · 2.64 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
# Copyright 2022 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.
.PHONY: build push all all-build all-push-images all-push push-manifest
REGISTRY?="gcr.io/k8s-staging-build-image"
IMAGE=$(REGISTRY)/distroless-iptables
TAG ?= $(shell git describe --tags --always --dirty)
IMAGE_VERSION ?= v0.2.0
CONFIG ?= distroless
BASEIMAGE ?= debian:bullseye-slim
GORUNNER_VERSION ?= v2.3.1-go1.19.1-bullseye.0
ARCH?=amd64
ALL_ARCH = amd64 arm arm64 ppc64le s390x
BASE_REGISTRY?=k8s.gcr.io/build-image
GORUNNERIMAGE?=$(BASE_REGISTRY)/go-runner:$(GORUNNER_VERSION)
QEMUVERSION=6.1.0-8
ifneq ($(ARCH), amd64)
SKIP_WRAPPER_CHECK=--no-sanity-check
endif
# This option is for running docker manifest command
export DOCKER_CLI_EXPERIMENTAL := enabled
SUDO=$(if $(filter 0,$(shell id -u)),,sudo)
build:
# Fix possible issues with the local umask
umask 0022
# Enable execution of multi-architecture containers
docker run --rm --privileged multiarch/qemu-user-static:$(QEMUVERSION) --reset -p yes
docker buildx version
BUILDER=$(shell docker buildx create --use)
docker buildx build \
--pull \
--load \
--platform linux/$(ARCH) \
-t $(IMAGE)-$(ARCH):$(IMAGE_VERSION) \
-t $(IMAGE)-$(ARCH):$(TAG)-$(CONFIG) \
-t $(IMAGE)-$(ARCH):latest-$(CONFIG) \
--build-arg=BASEIMAGE=$(BASEIMAGE) \
--build-arg=GORUNNERIMAGE=$(GORUNNERIMAGE) \
--build-arg=SKIP_WRAPPER_CHECK=$(SKIP_WRAPPER_CHECK) \
$(CONFIG)
docker buildx rm $$BUILDER
push: build
docker push $(IMAGE)-$(ARCH):$(IMAGE_VERSION)
docker push $(IMAGE)-$(ARCH):$(TAG)-$(CONFIG)
docker push $(IMAGE)-$(ARCH):latest-$(CONFIG)
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):$(IMAGE_VERSION) $(shell echo $(ALL_ARCH) | sed -e "s~[^ ]*~$(IMAGE)\-&:$(IMAGE_VERSION)~g")
@for arch in $(ALL_ARCH); do docker manifest annotate --arch $${arch} ${IMAGE}:${IMAGE_VERSION} ${IMAGE}-$${arch}:${IMAGE_VERSION}; done
docker manifest push --purge ${IMAGE}:${IMAGE_VERSION}
all: all-push