forked from projectcalico/libnetwork-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
145 lines (125 loc) · 5.95 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# Disable make's implicit rules, which are not useful for golang, and slow down the build
# considerably.
.SUFFIXES:
SRC_FILES=$(shell find . -type f -name '*.go')
# These variables can be overridden by setting an environment variable.
LOCAL_IP_ENV?=$(shell ip route get 8.8.8.8 | head -1 | awk '{print $$7}')
# Can choose different docker versions see list here - https://hub.docker.com/_/docker/
DOCKER_VERSION?=dind
HOST_CHECKOUT_DIR?=$(CURDIR)
CONTAINER_NAME?=hitomitak/libnetwork-plugin-ppc64le
CALICO_BUILD?=hitomitak/go-build-ppc64le
PLUGIN_LOCATION?=$(CURDIR)/dist/libnetwork-plugin
DOCKER_BINARY_CONTAINER?=docker-binary-container
# To run with non-native docker (e.g. on Windows or OSX) you might need to overide this variable
LOCAL_USER_ID?=$(shell id -u $$USER)
default: all
all: test
# Use this to populate the vendor directory after checking out the repository.
# To update upstream dependencies, delete the glide.lock file first.
vendor: glide.yaml
# To build without Docker just run "glide install -strip-vendor"
docker run --rm \
-v $(CURDIR):/go/src/github.com/projectcalico/libnetwork-plugin:rw \
-v $(HOME)/.glide:/home/user/.glide:rw \
-e LOCAL_USER_ID=$(LOCAL_USER_ID) \
$(CALICO_BUILD) /bin/sh -c ' \
cd /go/src/github.com/projectcalico/libnetwork-plugin && \
glide install -strip-vendor'
install:
CGO_ENABLED=0 go install github.com/projectcalico/libnetwork-plugin
# Run the build in a container. Useful for CI
dist/libnetwork-plugin: vendor
-mkdir -p dist
-mkdir -p .go-pkg-cache
docker run --rm \
-v $(CURDIR):/go/src/github.com/projectcalico/libnetwork-plugin:ro \
-v $(CURDIR)/dist:/go/src/github.com/projectcalico/libnetwork-plugin/dist \
-v $(CURDIR)/.go-pkg-cache:/go/pkg/:rw \
-e LOCAL_USER_ID=$(LOCAL_USER_ID) \
$(CALICO_BUILD) sh -c '\
cd /go/src/github.com/projectcalico/libnetwork-plugin && \
make build'
build: $(SRC_FILES) vendor
CGO_ENABLED=0 go build -v -i -o dist/libnetwork-plugin -ldflags "-X main.VERSION=$(shell git describe --tags --dirty) -s -w" main.go
$(CONTAINER_NAME): dist/libnetwork-plugin
docker build -t $(CONTAINER_NAME) .
# Perform static checks on the code. The golint checks are allowed to fail, the others must pass.
.PHONY: static-checks
static-checks: vendor
docker run --rm \
-e LOCAL_USER_ID=$(LOCAL_USER_ID) \
-v $(CURDIR):/go/src/github.com/projectcalico/libnetwork-plugin \
hitomitak/go-build-ppc64le sh -c '\
cd /go/src/github.com/projectcalico/libnetwork-plugin && \
gometalinter --deadline=30s --disable-all --enable=goimports --enable=vet --enable=errcheck --enable=varcheck --enable=unused --enable=dupl $$(glide nv)'
run-etcd:
@-docker rm -f calico-etcd
docker run --detach \
--net=host \
--name calico-etcd quay.io/coreos/etcd \
etcd \
--advertise-client-urls "http://$(LOCAL_IP_ENV):2379,http://127.0.0.1:2379" \
--listen-client-urls "http://0.0.0.0:2379"
semaphore: test-containerized
set -e; \
if [ -z $$PULL_REQUEST_NUMBER ]; then \
$(MAKE) $(CONTAINER_NAME); \
docker tag $(CONTAINER_NAME) $(CONTAINER_NAME):$$BRANCH_NAME && docker push $(CONTAINER_NAME):$$BRANCH_NAME; \
docker tag $(CONTAINER_NAME) quay.io/$(CONTAINER_NAME):$$BRANCH_NAME && docker push quay.io/$(CONTAINER_NAME):$$BRANCH_NAME; \
if [ "$$BRANCH_NAME" = "master" ]; then \
export VERSION=`git describe --tags --dirty`; \
docker tag $(CONTAINER_NAME) $(CONTAINER_NAME):$$VERSION && docker push $(CONTAINER_NAME):$$VERSION; \
docker tag $(CONTAINER_NAME) quay.io/$(CONTAINER_NAME):$$VERSION && docker push quay.io/$(CONTAINER_NAME):$$VERSION; \
fi; \
fi
release: clean
ifndef VERSION
$(error VERSION is undefined - run using make release VERSION=vX.Y.Z)
endif
git tag $(VERSION)
$(MAKE) $(CONTAINER_NAME)
# Check that the version output appears on a line of its own (the -x option to grep).
# Tests that the "git tag" makes it into the binary. Main point is to catch "-dirty" builds
@echo "Checking if the tag made it into the binary"
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)
docker tag calico/libnetwork-plugin calico/libnetwork-plugin:$(VERSION)
docker tag calico/libnetwork-plugin quay.io/calico/libnetwork-plugin:$(VERSION)
docker tag calico/libnetwork-plugin quay.io/calico/libnetwork-plugin:latest
@echo "Now push the tag and images. Then create a release on Github and attach the dist/libnetwork-plugin binary"
@echo "git push origin $(VERSION)"
@echo "docker push calico/libnetwork-plugin:$(VERSION)"
@echo "docker push quay.io/calico/libnetwork-plugin:$(VERSION)"
@echo "docker push calico/libnetwork-plugin:latest"
@echo "docker push quay.io/calico/libnetwork-plugin:latest"
clean:
rm -rf dist *.tar vendor docker .go-pkg-cache
run-plugin: run-etcd dist/libnetwork-plugin
-docker rm -f dind
docker run -tid -h test --name dind --privileged $(ADDITIONAL_DIND_ARGS) \
-e ETCD_ENDPOINTS=http://$(LOCAL_IP_ENV):2379 \
-p 5375:2375 \
-v $(PLUGIN_LOCATION):/libnetwork-plugin \
docker:$(DOCKER_VERSION) --cluster-store=etcd://$(LOCAL_IP_ENV):2379
# View the logs by running 'docker exec dind cat plugin.log'
docker exec -tid --privileged dind sh -c '/libnetwork-plugin 2>>/plugin.log'
# To speak to this docker:
# export DOCKER_HOST=localhost:5375
.PHONY: test
# Run the unit tests.
test:
CGO_ENABLED=0 ginkgo -v tests/*
test-containerized: dist/libnetwork-plugin
-docker rm -f $(DOCKER_BINARY_CONTAINER) 2>&1
docker create --name $(DOCKER_BINARY_CONTAINER) docker:$(DOCKER_VERSION)
docker cp $(DOCKER_BINARY_CONTAINER):/usr/local/bin/docker .
docker rm -f $(DOCKER_BINARY_CONTAINER)
docker run -ti --rm --net=host \
-v $(CURDIR):/go/src/github.com/projectcalico/libnetwork-plugin \
-v /var/run/docker.sock:/var/run/docker.sock \
-v $(CURDIR)/docker:/usr/bin/docker \
-e PLUGIN_LOCATION=$(CURDIR)/dist/libnetwork-plugin \
-e LOCAL_USER_ID=0 \
calico/go-build sh -c '\
cd /go/src/github.com/projectcalico/libnetwork-plugin && \
make test'