1
1
# ##############################################################################
2
- # The build architecture is select by setting the ARCH variable.
3
- # For example: When building on ppc64le you could use ARCH=ppc64le make <....>.
4
- # When ARCH is undefined it defaults to amd64.
5
- ARCH? =amd64
6
- ifeq ($(ARCH ) ,amd64)
7
- ARCHTAG? =
8
- GO_BUILD_VER?=v0.12
2
+ # Both native and cross architecture builds are supported.
3
+ # The target architecture is select by setting the ARCH variable.
4
+ # When ARCH is undefined it is set to the detected host architecture.
5
+ # When ARCH differs from the host architecture a crossbuild will be performed.
6
+ ARCHES =amd64 arm64 ppc64le s390x
7
+
8
+ # BUILDARCH is the host architecture
9
+ # ARCH is the target architecture
10
+ # we need to keep track of them separately
11
+ BUILDARCH ?= $(shell uname -m)
12
+
13
+ # canonicalized names for host architecture
14
+ ifeq ($(BUILDARCH ) ,aarch64)
15
+ BUILDARCH =arm64
9
16
endif
10
-
11
- ifeq ($(ARCH ) ,ppc64le)
12
- ARCHTAG: =-ppc64le
13
- GO_BUILD_VER?=latest
17
+ ifeq ($(BUILDARCH ) ,x86_64)
18
+ BUILDARCH =amd64
14
19
endif
15
20
16
- ifeq ($(ARCH ) ,s390x)
17
- ARCHTAG:=-s390x
18
- GO_BUILD_VER?=latest
21
+ # unless otherwise set, I am building for my own architecture, i.e. not cross-compiling
22
+ ARCH ?= $(BUILDARCH )
23
+
24
+ # canonicalized names for target architecture
25
+ ifeq ($(ARCH ) ,aarch64)
26
+ override ARCH =arm64
19
27
endif
28
+ ifeq ($(ARCH ) ,x86_64)
29
+ override ARCH =amd64
30
+ endif
31
+
32
+ GO_BUILD_VER ?= v0.15
20
33
21
34
HYPERKUBE_IMAGE? =gcr.io/google_containers/hyperkube-$(ARCH ) :v1.8.0-beta.1
22
- ETCD_IMAGE? =quay.io/coreos/etcd:v3.2.5$(ARCHTAG )
35
+ ETCD_IMAGE ?= quay.io/coreos/etcd:v3.2.5-$(BUILDARCH )
36
+ # If building on amd64 omit the arch in the container name.
37
+ ifeq ($(BUILDARCH ) ,amd64)
38
+ ETCD_IMAGE =quay.io/coreos/etcd:v3.2.5
39
+ endif
23
40
24
41
.PHONY : all binary build test clean help image
25
42
default : help
26
43
27
- # Makefile configuration options
28
- CONTAINER_NAME =calico/kube-controllers$( ARCHTAG )
44
+ # Makefile configuration options
45
+ CONTAINER_NAME =calico/kube-controllers
29
46
PACKAGE_NAME? =github.com/projectcalico/kube-controllers
30
- CALICO_BUILD? =calico/go-build$( ARCHTAG ) :$(GO_BUILD_VER )
47
+ CALICO_BUILD? =calico/go-build:$(GO_BUILD_VER )
31
48
LIBCALICOGO_PATH? =none
32
49
LOCAL_USER_ID? =$(shell id -u $$USER)
33
50
@@ -47,15 +64,19 @@ DOCKER_GO_BUILD := mkdir -p .go-pkg-cache && \
47
64
$(CALICO_BUILD )
48
65
49
66
# ##############################################################################
50
- # Build targets
67
+ # Build targets
51
68
# ##############################################################################
52
69
# # Builds the controller binary and docker image.
53
- image : image.created$( ARCHTAG )
54
- image.created$( ARCHTAG ) : dist/kube-controllers-linux-$(ARCH )
70
+ image : image.created- $( ARCH )
71
+ image.created- $( ARCH ) : dist/kube-controllers-linux-$(ARCH )
55
72
# Build the docker image for the policy controller.
56
- docker build -t $(CONTAINER_NAME ) -f Dockerfile$( ARCHTAG ) .
73
+ docker build -t $(CONTAINER_NAME ) :latest- $( ARCH ) -f Dockerfile. $( ARCH ) .
57
74
touch $@
58
75
76
+ image-all : $(addprefix sub-image-,$(ARCHES ) )
77
+ sub-image-% :
78
+ $(MAKE ) image ARCH=$*
79
+
59
80
dist/kube-controllers-linux-$(ARCH ) :
60
81
$(MAKE ) OS=linux ARCH=$(ARCH ) binary-containerized
61
82
@@ -90,22 +111,26 @@ binary: vendor
90
111
-ldflags " -X main.VERSION=$( GIT_VERSION) " ./main.go
91
112
92
113
# # Builds the controller binary in a container.
93
- build : binary-containerized
114
+ .PHONY : build-all
115
+ build-all : $(addprefix sub-build-,$(ARCHES ) )
116
+ sub-build-% :
117
+ $(MAKE ) build ARCH=$*
118
+
119
+ build : dist/kube-controllers-linux-$(ARCH )
94
120
binary-containerized : vendor
95
121
mkdir -p dist
96
122
-mkdir -p .go-pkg-cache
97
123
docker run --rm \
98
124
-e OS=$(OS ) -e ARCH=$(ARCH ) \
99
125
-v $(CURDIR ) :/go/src/$(PACKAGE_NAME ) :ro \
100
126
-v $(CURDIR ) /dist:/go/src/$(PACKAGE_NAME ) /dist \
127
+ -w /go/src/$(PACKAGE_NAME ) \
101
128
-e LOCAL_USER_ID=$(LOCAL_USER_ID ) \
102
129
-v $(CURDIR ) /.go-pkg-cache:/go/pkg/:rw \
103
- $(CALICO_BUILD ) sh -c ' \
104
- cd /go/src/$(PACKAGE_NAME ) && \
105
- make OS=$(OS ) ARCH=$(ARCH ) binary'
130
+ $(CALICO_BUILD ) make OS=$(OS ) ARCH=$(ARCH ) binary
106
131
107
132
# ##############################################################################
108
- # Test targets
133
+ # Test targets
109
134
# ##############################################################################
110
135
111
136
# # Builds the code and runs all tests.
@@ -125,13 +150,13 @@ ut: vendor
125
150
GINKGO_FOCUS? =.*
126
151
fv : tests/fv/fv.test image
127
152
@echo Running Go FVs.
128
- cd tests/fv && ETCD_IMAGE=$(ETCD_IMAGE ) HYPERKUBE_IMAGE=$(HYPERKUBE_IMAGE ) CONTAINER_NAME=$(CONTAINER_NAME ) ./fv.test -ginkgo.slowSpecThreshold 30 -ginkgo.focus $(GINKGO_FOCUS )
153
+ cd tests/fv && ETCD_IMAGE=$(ETCD_IMAGE ) HYPERKUBE_IMAGE=$(HYPERKUBE_IMAGE ) CONTAINER_NAME=$(CONTAINER_NAME ) :latest- $( ARCH ) ./fv.test -ginkgo.slowSpecThreshold 30 -ginkgo.focus $(GINKGO_FOCUS )
129
154
130
155
GET_CONTAINER_IP := docker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}'
131
156
K8S_VERSION =1.7.5
132
157
# # Runs system tests.
133
158
st : image run-etcd run-k8s-apiserver
134
- ./tests/system/apiserver-reconnection.sh $(ARCHTAG )
159
+ ./tests/system/apiserver-reconnection.sh $(CONTAINER_NAME ) :latest- $( ARCH )
135
160
$(MAKE ) stop-k8s-apiserver stop-etcd
136
161
137
162
tests/fv/fv.test : $(shell find ./tests -type f -name '* .go' -print)
@@ -164,10 +189,49 @@ stop-etcd:
164
189
165
190
# Make sure that a copyright statement exists on all go files.
166
191
check-copyright :
167
- ./check-copyrights.sh
192
+ ./check-copyrights.sh
193
+
194
+ # ##############################################################################
195
+ # tag and push images of any tag
196
+ # ##############################################################################
197
+
198
+
199
+ # ensure we have a real imagetag
200
+ imagetag :
201
+ ifndef IMAGETAG
202
+ $(error IMAGETAG is undefined - run using make <target> IMAGETAG=X.Y.Z)
203
+ endif
204
+
205
+ # # push one arch
206
+ push : imagetag
207
+ docker push $(CONTAINER_NAME ) :$(IMAGETAG ) -$(ARCH )
208
+ docker push quay.io/$(CONTAINER_NAME ) :$(IMAGETAG ) -$(ARCH )
209
+ ifeq ($(ARCH ) ,amd64)
210
+ docker push $(CONTAINER_NAME):$(IMAGETAG)
211
+ docker push quay.io/$(CONTAINER_NAME):$(IMAGETAG)
212
+ endif
213
+
214
+ push-all : imagetag $(addprefix sub-push-,$(ARCHES ) )
215
+ sub-push-% :
216
+ $(MAKE ) push ARCH=$* IMAGETAG=$(IMAGETAG )
217
+
218
+ # # tag images of one arch
219
+ tag-images : imagetag
220
+ docker tag $(CONTAINER_NAME ) :latest-$(ARCH ) $(CONTAINER_NAME ) :$(IMAGETAG ) -$(ARCH )
221
+ docker tag $(CONTAINER_NAME ) :latest-$(ARCH ) quay.io/$(CONTAINER_NAME ) :$(IMAGETAG ) -$(ARCH )
222
+ ifeq ($(ARCH ) ,amd64)
223
+ docker tag $(CONTAINER_NAME):latest-$(ARCH) $(CONTAINER_NAME):$(IMAGETAG)
224
+ docker tag $(CONTAINER_NAME):latest-$(ARCH) quay.io/$(CONTAINER_NAME):$(IMAGETAG)
225
+ endif
226
+
227
+ # # tag images of all archs
228
+ tag-images-all : imagetag $(addprefix sub-tag-images-,$(ARCHES ) )
229
+ sub-tag-images-% :
230
+ $(MAKE ) tag-images ARCH=$* IMAGETAG=$(IMAGETAG )
231
+
168
232
169
233
# ##############################################################################
170
- # Release targets
234
+ # Release targets
171
235
# ##############################################################################
172
236
PREVIOUS_RELEASE =$(shell git describe --tags --abbrev=0)
173
237
@@ -200,11 +264,9 @@ ifneq ($(VERSION), $(GIT_VERSION))
200
264
endif
201
265
202
266
$(MAKE) image
203
- docker tag $(CONTAINER_NAME) $(CONTAINER_NAME):$(VERSION)
204
- docker tag $(CONTAINER_NAME) quay.io/$(CONTAINER_NAME):$(VERSION)
205
-
267
+ $(MAKE) tag-images IMAGETAG=$(VERSION)
206
268
# Generate the `latest` images.
207
- docker tag $(CONTAINER_NAME) quay.io/$(CONTAINER_NAME): latest
269
+ $(MAKE) tag-images IMAGETAG= latest
208
270
209
271
# # Verifies the release artifacts produces by `make release-build` are correct.
210
272
release-verify : release-prereqs
@@ -227,8 +289,7 @@ release-publish: release-prereqs
227
289
git push origin $(VERSION )
228
290
229
291
# Push images.
230
- docker push calico/kube-controllers:$(VERSION)
231
- docker push quay.io/calico/kube-controllers:$(VERSION)
292
+ $(MAKE) push IMAGETAG=$(VERSION) ARCH=$(ARCH)
232
293
233
294
@echo "Finalize the GitHub release based on the pushed tag."
234
295
@echo ""
@@ -247,8 +308,7 @@ release-publish-latest: release-prereqs
247
308
if ! docker run calico/kube-controllers:latest -v | grep ' ^$(VERSION)$$' ; then echo " Reported version:" ` docker run calico/kube-controllers:latest -v` " \nExpected version: $( VERSION) " ; false ; else echo " \nVersion check passed\n" ; fi
248
309
if ! docker run quay.io/calico/kube-controllers:latest -v | grep ' ^$(VERSION)$$' ; then echo " Reported version:" ` docker run quay.io/calico/kube-controllers:latest -v` " \nExpected version: $( VERSION) " ; false ; else echo " \nVersion check passed\n" ; fi
249
310
250
- docker push calico/kube-controllers:latest
251
- docker push quay.io/calico/kube-controllers:latest
311
+ $(MAKE) push IMAGETAG=latest ARCH=$(ARCH)
252
312
253
313
# release-prereqs checks that the environment is configured properly to create a release.
254
314
release-prereqs :
@@ -258,13 +318,13 @@ endif
258
318
259
319
# # Removes all build artifacts.
260
320
clean :
261
- rm -rf dist image.created$( ARCHTAG )
321
+ rm -rf dist image.created- $( ARCH )
262
322
-docker rmi $(CONTAINER_NAME )
263
323
rm -f st-kubeconfig.yaml
264
324
rm -f tests/fv/fv.test
265
325
266
326
# ##############################################################################
267
- # Utilities
327
+ # Utilities
268
328
# ##############################################################################
269
329
270
330
.PHONY : help
0 commit comments