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
9+ BUSYBOX_IMAGE?=busybox:latest
10+ DIND_IMAGE?=docker:17.12.0-dind
11+ endif
12+
13+ ifeq ($(ARCH ) ,ppc64le)
14+ ARCHTAG:=-ppc64le
15+ GO_BUILD_VER?=latest
16+ BUSYBOX_IMAGE?=ppc64le/busybox:latest
17+ DIND_IMAGE?=ppc64le/docker:dind
18+ endif
19+
120# Disable make's implicit rules, which are not useful for golang, and slow down the build
221# considerably.
322.SUFFIXES :
423
5- GO_BUILD_VER? =v0.9
6-
724SRC_FILES =$(shell find . -type f -name '* .go')
825
926# These variables can be overridden by setting an environment variable.
1027LOCAL_IP_ENV? =$(shell ip route get 8.8.8.8 | head -1 | awk '{print $$7}')
1128
1229# Can choose different docker versions see list here - https://hub.docker.com/_/docker/
13- DOCKER_VERSION? =17.12.0-dind
1430HOST_CHECKOUT_DIR? =$(CURDIR )
15- CONTAINER_NAME? =calico/libnetwork-plugin
16- GO_BUILD_CONTAINER? =calico/go-build:$(GO_BUILD_VER )
17- PLUGIN_LOCATION? =$(CURDIR ) /dist/libnetwork-plugin
18- DOCKER_BINARY_CONTAINER? =docker-binary-container
31+ CONTAINER_NAME? =calico/libnetwork-plugin$(ARCHTAG )
32+ GO_BUILD_CONTAINER? =calico/go-build$(ARCHTAG ) :$(GO_BUILD_VER )
33+ DIST =dist/$(ARCH )
34+ PLUGIN_LOCATION? =$(CURDIR ) /$(DIST ) /libnetwork-plugin
35+ DOCKER_BINARY_CONTAINER? =docker-binary-container$(ARCHTAG )
1936
2037# To run with non-native docker (e.g. on Windows or OSX) you might need to overide this variable
2138LOCAL_USER_ID? =$(shell id -u $$USER)
@@ -39,39 +56,41 @@ install:
3956 CGO_ENABLED=0 go install github.com/projectcalico/libnetwork-plugin
4057
4158# Run the build in a container. Useful for CI
42- dist /libnetwork-plugin : vendor
43- -mkdir -p dist
59+ $( DIST ) /libnetwork-plugin : vendor
60+ -mkdir -p $( DIST )
4461 -mkdir -p .go-pkg-cache
4562 docker run --rm \
4663 -v $(CURDIR ) :/go/src/github.com/projectcalico/libnetwork-plugin:ro \
47- -v $(CURDIR ) /dist :/go/src/github.com/projectcalico/libnetwork-plugin/dist \
64+ -v $(CURDIR ) /$( DIST ) :/go/src/github.com/projectcalico/libnetwork-plugin/$( DIST ) \
4865 -v $(CURDIR ) /.go-pkg-cache:/go/pkg/:rw \
4966 -e LOCAL_USER_ID=$(LOCAL_USER_ID ) \
67+ -e ARCH=$(ARCH ) \
5068 $(GO_BUILD_CONTAINER ) sh -c ' \
5169 cd /go/src/github.com/projectcalico/libnetwork-plugin && \
5270 make build'
5371
5472build : $(SRC_FILES ) vendor
55- CGO_ENABLED=0 go build -v -i -o dist /libnetwork-plugin -ldflags " -X main.VERSION=$( shell git describe --tags --dirty) -s -w" main.go
73+ CGO_ENABLED=0 go build -v -i -o $( DIST ) /libnetwork-plugin -ldflags " -X main.VERSION=$( shell git describe --tags --dirty) -s -w" main.go
5674
57- $(CONTAINER_NAME ) : dist/libnetwork-plugin
58- docker build -t $(CONTAINER_NAME ) .
75+
76+ $(CONTAINER_NAME ) : $(DIST ) /libnetwork-plugin
77+ docker build -t $(CONTAINER_NAME ) -f Dockerfile$(ARCHTAG ) .
5978
6079# Perform static checks on the code. The golint checks are allowed to fail, the others must pass.
6180.PHONY : static-checks
6281static-checks : vendor
6382 docker run --rm \
6483 -e LOCAL_USER_ID=$(LOCAL_USER_ID ) \
6584 -v $(CURDIR ) :/go/src/github.com/projectcalico/libnetwork-plugin \
66- calico/go-build sh -c ' \
85+ $( GO_BUILD_CONTAINER ) sh -c ' \
6786 cd /go/src/github.com/projectcalico/libnetwork-plugin && \
6887 gometalinter --deadline=30s --disable-all --enable=goimports --enable=vet --enable=errcheck --enable=varcheck --enable=unused --enable=dupl $$(glide nv ) '
6988
7089run-etcd :
7190 @-docker rm -f calico-etcd
7291 docker run --detach \
7392 --net=host \
74- --name calico-etcd quay.io/coreos/etcd \
93+ --name calico-etcd quay.io/coreos/etcd:v3.2.5 $( ARCHTAG ) \
7594 etcd \
7695 --advertise-client-urls " http://$( LOCAL_IP_ENV) :2379,http://127.0.0.1:2379" \
7796 --listen-client-urls " http://0.0.0.0:2379"
@@ -85,28 +104,28 @@ endif
85104 # Check that the version output appears on a line of its own (the -x option to grep).
86105 # Tests that the "git tag" makes it into the binary. Main point is to catch "-dirty" builds
87106 @echo "Checking if the tag made it into the binary"
88- docker run --rm calico/libnetwork-plugin -v | grep -x $(VERSION) || (echo "Reported version:" `docker run --rm calico/libnetwork-plugin -v` "\nExpected version: $(VERSION)" && exit 1)
89- docker tag calico/libnetwork-plugin calico/libnetwork-plugin:$(VERSION)
90- docker tag calico/libnetwork-plugin quay.io/calico/libnetwork-plugin:$(VERSION)
91- docker tag calico/libnetwork-plugin quay.io/calico/libnetwork-plugin:latest
107+ docker run --rm calico/libnetwork-plugin$(ARCHTAG) -v | grep -x $(VERSION) || (echo "Reported version:" `docker run --rm calico/libnetwork-plugin$(ARCHTAG) -v` "\nExpected version: $(VERSION)" && exit 1)
108+ docker tag calico/libnetwork-plugin$(ARCHTAG) calico/libnetwork-plugin$(ARCHTAG) :$(VERSION)
109+ docker tag calico/libnetwork-plugin$(ARCHTAG) quay.io/calico/libnetwork-plugin$(ARCHTAG) :$(VERSION)
110+ docker tag calico/libnetwork-plugin$(ARCHTAG) quay.io/calico/libnetwork-plugin$(ARCHTAG) :latest
92111
93- @echo "Now push the tag and images. Then create a release on Github and attach the dist /libnetwork-plugin binary"
112+ @echo "Now push the tag and images. Then create a release on Github and attach the $(DIST) /libnetwork-plugin binary"
94113 @echo "git push origin $(VERSION)"
95- @echo "docker push calico/libnetwork-plugin:$(VERSION)"
96- @echo "docker push quay.io/calico/libnetwork-plugin:$(VERSION)"
97- @echo "docker push calico/libnetwork-plugin:latest"
98- @echo "docker push quay.io/calico/libnetwork-plugin:latest"
114+ @echo "docker push calico/libnetwork-plugin$(ARCHTAG) :$(VERSION)"
115+ @echo "docker push quay.io/calico/libnetwork-plugin$(ARCHTAG) :$(VERSION)"
116+ @echo "docker push calico/libnetwork-plugin$(ARCHTAG) :latest"
117+ @echo "docker push quay.io/calico/libnetwork-plugin$(ARCHTAG) :latest"
99118
100119clean :
101- rm -rf dist * .tar vendor docker .go-pkg-cache
120+ rm -rf $( DIST ) bin * .tar vendor .go-pkg-cache
102121
103- run-plugin : run-etcd dist /libnetwork-plugin
122+ run-plugin : run-etcd $( DIST ) /libnetwork-plugin
104123 -docker rm -f dind
105124 docker run -tid -h test --name dind --privileged $(ADDITIONAL_DIND_ARGS ) \
106125 -e ETCD_ENDPOINTS=http://$(LOCAL_IP_ENV ) :2379 \
107126 -p 5375:2375 \
108127 -v $(PLUGIN_LOCATION ) :/libnetwork-plugin \
109- docker: $( DOCKER_VERSION ) --cluster-store=etcd://$(LOCAL_IP_ENV ) :2379
128+ $( DIND_IMAGE ) --cluster-store=etcd://$(LOCAL_IP_ENV ) :2379
110129 # View the logs by running 'docker exec dind cat plugin.log'
111130 docker exec -tid --privileged dind sh -c ' sysctl -w net.ipv6.conf.default.disable_ipv6=0'
112131 docker exec -tid --privileged dind sh -c ' /libnetwork-plugin 2>>/plugin.log'
@@ -118,18 +137,28 @@ run-plugin: run-etcd dist/libnetwork-plugin
118137test :
119138 CGO_ENABLED=0 ginkgo -v tests/*
120139
121- test-containerized : dist/libnetwork-plugin
140+ # Target test-containerized needs the docker binary to be available in the go-build container.
141+ # Obtaining it from the docker:dind images docker should provided the latest version. However,
142+ # this assumes that the go_build container has the required dependencies or that docker is static.
143+ # This may not be the case in all configurations. In this cases you should pre-populate ./bin
144+ # with a docker binary compatible with the go-build image that is used.
145+ bin/docker :
122146 -docker rm -f $(DOCKER_BINARY_CONTAINER ) 2>&1
123- docker create --name $(DOCKER_BINARY_CONTAINER ) docker:$(DOCKER_VERSION )
124- docker cp $(DOCKER_BINARY_CONTAINER ) :/usr/local/bin/docker .
147+ mkdir -p ./bin
148+ docker create --name $(DOCKER_BINARY_CONTAINER ) $(DIND_IMAGE )
149+ docker cp $(DOCKER_BINARY_CONTAINER ) :/usr/local/bin/docker ./bin/docker
125150 docker rm -f $(DOCKER_BINARY_CONTAINER )
126- docker run -ti --rm --net=host \
151+
152+ test-containerized : $(DIST ) /libnetwork-plugin bin/docker
153+ docker run -t --rm --net=host \
127154 -v $(CURDIR ) :/go/src/github.com/projectcalico/libnetwork-plugin \
128155 -v /var/run/docker.sock:/var/run/docker.sock \
129- -v $(CURDIR ) /docker:/usr/bin/docker \
130- -e PLUGIN_LOCATION=$(CURDIR ) /dist /libnetwork-plugin \
156+ -v $(CURDIR ) /bin/ docker:/usr/bin/docker \
157+ -e PLUGIN_LOCATION=$(CURDIR ) /$( DIST ) /libnetwork-plugin \
131158 -e LOCAL_USER_ID=0 \
132- calico/go-build sh -c ' \
159+ -e ARCH=$(ARCH ) \
160+ -e BUSYBOX_IMAGE=$(BUSYBOX_IMAGE ) \
161+ $(GO_BUILD_CONTAINER ) sh -c ' \
133162 cd /go/src/github.com/projectcalico/libnetwork-plugin && \
134163 make test'
135164
0 commit comments