Makefile 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. .PHONY: test e2e-test cover gofmt gofmt-fix license-check clean tar.gz docker-push release docker-push-all
  2. # Registry used for publishing images
  3. REGISTRY?=quay.io/coreos
  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 remote
  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=x86_64-linux-gnu
  15. CC=gcc
  16. endif
  17. ifeq ($(ARCH),arm)
  18. LIB_DIR=arm-linux-gnueabi
  19. CC=arm-linux-gnueabi-gcc
  20. endif
  21. ifeq ($(ARCH),arm64)
  22. LIB_DIR=aarch64-linux-gnu
  23. CC=aarch64-linux-gnu-gcc
  24. endif
  25. ifeq ($(ARCH),ppc64le)
  26. LIB_DIR=powerpc64le-linux-gnu
  27. CC=powerpc64le-linux-gnu-gcc
  28. endif
  29. GOARM=6
  30. KUBE_CROSS_TAG=v1.6.2-2
  31. IPTABLES_VERSION=1.4.21
  32. dist/flanneld: $(shell find . -type f -name '*.go')
  33. go build -o dist/flanneld \
  34. -ldflags "-X github.com/coreos/flannel/version.Version=$(TAG)"
  35. test: license-check gofmt
  36. go test -cover $(TEST_PACKAGES_EXPANDED)
  37. cd dist; ./mk-docker-opts_tests.sh
  38. e2e-test: dist/flanneld-$(TAG)-$(ARCH).docker
  39. cd dist; ./functional-test.sh $(REGISTRY)/flannel:$(TAG)-$(ARCH)
  40. cover:
  41. # A single package must be given - e.g. 'PACKAGES=pkg/ip make cover'
  42. go test -coverprofile cover.out $(PACKAGES_EXPANDED)
  43. go tool cover -html=cover.out
  44. # Throw an error if gofmt finds problems.
  45. # "read" will return a failure return code if there is no output. This is inverted wth the "!"
  46. gofmt:
  47. bash -c '! gofmt -d $(PACKAGES) 2>&1 | read'
  48. gofmt-fix:
  49. gofmt -w $(PACKAGES)
  50. license-check:
  51. ./license-check.sh
  52. clean:
  53. rm -f dist/flanneld*
  54. rm -f dist/iptables*
  55. rm -f dist/*.aci
  56. rm -f dist/*.docker
  57. rm -f dist/*.tar.gz
  58. ## Create a docker image on disk for a specific arch and tag
  59. dist/flanneld-$(TAG)-$(ARCH).docker: dist/flanneld-$(ARCH) dist/iptables-$(ARCH) dist/libpthread.so.0-$(ARCH)
  60. docker build -f Dockerfile.$(ARCH) -t $(REGISTRY)/flannel:$(TAG)-$(ARCH) .
  61. docker save -o dist/flanneld-$(TAG)-$(ARCH).docker $(REGISTRY)/flannel:$(TAG)-$(ARCH)
  62. # amd64 gets an image with the suffix too (i.e. it's the default)
  63. ifeq ($(ARCH),amd64)
  64. docker build -f Dockerfile.$(ARCH) -t $(REGISTRY)/flannel:$(TAG) .
  65. endif
  66. ## Create an ACI on disk for a specific arch and tag
  67. dist/flanneld-$(TAG)-$(ARCH).aci: dist/flanneld-$(TAG)-$(ARCH).docker
  68. docker2aci dist/flanneld-$(TAG)-$(ARCH).docker
  69. mv quay.io-coreos-flannel-$(TAG)-$(ARCH).aci dist/flanneld-$(TAG)-$(ARCH).aci
  70. actool patch-manifest --replace --capability=CAP_NET_ADMIN \
  71. --mounts=run-flannel,path=/run/flannel,readOnly=false:etc-ssl-etcd,path=/etc/ssl/etcd,readOnly=true:dev-net,path=/dev/net,readOnly=false \
  72. dist/flanneld-$(TAG)-$(ARCH).aci
  73. docker-push: dist/flanneld-$(TAG)-$(ARCH).docker
  74. docker push $(REGISTRY)/flannel:$(TAG)-$(ARCH)
  75. # amd64 gets an image with the suffix too (i.e. it's the default)
  76. ifeq ($(ARCH),amd64)
  77. docker push $(REGISTRY)/flannel:$(TAG)
  78. endif
  79. ## Build an architecture specific flanneld binary
  80. dist/flanneld-$(ARCH):
  81. # Build for other platforms with ARCH=$$ARCH make build
  82. # valid values for $$ARCH are [amd64 arm arm64 ppc64le]
  83. docker run -e CC=$(CC) -e GOARM=$(GOARM) -e GOARCH=$(ARCH) -it \
  84. -u $(shell id -u):$(shell id -u) \
  85. -v ${PWD}:/go/src/github.com/coreos/flannel:ro \
  86. -v ${PWD}/dist:/go/src/github.com/coreos/flannel/dist \
  87. gcr.io/google_containers/kube-cross:$(KUBE_CROSS_TAG) /bin/bash -c '\
  88. cd /go/src/github.com/coreos/flannel && \
  89. CGO_ENABLED=1 make -e dist/flanneld && \
  90. mv dist/flanneld dist/flanneld-$(ARCH) && \
  91. file dist/flanneld-$(ARCH)'
  92. ## Busybox images are missing pthread. Pull it out of the kube-cross image
  93. dist/libpthread.so.0-$(ARCH):
  94. docker run -ti --rm -v `pwd`:/host gcr.io/google_containers/kube-cross:$(KUBE_CROSS_TAG) cp /lib/$(LIB_DIR)/libpthread.so.0 /host/dist/libpthread.so.0-$(ARCH)
  95. ## Build an architecture specific iptables binary
  96. dist/iptables-$(ARCH):
  97. docker run -e CC=$(CC) -e GOARM=$(GOARM) -e GOARCH=$(ARCH) -it \
  98. -u $(shell id -u):$(shell id -u) \
  99. -v ${PWD}:/go/src/github.com/coreos/flannel:ro \
  100. -v ${PWD}/dist:/go/src/github.com/coreos/flannel/dist \
  101. gcr.io/google_containers/kube-cross:$(KUBE_CROSS_TAG) /bin/bash -c '\
  102. curl -sSL http://www.netfilter.org/projects/iptables/files/iptables-$(IPTABLES_VERSION).tar.bz2 | tar -jxv && \
  103. cd iptables-$(IPTABLES_VERSION) && \
  104. ./configure \
  105. --prefix=/usr \
  106. --mandir=/usr/man \
  107. --disable-shared \
  108. --disable-devel \
  109. --disable-nftables \
  110. --enable-static \
  111. --host=amd64 && \
  112. make && \
  113. cp iptables/xtables-multi /go/src/github.com/coreos/flannel/dist/iptables-$(ARCH) && \
  114. cd /go/src/github.com/coreos/flannel && \
  115. file dist/iptables-$(ARCH)'
  116. ## Build a .tar.gz for the amd64 flanneld binary
  117. tar.gz: dist/flannel-$(TAG)-linux-amd64.tar.gz
  118. dist/flannel-$(TAG)-linux-amd64.tar.gz:
  119. ARCH=amd64 make dist/flanneld-amd64
  120. tar --transform='flags=r;s|-amd64||' -zcvf dist/flannel-$(TAG)-linux-amd64.tar.gz -C dist flanneld-amd64 mk-docker-opts.sh ../README.md
  121. tar -tvf dist/flannel-$(TAG)-linux-amd64.tar.gz
  122. ## Make a release after creating a tag
  123. release: dist/flannel-$(TAG)-linux-amd64.tar.gz
  124. ARCH=amd64 make dist/flanneld-$(TAG)-amd64.aci
  125. ARCH=arm make dist/flanneld-$(TAG)-arm.aci
  126. ARCH=arm64 make dist/flanneld-$(TAG)-arm64.aci
  127. ARCH=ppc64le make dist/flanneld-$(TAG)-ppc64le.aci
  128. @echo "Everything should be built for $(TAG)"
  129. @echo "Add all *.aci, flanneld-* and *.tar.gz files from dist/ to the Github release"
  130. @echo "Use make docker-push-all to push the images to a registry"
  131. docker-push-all:
  132. ARCH=amd64 make docker-push
  133. ARCH=arm make docker-push
  134. ARCH=arm64 make docker-push
  135. ARCH=ppc64le make docker-push