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
+
1
20
# Disable make's implicit rules, which are not useful for golang, and slow down the build
2
21
# considerably.
3
22
.SUFFIXES :
4
23
5
- GO_BUILD_VER? =v0.9
6
-
7
24
SRC_FILES =$(shell find . -type f -name '* .go')
8
25
9
26
# These variables can be overridden by setting an environment variable.
10
27
LOCAL_IP_ENV? =$(shell ip route get 8.8.8.8 | head -1 | awk '{print $$7}')
11
28
12
29
# Can choose different docker versions see list here - https://hub.docker.com/_/docker/
13
- DOCKER_VERSION? =17.12.0-dind
14
30
HOST_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 )
19
36
20
37
# To run with non-native docker (e.g. on Windows or OSX) you might need to overide this variable
21
38
LOCAL_USER_ID? =$(shell id -u $$USER)
@@ -39,39 +56,41 @@ install:
39
56
CGO_ENABLED=0 go install github.com/projectcalico/libnetwork-plugin
40
57
41
58
# 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 )
44
61
-mkdir -p .go-pkg-cache
45
62
docker run --rm \
46
63
-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 ) \
48
65
-v $(CURDIR ) /.go-pkg-cache:/go/pkg/:rw \
49
66
-e LOCAL_USER_ID=$(LOCAL_USER_ID ) \
67
+ -e ARCH=$(ARCH ) \
50
68
$(GO_BUILD_CONTAINER ) sh -c ' \
51
69
cd /go/src/github.com/projectcalico/libnetwork-plugin && \
52
70
make build'
53
71
54
72
build : $(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
56
74
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 ) .
59
78
60
79
# Perform static checks on the code. The golint checks are allowed to fail, the others must pass.
61
80
.PHONY : static-checks
62
81
static-checks : vendor
63
82
docker run --rm \
64
83
-e LOCAL_USER_ID=$(LOCAL_USER_ID ) \
65
84
-v $(CURDIR ) :/go/src/github.com/projectcalico/libnetwork-plugin \
66
- calico/go-build sh -c ' \
85
+ $( GO_BUILD_CONTAINER ) sh -c ' \
67
86
cd /go/src/github.com/projectcalico/libnetwork-plugin && \
68
87
gometalinter --deadline=30s --disable-all --enable=goimports --enable=vet --enable=errcheck --enable=varcheck --enable=unused --enable=dupl $$(glide nv ) '
69
88
70
89
run-etcd :
71
90
@-docker rm -f calico-etcd
72
91
docker run --detach \
73
92
--net=host \
74
- --name calico-etcd quay.io/coreos/etcd \
93
+ --name calico-etcd quay.io/coreos/etcd:v3.2.5 $( ARCHTAG ) \
75
94
etcd \
76
95
--advertise-client-urls " http://$( LOCAL_IP_ENV) :2379,http://127.0.0.1:2379" \
77
96
--listen-client-urls " http://0.0.0.0:2379"
@@ -85,28 +104,28 @@ endif
85
104
# Check that the version output appears on a line of its own (the -x option to grep).
86
105
# Tests that the "git tag" makes it into the binary. Main point is to catch "-dirty" builds
87
106
@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
92
111
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"
94
113
@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"
99
118
100
119
clean :
101
- rm -rf dist * .tar vendor docker .go-pkg-cache
120
+ rm -rf $( DIST ) bin * .tar vendor .go-pkg-cache
102
121
103
- run-plugin : run-etcd dist /libnetwork-plugin
122
+ run-plugin : run-etcd $( DIST ) /libnetwork-plugin
104
123
-docker rm -f dind
105
124
docker run -tid -h test --name dind --privileged $(ADDITIONAL_DIND_ARGS ) \
106
125
-e ETCD_ENDPOINTS=http://$(LOCAL_IP_ENV ) :2379 \
107
126
-p 5375:2375 \
108
127
-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
110
129
# View the logs by running 'docker exec dind cat plugin.log'
111
130
docker exec -tid --privileged dind sh -c ' sysctl -w net.ipv6.conf.default.disable_ipv6=0'
112
131
docker exec -tid --privileged dind sh -c ' /libnetwork-plugin 2>>/plugin.log'
@@ -118,18 +137,28 @@ run-plugin: run-etcd dist/libnetwork-plugin
118
137
test :
119
138
CGO_ENABLED=0 ginkgo -v tests/*
120
139
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 :
122
146
-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
125
150
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 \
127
154
-v $(CURDIR ) :/go/src/github.com/projectcalico/libnetwork-plugin \
128
155
-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 \
131
158
-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 ' \
133
162
cd /go/src/github.com/projectcalico/libnetwork-plugin && \
134
163
make test'
135
164
0 commit comments