-
Notifications
You must be signed in to change notification settings - Fork 4.1k
/
Copy pathMakefile
106 lines (85 loc) · 3.35 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
94
95
96
97
98
99
100
101
102
103
104
105
106
# Copyright 2016 The Kubernetes Authors. All rights reserved#
#
# 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..
# Usage:
# Build docker image for all the architecture - make all
# Build and push images for all the architecture - make all-push
# Build for specific architecture(ppc64le) - make container ARCH=ppc64le
ALL_ARCH = amd64 arm arm64 ppc64le s390x
ARCH ?= amd64
GOARM=7
GOLANG_VERSION = 1.12.1
REGISTRY = staging-k8s.gcr.io
IMGNAME = addon-resizer
IMAGE = $(REGISTRY)/$(IMGNAME)
MULTI_ARCH_IMG = $(IMAGE)-$(ARCH)
TAG = 2.3
# The output type could either be docker (local), or registry.
OUTPUT_TYPE ?= docker
BASEIMAGE?=gcr.io/distroless/static:latest
TEMP_DIR := $(shell mktemp -d)
all: all-container
sub-container-%:
$(MAKE) ARCH=$* container
sub-manifest-push-%:
$(MAKE) ARCH=$* manifest-push
sub-push-%:
$(MAKE) ARCH=$* push
all-container: test $(addprefix sub-container-,$(ALL_ARCH))
all-manifest-push: $(addprefix sub-manifest-push-,$(ALL_ARCH))
docker manifest push -p $(IMAGE):$(TAG)
all-push: $(addprefix sub-push-,$(ALL_ARCH)) all-manifest-push
buildx-setup:
docker buildx inspect img-builder > /dev/null || docker buildx create --name img-builder --use
container: .container-$(ARCH)
.container-$(ARCH): buildx-setup
cp -r * $(TEMP_DIR)
cd $(TEMP_DIR) && sed -i 's|BASEIMAGE|$(BASEIMAGE)|g' Dockerfile
docker run --rm -v $(TEMP_DIR):$(TEMP_DIR):Z -v `pwd`:/go/src/k8s.io/autoscaler/addon-resizer/:Z \
golang:${GOLANG_VERSION} \
/bin/bash -c "\
go get github.com/tools/godep && \
cd /go/src/k8s.io/autoscaler/addon-resizer/ && \
CGO_ENABLED=0 GOARM=$(GOARM) GOARCH=$(ARCH) godep go build -a -installsuffix cgo --ldflags '-w -X k8s.io/autoscaler/addon-resizer/nanny.AddonResizerVersion=$(TAG)' -o $(TEMP_DIR)/pod_nanny main.go"
docker buildx build \
--pull \
--platform linux/$(ARCH) \
--output=type=$(OUTPUT_TYPE) \
-t $(MULTI_ARCH_IMG):$(TAG) $(TEMP_DIR)
ifeq ($(ARCH), amd64)
# This is for to maintain the backward compatibility
docker tag $(MULTI_ARCH_IMG):$(TAG) $(IMAGE):$(TAG)
endif
test:
docker run --rm -v `pwd`:/go/src/k8s.io/autoscaler/addon-resizer/:Z \
golang:${GOLANG_VERSION} \
/bin/bash -c "\
go get github.com/tools/godep && \
cd /go/src/k8s.io/autoscaler/addon-resizer/ && \
godep go test ./nanny -v"
push: .push-$(ARCH)
.push-$(ARCH): .container-$(ARCH)
gcloud docker -- push $(MULTI_ARCH_IMG):$(TAG)
ifeq ($(ARCH), amd64)
gcloud docker -- push $(IMAGE):$(TAG)
endif
manifest-push: .manifest-push-$(ARCH)
.manifest-push-$(ARCH):
docker manifest create --amend $(IMAGE):$(TAG) $(MULTI_ARCH_IMG):$(TAG) && \
docker manifest annotate --os=linux --arch=$(ARCH) $(IMAGE):$(TAG) $(MULTI_ARCH_IMG):$(TAG)
clean: $(addprefix sub-clean-,$(ALL_ARCH))
sub-clean-%:
docker rmi -f $(IMAGE)-$*:$(TAG) || true
ifeq ($(ARCH), amd64)
docker rmi -f $(IMAGE):$(TAG)
endif