Skip to content

Commit 9a76ea3

Browse files
committed
Cross-compile multi-push and standard targets
1 parent e7f25e0 commit 9a76ea3

8 files changed

+141
-62
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ dist/
99
*.tmp
1010
*~
1111
.vscode/
12-
image.created
12+
image.created*
1313
vendor/
1414
dist/kube-controllers
1515
.go-pkg-cache

Dockerfile

-18
This file was deleted.

Dockerfile

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Dockerfile.amd64

Dockerfile.amd64

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Copyright 2015-2017 Tigera, Inc
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
FROM amd64/alpine:3.7
15+
LABEL maintainer "Casey Davenport <[email protected]>"
16+
17+
ADD dist/kube-controllers-linux-amd64 /usr/bin/kube-controllers
18+
ENTRYPOINT ["/usr/bin/kube-controllers"]

Dockerfile.arm64

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Copyright 2015-2017 Tigera, Inc
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
FROM arm64v8/alpine:3.7
15+
LABEL maintainer "Casey Davenport <[email protected]>"
16+
17+
ADD dist/kube-controllers-linux-amd64 /usr/bin/kube-controllers
18+
ENTRYPOINT ["/usr/bin/kube-controllers"]
File renamed without changes.
File renamed without changes.

Makefile

+101-41
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,50 @@
11
###############################################################################
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
916
endif
10-
11-
ifeq ($(ARCH),ppc64le)
12-
ARCHTAG:=-ppc64le
13-
GO_BUILD_VER?=latest
17+
ifeq ($(BUILDARCH),x86_64)
18+
BUILDARCH=amd64
1419
endif
1520

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
1927
endif
28+
ifeq ($(ARCH),x86_64)
29+
override ARCH=amd64
30+
endif
31+
32+
GO_BUILD_VER ?= v0.15
2033

2134
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
2340

2441
.PHONY: all binary build test clean help image
2542
default: help
2643

27-
# Makefile configuration options
28-
CONTAINER_NAME=calico/kube-controllers$(ARCHTAG)
44+
# Makefile configuration options
45+
CONTAINER_NAME=calico/kube-controllers
2946
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)
3148
LIBCALICOGO_PATH?=none
3249
LOCAL_USER_ID?=$(shell id -u $$USER)
3350

@@ -47,15 +64,19 @@ DOCKER_GO_BUILD := mkdir -p .go-pkg-cache && \
4764
$(CALICO_BUILD)
4865

4966
###############################################################################
50-
# Build targets
67+
# Build targets
5168
###############################################################################
5269
## 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)
5572
# 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) .
5774
touch $@
5875

76+
image-all: $(addprefix sub-image-,$(ARCHES))
77+
sub-image-%:
78+
$(MAKE) image ARCH=$*
79+
5980
dist/kube-controllers-linux-$(ARCH):
6081
$(MAKE) OS=linux ARCH=$(ARCH) binary-containerized
6182

@@ -90,22 +111,26 @@ binary: vendor
90111
-ldflags "-X main.VERSION=$(GIT_VERSION)" ./main.go
91112

92113
## 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)
94120
binary-containerized: vendor
95121
mkdir -p dist
96122
-mkdir -p .go-pkg-cache
97123
docker run --rm \
98124
-e OS=$(OS) -e ARCH=$(ARCH) \
99125
-v $(CURDIR):/go/src/$(PACKAGE_NAME):ro \
100126
-v $(CURDIR)/dist:/go/src/$(PACKAGE_NAME)/dist \
127+
-w /go/src/$(PACKAGE_NAME) \
101128
-e LOCAL_USER_ID=$(LOCAL_USER_ID) \
102129
-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
106131

107132
###############################################################################
108-
# Test targets
133+
# Test targets
109134
###############################################################################
110135

111136
## Builds the code and runs all tests.
@@ -125,13 +150,13 @@ ut: vendor
125150
GINKGO_FOCUS?=.*
126151
fv: tests/fv/fv.test image
127152
@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)
129154

130155
GET_CONTAINER_IP := docker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}'
131156
K8S_VERSION=1.7.5
132157
## Runs system tests.
133158
st: image run-etcd run-k8s-apiserver
134-
./tests/system/apiserver-reconnection.sh $(ARCHTAG)
159+
./tests/system/apiserver-reconnection.sh $(CONTAINER_NAME):latest-$(ARCH)
135160
$(MAKE) stop-k8s-apiserver stop-etcd
136161

137162
tests/fv/fv.test: $(shell find ./tests -type f -name '*.go' -print)
@@ -164,10 +189,49 @@ stop-etcd:
164189

165190
# Make sure that a copyright statement exists on all go files.
166191
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+
168232

169233
###############################################################################
170-
# Release targets
234+
# Release targets
171235
###############################################################################
172236
PREVIOUS_RELEASE=$(shell git describe --tags --abbrev=0)
173237

@@ -200,11 +264,9 @@ ifneq ($(VERSION), $(GIT_VERSION))
200264
endif
201265

202266
$(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)
206268
# Generate the `latest` images.
207-
docker tag $(CONTAINER_NAME) quay.io/$(CONTAINER_NAME):latest
269+
$(MAKE) tag-images IMAGETAG=latest
208270

209271
## Verifies the release artifacts produces by `make release-build` are correct.
210272
release-verify: release-prereqs
@@ -227,8 +289,7 @@ release-publish: release-prereqs
227289
git push origin $(VERSION)
228290

229291
# 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)
232293

233294
@echo "Finalize the GitHub release based on the pushed tag."
234295
@echo ""
@@ -247,8 +308,7 @@ release-publish-latest: release-prereqs
247308
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
248309
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
249310

250-
docker push calico/kube-controllers:latest
251-
docker push quay.io/calico/kube-controllers:latest
311+
$(MAKE) push IMAGETAG=latest ARCH=$(ARCH)
252312

253313
# release-prereqs checks that the environment is configured properly to create a release.
254314
release-prereqs:
@@ -258,13 +318,13 @@ endif
258318

259319
## Removes all build artifacts.
260320
clean:
261-
rm -rf dist image.created$(ARCHTAG)
321+
rm -rf dist image.created-$(ARCH)
262322
-docker rmi $(CONTAINER_NAME)
263323
rm -f st-kubeconfig.yaml
264324
rm -f tests/fv/fv.test
265325

266326
###############################################################################
267-
# Utilities
327+
# Utilities
268328
###############################################################################
269329

270330
.PHONY: help

tests/system/apiserver-reconnection.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash -ex
22

3-
ARCHTAG=$1
3+
IMAGE=$1
44

55
function get_container_ip {
66
docker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $1
@@ -59,7 +59,7 @@ docker run --detach --name=calico-policy-controller \
5959
-e KUBECONFIG=/st-kubeconfig.yaml \
6060
-e ENABLED_CONTROLLERS="workloadendpoint,profile,policy" \
6161
-e LOG_LEVEL="debug" \
62-
calico/kube-controllers$ARCHTAG
62+
${IMAGE}
6363
sleep 2
6464

6565
# Create a trap which emits policy controller logs on failure.

0 commit comments

Comments
 (0)