Makefile 5.4 KB

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