forked from projectcalico/confd
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
123 lines (101 loc) · 4.18 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
# Disable make's implicit rules, which are not useful for golang, and slow down the build
# considerably.
.SUFFIXES:
all: clean test
GO_BUILD_CONTAINER?=calico/go-build:v0.4
K8S_VERSION=v1.7.4
ETCDCTL_VER=v3.1.8
BIRD_VER=v0.3.1
LOCAL_IP_ENV?=$(shell ip route get 8.8.8.8 | head -1 | awk '{print $$7}')
# Ensure that the bin directory is always created
MAKE_SURE_BIN_EXIST := $(shell mkdir -p bin)
# All go files.
GO_FILES:=$(shell find . -type f -name '*.go')
# Figure out the users UID. This is needed to run docker containers
# as the current user and ensure that files built inside containers are
# owned by the current user.
MY_UID:=$(shell id -u)
DOCKER_GO_BUILD := mkdir -p .go-pkg-cache && \
docker run --rm \
--net=host \
$(EXTRA_DOCKER_ARGS) \
-e LOCAL_USER_ID=$(MY_UID) \
-v ${CURDIR}:/go/src/github.com/kelseyhightower/confd:rw \
-v ${CURDIR}/.go-pkg-cache:/go/pkg:rw \
-w /go/src/github.com/kelseyhightower/confd \
$(GO_BUILD_CONTAINER)
# Update the vendored dependencies with the latest upstream versions matching
# our glide.yaml. If there are any changes, this updates glide.lock
# as a side effect. Unless you're adding/updating a dependency, you probably
# want to use the vendor target to install the versions from glide.lock.
.PHONY: update-vendor
update-vendor:
mkdir -p $$HOME/.glide
$(DOCKER_GO_BUILD) glide up --strip-vendor
touch vendor/.up-to-date
# vendor is a shortcut for force rebuilding the go vendor directory.
.PHONY: vendor
vendor vendor/.up-to-date: glide.lock
mkdir -p $$HOME/.glide
$(DOCKER_GO_BUILD) glide install --strip-vendor
touch vendor/.up-to-date
bin/confd: $(GO_FILES) vendor/.up-to-date
@echo Building confd...
$(DOCKER_GO_BUILD) \
sh -c 'go build -v -i -o $@ "github.com/kelseyhightower/confd" && \
( ldd bin/confd 2>&1 | grep -q "Not a valid dynamic program" || \
( echo "Error: bin/confd was not statically linked"; false ) )'
.PHONY: test
## Run all tests
test: test-kdd test-etcd
.PHONY: test-kdd
## Run template tests against KDD
test-kdd: bin/confd bin/kubectl bin/bird bin/bird6 run-k8s-apiserver
docker run --rm --net=host \
-v $(CURDIR)/tests/:/tests/ \
-v $(CURDIR)/bin:/calico/bin/ \
-e LOCAL_USER_ID=0 \
$(GO_BUILD_CONTAINER) /tests/test_suite_kdd.sh
.PHONY: test-etcd
## Run template tests against etcd
test-etcd: bin/confd bin/etcdctl bin/bird bin/bird6 run-etcd
docker run --rm --net=host \
-v $(CURDIR)/tests/:/tests/ \
-v $(CURDIR)/bin:/calico/bin/ \
-e LOCAL_USER_ID=0 \
$(GO_BUILD_CONTAINER) /tests/test_suite_etcd.sh
## Etcd is used by the kubernetes
run-etcd: stop-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,http://$(LOCAL_IP_ENV):4001,http://127.0.0.1:4001" \
--listen-client-urls "http://0.0.0.0:2379,http://0.0.0.0:4001"
## Stops calico-etcd containers
stop-etcd:
@-docker rm -f calico-etcd
## Kubernetes apiserver used for tests
run-k8s-apiserver: stop-k8s-apiserver run-etcd
docker run --detach --net=host \
--name calico-k8s-apiserver \
gcr.io/google_containers/hyperkube-amd64:$(K8S_VERSION) \
/hyperkube apiserver --etcd-servers=http://$(LOCAL_IP_ENV):2379 \
--service-cluster-ip-range=10.101.0.0/16
## Stop Kubernetes apiserver
stop-k8s-apiserver:
@-docker rm -f calico-k8s-apiserver
bin/kubectl:
curl -sSf -L --retry 5 https://storage.googleapis.com/kubernetes-release/release/$(K8S_VERSION)/bin/linux/amd64/kubectl -o $@
chmod +x $@
bin/bird:
curl -sSf -L --retry 5 https://github.com/projectcalico/bird/releases/download/$(BIRD_VER)/bird -o $@
chmod +x $@
bin/bird6:
curl -sSf -L --retry 5 https://github.com/projectcalico/bird/releases/download/$(BIRD_VER)/bird6 -o $@
chmod +x $@
bin/etcdctl:
curl -sSf -L --retry 5 https://github.com/coreos/etcd/releases/download/$(ETCDCTL_VER)/etcd-$(ETCDCTL_VER)-linux-amd64.tar.gz | tar -xz -C bin --strip-components=1 etcd-$(ETCDCTL_VER)-linux-amd64/etcdctl
.PHONY: clean
clean:
rm -rf bin/*