forked from flannel-io/flannel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
147 lines (126 loc) · 5.38 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
145
146
147
.PHONY: test cover gofmt gofmt-fix license-check clean tar.gz docker-push release docker-push-all
# Registry used for publishing images
REGISTRY?=quay.io/coreos
# Default tag and architecture. Can be overridden
TAG?=$(shell git describe --tags --dirty)
ARCH?=amd64
# These variables can be overridden by setting an environment variable.
TEST_PACKAGES?=pkg/ip subnet remote
TEST_PACKAGES_EXPANDED=$(TEST_PACKAGES:%=github.com/coreos/flannel/%)
PACKAGES?=$(TEST_PACKAGES) network
PACKAGES_EXPANDED=$(PACKAGES:%=github.com/coreos/flannel/%)
# Set the (cross) compiler to use for different architectures
ifeq ($(ARCH),amd64)
CC=gcc
endif
ifeq ($(ARCH),arm)
CC=arm-linux-gnueabi-gcc
endif
ifeq ($(ARCH),arm64)
CC=aarch64-linux-gnu-gcc
endif
ifeq ($(ARCH),ppc64le)
CC=powerpc64le-linux-gnu-gcc
endif
GOARM=6
KUBE_CROSS_TAG=v1.6.2-2
IPTABLES_VERSION=1.4.21
dist/flanneld: $(shell find . -type f -name '*.go')
go build -o dist/flanneld \
-ldflags "-X github.com/coreos/flannel/version.Version=$(TAG)"
test: license-check gofmt
go test -cover $(TEST_PACKAGES_EXPANDED)
cd dist; ./mk-docker-opts_tests.sh
cover:
# A single package must be given - e.g. 'PACKAGES=pkg/ip make cover'
go test -coverprofile cover.out $(PACKAGES_EXPANDED)
go tool cover -html=cover.out
# Throw an error if gofmt finds problems.
# "read" will return a failure return code if there is no output. This is inverted wth the "!"
gofmt:
bash -c '! gofmt -d $(PACKAGES) 2>&1 | read'
gofmt-fix:
gofmt -w $(PACKAGES)
license-check:
./license-check.sh
clean:
rm -f dist/flanneld*
rm -f dist/iptables*
rm -f dist/*.aci
rm -f dist/*.docker
rm -f dist/*.tar.gz
## Create a docker image on disk for a specific arch and tag
dist/flanneld-$(ARCH)-$(TAG).docker: dist/flanneld-$(ARCH) dist/iptables-$(ARCH)
docker build -f Dockerfile.$(ARCH) -t $(REGISTRY)/flannel-$(ARCH):$(TAG) .
docker save -o dist/flanneld-$(ARCH)-$(TAG).docker $(REGISTRY)/flannel-$(ARCH):$(TAG)
# amd64 gets an image with the suffix too (i.e. it's the default)
ifeq ($(ARCH),amd64)
docker build -f Dockerfile.$(ARCH) -t $(REGISTRY)/flannel:$(TAG) .
endif
## Create an ACI on disk for a specific arch and tag
dist/flanneld-$(ARCH)-$(TAG).aci: dist/flanneld-$(ARCH)-$(TAG).docker
docker2aci dist/flanneld-$(ARCH)-$(TAG).docker
mv quay.io-coreos-flannel-$(ARCH)-$(TAG).aci dist/flanneld-$(ARCH)-$(TAG).aci
actool patch-manifest --replace --capability=CAP_NET_ADMIN \
--mounts=run-flannel,path=/run/flannel,readOnly=false:etc-ssl-etcd,path=/etc/ssl/etcd,readOnly=true:dev-net,path=/dev/net,readOnly=false \
dist/flanneld-$(ARCH)-$(TAG).aci
docker-push: dist/flanneld-$(ARCH)-$(TAG).docker
docker push $(REGISTRY)/flannel-$(ARCH):$(TAG)
# amd64 gets an image with the suffix too (i.e. it's the default)
ifeq ($(ARCH),amd64)
docker push $(REGISTRY)/flannel:$(TAG)
endif
## Build an architecture specific flanneld binary
dist/flanneld-$(ARCH):
# Build for other platforms with ARCH=$ARCH make build
# valid values for $ARCH are [amd64 arm arm64 ppc64le]
docker run -e CC=$(CC) -e GOARM=$(GOARM) -e GOARCH=$(ARCH) -it \
-u $(shell id -u):$(shell id -u) \
-v ${PWD}:/go/src/github.com/coreos/flannel:ro \
-v ${PWD}/dist:/go/src/github.com/coreos/flannel/dist \
gcr.io/google_containers/kube-cross:$(KUBE_CROSS_TAG) /bin/bash -c '\
cd /go/src/github.com/coreos/flannel && \
CGO_ENABLED=1 make -e dist/flanneld && \
mv dist/flanneld dist/flanneld-$(ARCH) && \
file dist/flanneld-$(ARCH)'
## Build an architecture specific iptables binary
dist/iptables-$(ARCH):
docker run -e CC=$(CC) -e GOARM=$(GOARM) -e GOARCH=$(ARCH) -it \
-u $(shell id -u):$(shell id -u) \
-v ${PWD}:/go/src/github.com/coreos/flannel:ro \
-v ${PWD}/dist:/go/src/github.com/coreos/flannel/dist \
gcr.io/google_containers/kube-cross:$(KUBE_CROSS_TAG) /bin/bash -c '\
curl -sSL http://www.netfilter.org/projects/iptables/files/iptables-$(IPTABLES_VERSION).tar.bz2 | tar -jxv && \
cd iptables-$(IPTABLES_VERSION) && \
./configure \
--prefix=/usr \
--mandir=/usr/man \
--disable-shared \
--disable-devel \
--disable-nftables \
--enable-static \
--host=amd64 && \
make && \
cp iptables/xtables-multi /go/src/github.com/coreos/flannel/dist/iptables-$(ARCH) && \
cd /go/src/github.com/coreos/flannel && \
file dist/iptables-$(ARCH)'
## Build a .tar.gz for the amd64 flanneld binary
tar.gz: dist/flannel-$(TAG)-linux-amd64.tar.gz
dist/flannel-$(TAG)-linux-amd64.tar.gz:
ARCH=amd64 make dist/flanneld-amd64
tar --transform='flags=r;s|-amd64||' -cvf dist/flannel-$(TAG)-linux-amd64.tar.gz -C dist flanneld-amd64 mk-docker-opts.sh ../README.md
tar -tvf dist/flannel-$(TAG)-linux-amd64.tar.gz
## Make a release after creating a tag
release: dist/flannel-$(TAG)-linux-amd64.tar.gz
ARCH=amd64 make dist/flanneld-amd64-$(TAG).aci
ARCH=arm make dist/flanneld-arm-$(TAG).aci
ARCH=arm64 make dist/flanneld-arm64-$(TAG).aci
ARCH=ppc64le make dist/flanneld-ppc64le-$(TAG).aci
@echo "Everything should be built for $(TAG)"
@echo "Add all *.aci, flanneld-* and *.tar.gz files from dist/ to the Github release"
@echo "Use make docker-push-all to push the images to a registry"
docker-push-all:
ARCH=amd64 make docker-push
ARCH=arm make docker-push
ARCH=arm64 make docker-push
ARCH=ppc64le make docker-push