Makefile 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. .PHONY: test e2e-test cover gofmt gofmt-fix license-check clean tar.gz docker-push release docker-push-all flannel-git
  2. # Registry used for publishing images
  3. REGISTRY?=quay.io/coreos/flannel
  4. # Default tag and architecture. Can be overridden
  5. TAG?=$(shell git describe --tags --dirty)
  6. ARCH?=amd64
  7. # These variables can be overridden by setting an environment variable.
  8. TEST_PACKAGES?=pkg/ip subnet subnet/etcdv2
  9. TEST_PACKAGES_EXPANDED=$(TEST_PACKAGES:%=github.com/coreos/flannel/%)
  10. PACKAGES?=$(TEST_PACKAGES) network
  11. PACKAGES_EXPANDED=$(PACKAGES:%=github.com/coreos/flannel/%)
  12. # Set the (cross) compiler to use for different architectures
  13. ifeq ($(ARCH),amd64)
  14. LIB_DIR=/lib/x86_64-linux-gnu
  15. CC=gcc
  16. endif
  17. ifeq ($(ARCH),arm)
  18. LIB_DIR=/usr/arm-linux-gnueabihf/lib
  19. CC=arm-linux-gnueabihf-gcc
  20. endif
  21. ifeq ($(ARCH),arm64)
  22. LIB_DIR=/usr/aarch64-linux-gnu/lib
  23. CC=aarch64-linux-gnu-gcc
  24. endif
  25. ifeq ($(ARCH),ppc64le)
  26. LIB_DIR=/usr/powerpc64le-linux-gnu/lib
  27. CC=powerpc64le-linux-gnu-gcc
  28. endif
  29. ifeq ($(ARCH),s390x)
  30. LIB_DIR=/usr/s390x-linux-gnu/lib
  31. CC=s390x-linux-gnu-gcc
  32. endif
  33. GOARM=7
  34. # List images with gcloud alpha container images list-tags gcr.io/google_containers/kube-cross
  35. KUBE_CROSS_TAG=v1.7.5-3
  36. IPTABLES_VERSION=1.4.21
  37. dist/flanneld: $(shell find . -type f -name '*.go')
  38. go build -o dist/flanneld \
  39. -ldflags "-X github.com/coreos/flannel/version.Version=$(TAG)"
  40. test: license-check gofmt
  41. go test -cover $(TEST_PACKAGES_EXPANDED)
  42. cd dist; ./mk-docker-opts_tests.sh
  43. e2e-test: dist/flanneld-$(TAG)-$(ARCH).docker
  44. cd dist; ./functional-test.sh $(REGISTRY):$(TAG)-$(ARCH)
  45. cover:
  46. # A single package must be given - e.g. 'PACKAGES=pkg/ip make cover'
  47. go test -coverprofile cover.out $(PACKAGES_EXPANDED)
  48. go tool cover -html=cover.out
  49. # Throw an error if gofmt finds problems.
  50. # "read" will return a failure return code if there is no output. This is inverted wth the "!"
  51. gofmt:
  52. bash -c '! gofmt -d $(PACKAGES) 2>&1 | read'
  53. gofmt-fix:
  54. gofmt -w $(PACKAGES)
  55. license-check:
  56. ./license-check.sh
  57. update-glide:
  58. # go get -d -u github.com/Masterminds/glide
  59. glide update --strip-vendor
  60. # go get -d -u github.com/sgotti/glide-vc
  61. glide vc --only-code --no-tests
  62. clean:
  63. rm -f dist/flanneld*
  64. rm -f dist/iptables*
  65. rm -f dist/libpthread*
  66. rm -f dist/*.aci
  67. rm -f dist/*.docker
  68. rm -f dist/*.tar.gz
  69. ## Create a docker image on disk for a specific arch and tag
  70. dist/flanneld-$(TAG)-$(ARCH).docker: dist/flanneld-$(ARCH) dist/iptables-$(ARCH) dist/libpthread.so.0-$(ARCH)
  71. docker build -f Dockerfile.$(ARCH) -t $(REGISTRY):$(TAG)-$(ARCH) .
  72. docker save -o dist/flanneld-$(TAG)-$(ARCH).docker $(REGISTRY):$(TAG)-$(ARCH)
  73. # amd64 gets an image with the suffix too (i.e. it's the default)
  74. ifeq ($(ARCH),amd64)
  75. docker build -f Dockerfile.$(ARCH) -t $(REGISTRY):$(TAG) .
  76. endif
  77. ## Create an ACI on disk for a specific arch and tag
  78. dist/flanneld-$(TAG)-$(ARCH).aci: dist/flanneld-$(TAG)-$(ARCH).docker
  79. docker2aci dist/flanneld-$(TAG)-$(ARCH).docker
  80. mv quay.io-coreos-flannel-$(TAG)-$(ARCH).aci dist/flanneld-$(TAG)-$(ARCH).aci
  81. actool patch-manifest --replace --capability=CAP_NET_ADMIN \
  82. --mounts=run-flannel,path=/run/flannel,readOnly=false:etc-ssl-etcd,path=/etc/ssl/etcd,readOnly=true:dev-net,path=/dev/net,readOnly=false \
  83. dist/flanneld-$(TAG)-$(ARCH).aci
  84. docker-push: dist/flanneld-$(TAG)-$(ARCH).docker
  85. docker push $(REGISTRY):$(TAG)-$(ARCH)
  86. # amd64 gets an image with the suffix too (i.e. it's the default)
  87. ifeq ($(ARCH),amd64)
  88. docker push $(REGISTRY):$(TAG)
  89. endif
  90. ## Build an architecture specific flanneld binary
  91. dist/flanneld-$(ARCH):
  92. # Build for other platforms with 'ARCH=$$ARCH make dist/flanneld-$$ARCH'
  93. # valid values for $$ARCH are [amd64 arm arm64 ppc64le s390x]
  94. docker run -e CC=$(CC) -e GOARM=$(GOARM) -e GOARCH=$(ARCH) \
  95. -u $(shell id -u):$(shell id -g) \
  96. -v $(CURDIR):/go/src/github.com/coreos/flannel:ro \
  97. -v $(CURDIR)/dist:/go/src/github.com/coreos/flannel/dist \
  98. gcr.io/google_containers/kube-cross:$(KUBE_CROSS_TAG) /bin/bash -c '\
  99. cd /go/src/github.com/coreos/flannel && \
  100. CGO_ENABLED=1 make -e dist/flanneld && \
  101. mv dist/flanneld dist/flanneld-$(ARCH) && \
  102. file dist/flanneld-$(ARCH)'
  103. ## Busybox images need updated libs. Pull them out of the kube-cross image
  104. dist/libpthread.so.0-$(ARCH) dist/libc.so.6-$(ARCH) dist/ld64.so.1-$(ARCH):
  105. docker run --rm -v $(CURDIR):/host gcr.io/google_containers/kube-cross:$(KUBE_CROSS_TAG) cp $(LIB_DIR)/libc-2.23.so /host/dist/libc.so.6-$(ARCH)
  106. docker run --rm -v $(CURDIR):/host gcr.io/google_containers/kube-cross:$(KUBE_CROSS_TAG) cp $(LIB_DIR)/ld-2.23.so /host/dist/ld64.so.1-$(ARCH)
  107. docker run --rm -v $(CURDIR):/host gcr.io/google_containers/kube-cross:$(KUBE_CROSS_TAG) cp $(LIB_DIR)/libpthread.so.0 /host/dist/libpthread.so.0-$(ARCH)
  108. ## Build an architecture specific iptables binary
  109. dist/iptables-$(ARCH):
  110. docker run -e CC=$(CC) -e GOARM=$(GOARM) -e GOARCH=$(ARCH) \
  111. -u $(shell id -u):$(shell id -g) \
  112. -v $(CURDIR):/go/src/github.com/coreos/flannel:ro \
  113. -v $(CURDIR)/dist:/go/src/github.com/coreos/flannel/dist \
  114. gcr.io/google_containers/kube-cross:$(KUBE_CROSS_TAG) /bin/bash -c '\
  115. curl -sSL http://www.netfilter.org/projects/iptables/files/iptables-$(IPTABLES_VERSION).tar.bz2 | tar -jxv && \
  116. cd iptables-$(IPTABLES_VERSION) && \
  117. ./configure \
  118. --prefix=/usr \
  119. --mandir=/usr/man \
  120. --disable-shared \
  121. --disable-devel \
  122. --disable-nftables \
  123. --enable-static \
  124. --host=amd64 && \
  125. make && \
  126. cp iptables/xtables-multi /go/src/github.com/coreos/flannel/dist/iptables-$(ARCH) && \
  127. cd /go/src/github.com/coreos/flannel && \
  128. file dist/iptables-$(ARCH)'
  129. ## Build a .tar.gz for the amd64 ppc64le arm arm64 flanneld binary
  130. tar.gz:
  131. ARCH=amd64 make dist/flanneld-amd64
  132. tar --transform='flags=r;s|-amd64||' -zcvf dist/flannel-$(TAG)-linux-amd64.tar.gz -C dist flanneld-amd64 mk-docker-opts.sh ../README.md
  133. tar -tvf dist/flannel-$(TAG)-linux-amd64.tar.gz
  134. ARCH=ppc64le make dist/flanneld-ppc64le
  135. tar --transform='flags=r;s|-ppc64le||' -zcvf dist/flannel-$(TAG)-linux-ppc64le.tar.gz -C dist flanneld-ppc64le mk-docker-opts.sh ../README.md
  136. tar -tvf dist/flannel-$(TAG)-linux-ppc64le.tar.gz
  137. ARCH=arm make dist/flanneld-arm
  138. tar --transform='flags=r;s|-arm||' -zcvf dist/flannel-$(TAG)-linux-arm.tar.gz -C dist flanneld-arm mk-docker-opts.sh ../README.md
  139. tar -tvf dist/flannel-$(TAG)-linux-arm.tar.gz
  140. ARCH=arm64 make dist/flanneld-arm64
  141. tar --transform='flags=r;s|-arm64||' -zcvf dist/flannel-$(TAG)-linux-arm64.tar.gz -C dist flanneld-arm64 mk-docker-opts.sh ../README.md
  142. tar -tvf dist/flannel-$(TAG)-linux-arm64.tar.gz
  143. ARCH=s390x make dist/flanneld-s390x
  144. tar --transform='flags=r;s|-s390x||' -zcvf dist/flannel-$(TAG)-linux-s390x.tar.gz -C dist flanneld-s390x mk-docker-opts.sh ../README.md
  145. tar -tvf dist/flannel-$(TAG)-linux-s390x.tar.gz
  146. ## Make a release after creating a tag
  147. release: tar.gz
  148. ARCH=amd64 make dist/flanneld-$(TAG)-amd64.aci
  149. ARCH=arm make dist/flanneld-$(TAG)-arm.aci
  150. ARCH=arm64 make dist/flanneld-$(TAG)-arm64.aci
  151. ARCH=ppc64le make dist/flanneld-$(TAG)-ppc64le.aci
  152. ARCH=s390x make dist/flanneld-$(TAG)-s390x.aci
  153. @echo "Everything should be built for $(TAG)"
  154. @echo "Add all *.aci, flanneld-* and *.tar.gz files from dist/ to the Github release"
  155. @echo "Use make docker-push-all to push the images to a registry"
  156. docker-push-all:
  157. ARCH=amd64 make docker-push
  158. ARCH=arm make docker-push
  159. ARCH=arm64 make docker-push
  160. ARCH=ppc64le make docker-push
  161. ARCH=s390x make docker-push
  162. flannel-git:
  163. ARCH=amd64 REGISTRY=quay.io/coreos/flannel-git make clean dist/flanneld-$(TAG)-amd64.docker docker-push
  164. docker build -f Dockerfile.amd64 -t quay.io/coreos/flannel-git .
  165. docker push quay.io/coreos/flannel-git
  166. ARCH=arm REGISTRY=quay.io/coreos/flannel-git make clean dist/flanneld-$(TAG)-arm.docker docker-push
  167. ARCH=arm64 REGISTRY=quay.io/coreos/flannel-git make clean dist/flanneld-$(TAG)-arm64.docker docker-push
  168. ARCH=ppc64le REGISTRY=quay.io/coreos/flannel-git make clean dist/flanneld-$(TAG)-ppc64le.docker docker-push
  169. ARCH=s390x REGISTRY=quay.io/coreos/flannel-git make clean dist/flanneld-$(TAG)-s390x.docker docker-push
  170. install:
  171. # This is intended as just a developer convenience to help speed up non-containerized builds
  172. # It is NOT how you install flannel
  173. CGO_ENABLED=1 go install -v github.com/coreos/flannel
  174. minikube-start:
  175. minikube start --network-plugin cni
  176. minikube-build-image: dist/iptables-amd64 dist/libpthread.so.0-amd64
  177. CGO_ENABLED=1 go build -v -o dist/flanneld-amd64
  178. # Make sure the minikube docker is being used "eval $(minikube docker-env)"
  179. sh -c 'eval $$(minikube docker-env) && docker build -f Dockerfile.amd64 -t flannel/minikube .'
  180. minikube-deploy-flannel:
  181. kubectl apply -f Documentation/minikube.yml
  182. minikube-remove-flannel:
  183. kubectl delete -f Documentation/minikube.yml
  184. minikube-restart-pod:
  185. # Use this to pick up a new image
  186. kubectl delete pods -l app=flannel --grace-period=0
  187. kubernetes-logs:
  188. kubectl logs `kubectl get po -l app=flannel -o=custom-columns=NAME:metadata.name --no-headers=true` -c kube-flannel -f
  189. LOCAL_IP_ENV?=$(shell ip route get 8.8.8.8 | head -1 | awk '{print $$7}')
  190. run-etcd: stop-etcd
  191. docker run --detach \
  192. -p 2379:2379 \
  193. --name flannel-etcd quay.io/coreos/etcd \
  194. etcd \
  195. --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" \
  196. --listen-client-urls "http://0.0.0.0:2379,http://0.0.0.0:4001"
  197. stop-etcd:
  198. @-docker rm -f flannel-etcd