15
15
# Build the node-problem-detector image.
16
16
17
17
.PHONY : all build-container build-tar build push-container push-tar push \
18
- clean vet fmt version \
19
- Dockerfile build-binaries docker-builder build-in-docker
18
+ clean vet fmt version \
19
+ Dockerfile build-binaries docker-builder build-in-docker \
20
+ build-all build-all-container \
21
+ build-tar-all push-all push-all-container push-manifest push-tar-all qemu-register \
22
+ release-staging
23
+
24
+ TEMP_DIR := $(shell mktemp -d)
20
25
21
26
all : build
22
27
@@ -26,9 +31,19 @@ VERSION?=$(shell if [ -d .git ]; then echo `git describe --tags --dirty`; else e
26
31
# TAG is the tag of the container image, default to binary version.
27
32
TAG? =$(VERSION )
28
33
34
+ ARCH ?= $(shell go env GOARCH)
35
+ ALL_ARCH = amd64 arm arm64 ppc64le s390x
36
+ QEMUVERSION =v4.0.0-4
37
+
38
+ # This option is for running docker manifest command
39
+ export DOCKER_CLI_EXPERIMENTAL := enabled
40
+
29
41
# REGISTRY is the container registry to push into.
30
42
REGISTRY? =staging-k8s.gcr.io
31
43
44
+ # STAGING_REGISTRY is the new registry for staging
45
+ STAGING_REGISTRY? =gcr.io/k8s-staging-npd
46
+
32
47
# UPLOAD_PATH is the cloud storage path to upload release tar.
33
48
UPLOAD_PATH? =gs://kubernetes-release
34
49
# Trim the trailing '/' in the path
@@ -44,20 +59,45 @@ PKG_SOURCES:=$(shell find pkg cmd -name '*.go')
44
59
PARALLEL? =3
45
60
46
61
# TARBALL is the name of release tar. Include binary version by default.
47
- TARBALL? =node-problem-detector-$(VERSION ) .tar.gz
62
+ TARBALL: =node-problem-detector-$(VERSION ) .tar.gz
63
+ TARBALL-ALL: =node-problem-detector-$(VERSION ) -all.tar.gz
48
64
49
65
# IMAGE is the image name of the node problem detector container image.
50
66
IMAGE: =$(REGISTRY ) /node-problem-detector:$(TAG )
67
+ IMAGE_WITH_ARCH: =$(IMAGE ) -$(ARCH )
51
68
52
69
# ENABLE_JOURNALD enables build journald support or not. Building journald
53
70
# support needs libsystemd-dev or libsystemd-journal-dev.
54
71
ENABLE_JOURNALD? =1
55
72
56
- # TODO(random-liu): Support different architectures.
57
73
# The debian-base:v1.0.0 image built from kubernetes repository is based on
58
74
# Debian Stretch. It includes systemd 232 with support for both +XZ and +LZ4
59
75
# compression. +LZ4 is needed on some os distros such as COS.
60
- BASEIMAGE: =k8s.gcr.io/debian-base-amd64:v1.0.0
76
+ # Set the (cross) compiler, BASEIMAGE to use for different architectures
77
+ ifeq ($(ARCH ) ,amd64)
78
+ CC=gcc
79
+ BASEIMAGE:=k8s.gcr.io/debian-base-amd64:v1.0.0
80
+ endif
81
+ ifeq ($(ARCH ) ,arm)
82
+ QEMUARCH=arm
83
+ CC=arm-linux-gnueabihf-gcc
84
+ BASEIMAGE:=k8s.gcr.io/debian-base-arm:v1.0.0
85
+ endif
86
+ ifeq ($(ARCH ) ,arm64)
87
+ QEMUARCH=aarch64
88
+ CC=aarch64-linux-gnu-gcc
89
+ BASEIMAGE:=k8s.gcr.io/debian-base-arm64:v1.0.0
90
+ endif
91
+ ifeq ($(ARCH ) ,ppc64le)
92
+ QEMUARCH=ppc64le
93
+ CC=powerpc64le-linux-gnu-gcc
94
+ BASEIMAGE:=k8s.gcr.io/debian-base-ppc64le:v1.0.0
95
+ endif
96
+ ifeq ($(ARCH ) ,s390x)
97
+ QEMUARCH=s390x
98
+ CC=s390x-linux-gnu-gcc
99
+ BASEIMAGE:=k8s.gcr.io/debian-base-s390x:v1.0.0
100
+ endif
61
101
62
102
# Disable cgo by default to make the binary statically linked.
63
103
CGO_ENABLED: =0
@@ -88,9 +128,9 @@ version:
88
128
89
129
./bin/log-counter : $(PKG_SOURCES )
90
130
ifeq ($(ENABLE_JOURNALD ) , 1)
91
- CGO_ENABLED=$(CGO_ENABLED) GOOS=linux GO111MODULE=on go build \
131
+ CGO_ENABLED=$(CGO_ENABLED) GOOS=linux GOARCH=$(ARCH) GO111MODULE=on go build \
92
132
-mod vendor \
93
- -o bin/log-counter \
133
+ -o bin/log-counter-$(ARCH) \
94
134
-ldflags '-X $(PKG)/pkg/version.version=$(VERSION)' \
95
135
-tags "$(BUILD_TAGS)" \
96
136
cmd/logcounter/log_counter.go
@@ -99,27 +139,38 @@ else
99
139
endif
100
140
101
141
./bin/node-problem-detector : $(PKG_SOURCES )
102
- CGO_ENABLED=$(CGO_ENABLED ) GOOS=linux GO111MODULE=on go build \
142
+ CGO_ENABLED=$(CGO_ENABLED ) GOOS=linux GOARCH= $( ARCH ) GO111MODULE=on go build \
103
143
-mod vendor \
104
- -o bin/node-problem-detector \
144
+ -o bin/node-problem-detector- $( ARCH ) \
105
145
-ldflags ' -X $(PKG)/pkg/version.version=$(VERSION)' \
106
146
-tags " $( BUILD_TAGS) " \
107
147
./cmd/nodeproblemdetector
108
148
109
149
./test/bin/problem-maker : $(PKG_SOURCES )
110
- CGO_ENABLED=$(CGO_ENABLED ) GOOS=linux GO111MODULE=on go build \
150
+ CGO_ENABLED=$(CGO_ENABLED ) GOOS=linux GOARCH= $( ARCH ) GO111MODULE=on go build \
111
151
-mod vendor \
112
152
-o test/bin/problem-maker \
113
153
-tags " $( BUILD_TAGS) " \
114
154
./test/e2e/problemmaker/problem_maker.go
115
155
156
+ qemu-register :
157
+ docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
158
+
116
159
Dockerfile : Dockerfile.in
117
160
sed -e ' s|@BASEIMAGE@|$(BASEIMAGE)|g' $< > $@
118
161
ifneq ($(ENABLE_JOURNALD ) , 1)
119
162
sed -i '/Below command depends on ENABLE_JOURNAL=1/,+2d' $@
120
163
echo "Warning: log-counter requires journald, skipping."
121
164
endif
122
-
165
+ sed -i "s|-ARCH|-$(QEMUARCH)|g" $@
166
+ sed -i "s|-BINARCH|-$(ARCH)|g" $@
167
+ ifeq ($(ARCH ) ,amd64)
168
+ # When building "normally" for amd64, remove the whole line, it has no part in the amd64 image
169
+ sed -i "/CROSS_BUILD_/d" Dockerfile
170
+ else
171
+ curl -sSL https://github.com/multiarch/qemu-user-static/releases/download/$(QEMUVERSION)/x86_64_qemu-$(QEMUARCH)-static.tar.gz | tar -xz -C .
172
+ sed -i "s/CROSS_BUILD_//g" Dockerfile
173
+ endif
123
174
124
175
test : vet fmt
125
176
GO111MODULE=on go test -mod vendor -timeout=1m -v -race -short -tags " $( BUILD_TAGS) " ./...
@@ -136,35 +187,71 @@ e2e-test: vet fmt build-tar
136
187
137
188
build-binaries : ./bin/node-problem-detector ./bin/log-counter
138
189
139
- build-container : build-binaries Dockerfile
140
- docker build -t $(IMAGE ) .
190
+ build-all-container : $(addprefix build-container-,$(ALL_ARCH ) )
191
+
192
+ build-container-% : qemu-register
193
+ $(MAKE ) ARCH=$* build-container
194
+
195
+ build-container : clean build-in-docker Dockerfile
196
+ docker build -t $(IMAGE_WITH_ARCH ) .
141
197
142
198
build-tar : ./bin/node-problem-detector ./bin/log-counter ./test/bin/problem-maker
143
199
tar -zcvf $(TARBALL ) bin/ config/ test/e2e-install.sh test/bin/problem-maker
144
200
sha1sum $(TARBALL )
145
201
md5sum $(TARBALL )
146
202
203
+ build-tar-all : clean
204
+ @for arch in $(ALL_ARCH ) ; do $(MAKE ) ARCH=$$ {arch} build-in-docker; done
205
+ @for arch in $(ALL_ARCH ) ; do cp bin/node-problem-detector-$(ARCH ) bin/node-problem-detector; done
206
+ @for arch in $(ALL_ARCH ) ; do cp bin/log-counter-$(ARCH ) bin/log-counter; done
207
+ tar -zcvf $(TARBALL-ALL ) bin/ config/ test/e2e-install.sh
208
+ sha1sum $(TARBALL-ALL )
209
+ md5sum $(TARBALL-ALL )
210
+
211
+ build-all : build-all-container build-tar-all
212
+
147
213
build : build-container build-tar
148
214
149
215
docker-builder :
150
216
docker build -t npd-builder ./builder
151
217
152
- build-in-docker : clean docker-builder
218
+ build-in-docker : docker-builder
153
219
docker run \
220
+ -e CC=$(CC ) -e GOARM=$(GOARM ) -e GOARCH=$(ARCH ) -e GOCACHE=/go/.cache/go-build \
221
+ -u $(shell id -u ${USER}) :$(shell id -g ${USER}) \
154
222
-v ` pwd` :/gopath/src/k8s.io/node-problem-detector/ npd-builder:latest bash \
155
223
-c ' cd /gopath/src/k8s.io/node-problem-detector/ && make build-binaries'
156
224
225
+ push-all-container : build-all-container $(addprefix push-container-,$(ALL_ARCH ) )
226
+
227
+ push-container-% :
228
+ $(MAKE ) ARCH=$* push-container
229
+
157
230
push-container : build-container
158
231
gcloud auth configure-docker
159
- docker push $(IMAGE )
232
+ docker push $(IMAGE_WITH_ARCH )
233
+
234
+ push-manifest :
235
+ gcloud auth configure-docker
236
+ docker manifest create --amend $(IMAGE ) $(shell echo $(ALL_ARCH ) | sed -e "s~[^ ]* ~$(IMAGE ) \-&~g")
237
+ @for arch in $(ALL_ARCH ) ; do docker manifest annotate --arch $$ {arch} ${IMAGE} ${IMAGE} -$$ {arch}; done
238
+ docker manifest push --purge ${IMAGE}
160
239
161
240
push-tar : build-tar
162
241
gsutil cp $(TARBALL ) $(UPLOAD_PATH ) /node-problem-detector/
163
242
243
+ push-tar-all : build-tar-all
244
+ gsutil cp $(TARBALL-ALL ) $(UPLOAD_PATH ) /node-problem-detector/
245
+
246
+ push-all : push-all-container push-manifest push-tar-all push-tar
247
+
164
248
push : push-container push-tar
165
249
250
+ release-staging :
251
+ REGISTRY=$(STAGING_REGISTRY ) $(MAKE ) push-all
252
+
166
253
clean :
167
- rm -f bin/log-counter
168
- rm -f bin/node-problem-detector
169
- rm -f test/bin/problem-maker
254
+ rm -f bin/log-counter*
255
+ rm -f bin/node-problem-detector*
256
+ rm -f test/bin/problem-maker*
170
257
rm -f node-problem-detector-* .tar.gz
0 commit comments