Makefile 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. VERSION := $(shell git describe --tags --always --dirty="-dev" --match "[0-9][0-9][0-9][0-9].*.*")
  2. MSI_VERSION := $(shell git tag -l --sort=v:refname | grep "w" | tail -1 | cut -c2-)
  3. #MSI_VERSION expects the format of the tag to be: (wX.X.X). Starts with the w character to not break cfsetup.
  4. #e.g. w3.0.1 or w4.2.10. It trims off the w character when creating the MSI.
  5. ifeq ($(FIPS), true)
  6. GO_BUILD_TAGS := $(GO_BUILD_TAGS) fips
  7. endif
  8. ifneq ($(GO_BUILD_TAGS),)
  9. GO_BUILD_TAGS := -tags $(GO_BUILD_TAGS)
  10. endif
  11. DATE := $(shell date -u '+%Y-%m-%d-%H%M UTC')
  12. VERSION_FLAGS := -ldflags='-X "main.Version=$(VERSION)" -X "main.BuildTime=$(DATE)"'
  13. IMPORT_PATH := github.com/cloudflare/cloudflared
  14. PACKAGE_DIR := $(CURDIR)/packaging
  15. INSTALL_BINDIR := /usr/bin/
  16. MAN_DIR := /usr/share/man/man1/
  17. EQUINOX_FLAGS = --version="$(VERSION)" \
  18. --platforms="$(EQUINOX_BUILD_PLATFORMS)" \
  19. --app="$(EQUINOX_APP_ID)" \
  20. --token="$(EQUINOX_TOKEN)" \
  21. --channel="$(EQUINOX_CHANNEL)"
  22. ifeq ($(EQUINOX_IS_DRAFT), true)
  23. EQUINOX_FLAGS := --draft $(EQUINOX_FLAGS)
  24. endif
  25. LOCAL_ARCH ?= $(shell uname -m)
  26. ifneq ($(GOARCH),)
  27. TARGET_ARCH ?= $(GOARCH)
  28. else ifeq ($(LOCAL_ARCH),x86_64)
  29. TARGET_ARCH ?= amd64
  30. else ifeq ($(LOCAL_ARCH),amd64)
  31. TARGET_ARCH ?= amd64
  32. else ifeq ($(LOCAL_ARCH),i686)
  33. TARGET_ARCH ?= amd64
  34. else ifeq ($(shell echo $(LOCAL_ARCH) | head -c 5),armv8)
  35. TARGET_ARCH ?= arm64
  36. else ifeq ($(LOCAL_ARCH),aarch64)
  37. TARGET_ARCH ?= arm64
  38. else ifeq ($(shell echo $(LOCAL_ARCH) | head -c 4),armv)
  39. TARGET_ARCH ?= arm
  40. else
  41. $(error This system's architecture $(LOCAL_ARCH) isn't supported)
  42. endif
  43. LOCAL_OS ?= $(shell go env GOOS)
  44. ifeq ($(LOCAL_OS),linux)
  45. TARGET_OS ?= linux
  46. else ifeq ($(LOCAL_OS),darwin)
  47. TARGET_OS ?= darwin
  48. else ifeq ($(LOCAL_OS),windows)
  49. TARGET_OS ?= windows
  50. else ifeq ($(LOCAL_OS),freebsd)
  51. TARGET_OS ?= freebsd
  52. else
  53. $(error This system's OS $(LOCAL_OS) isn't supported)
  54. endif
  55. ifeq ($(TARGET_OS), windows)
  56. EXECUTABLE_PATH=./cloudflared.exe
  57. else
  58. EXECUTABLE_PATH=./cloudflared
  59. endif
  60. ifeq ($(FLAVOR), centos-7)
  61. TARGET_PUBLIC_REPO ?= el7
  62. else
  63. TARGET_PUBLIC_REPO ?= $(FLAVOR)
  64. endif
  65. .PHONY: all
  66. all: cloudflared test
  67. .PHONY: clean
  68. clean:
  69. go clean
  70. .PHONY: cloudflared
  71. cloudflared: tunnel-deps
  72. ifeq ($(FIPS), true)
  73. $(info Building cloudflared with go-fips)
  74. -test -f fips/fips.go && mv fips/fips.go fips/fips.go.linux-amd64
  75. mv fips/fips.go.linux-amd64 fips/fips.go
  76. endif
  77. GOOS=$(TARGET_OS) GOARCH=$(TARGET_ARCH) go build -v -mod=vendor $(GO_BUILD_TAGS) $(VERSION_FLAGS) $(IMPORT_PATH)/cmd/cloudflared
  78. ifeq ($(FIPS), true)
  79. mv fips/fips.go fips/fips.go.linux-amd64
  80. endif
  81. .PHONY: container
  82. container:
  83. docker build --build-arg=TARGET_ARCH=$(TARGET_ARCH) --build-arg=TARGET_OS=$(TARGET_OS) -t cloudflare/cloudflared-$(TARGET_OS)-$(TARGET_ARCH):"$(VERSION)" .
  84. .PHONY: test
  85. test: vet
  86. ifndef CI
  87. go test -v -mod=vendor -race $(VERSION_FLAGS) ./...
  88. else
  89. @mkdir -p .cover
  90. go test -v -mod=vendor -race $(VERSION_FLAGS) -coverprofile=".cover/c.out" ./...
  91. go tool cover -html ".cover/c.out" -o .cover/all.html
  92. endif
  93. .PHONY: test-ssh-server
  94. test-ssh-server:
  95. docker-compose -f ssh_server_tests/docker-compose.yml up
  96. define publish_package
  97. chmod 664 cloudflared*.$(1); \
  98. for HOST in $(CF_PKG_HOSTS); do \
  99. ssh-keyscan -t rsa $$HOST >> ~/.ssh/known_hosts; \
  100. scp -p -4 cloudflared*.$(1) cfsync@$$HOST:/state/cf-pkg/staging/$(2)/$(TARGET_PUBLIC_REPO)/cloudflared/; \
  101. done
  102. endef
  103. .PHONY: publish-deb
  104. publish-deb: cloudflared-deb
  105. $(call publish_package,deb,apt)
  106. .PHONY: publish-rpm
  107. publish-rpm: cloudflared-rpm
  108. $(call publish_package,rpm,yum)
  109. define build_package
  110. mkdir -p $(PACKAGE_DIR)
  111. cp cloudflared $(PACKAGE_DIR)/cloudflared
  112. cat cloudflared_man_template | sed -e 's/\$${VERSION}/$(VERSION)/; s/\$${DATE}/$(DATE)/' > $(PACKAGE_DIR)/cloudflared.1
  113. fakeroot fpm -C $(PACKAGE_DIR) -s dir -t $(1) \
  114. --description 'Cloudflare Argo tunnel daemon' \
  115. --vendor 'Cloudflare' \
  116. --license 'Cloudflare Service Agreement' \
  117. --url 'https://github.com/cloudflare/cloudflared' \
  118. -m 'Cloudflare <support@cloudflare.com>' \
  119. -a $(TARGET_ARCH) -v $(VERSION) -n cloudflared --after-install postinst.sh --after-remove postrm.sh \
  120. cloudflared=$(INSTALL_BINDIR) cloudflared.1=$(MAN_DIR)
  121. endef
  122. .PHONY: cloudflared-deb
  123. cloudflared-deb: cloudflared
  124. $(call build_package,deb)
  125. .PHONY: cloudflared-rpm
  126. cloudflared-rpm: cloudflared
  127. $(call build_package,rpm)
  128. .PHONY: cloudflared-darwin-amd64.tgz
  129. cloudflared-darwin-amd64.tgz: cloudflared
  130. tar czf cloudflared-darwin-amd64.tgz cloudflared
  131. rm cloudflared
  132. .PHONY: cloudflared-junos
  133. cloudflared-junos: cloudflared jetez-certificate.pem jetez-key.pem
  134. jetez --source . \
  135. -j jet.yaml \
  136. --key jetez-key.pem \
  137. --cert jetez-certificate.pem \
  138. --version $(VERSION)
  139. rm jetez-*.pem
  140. jetez-certificate.pem:
  141. ifndef JETEZ_CERT
  142. $(error JETEZ_CERT not defined)
  143. endif
  144. @echo "Writing JetEZ certificate"
  145. @echo "$$JETEZ_CERT" > jetez-certificate.pem
  146. jetez-key.pem:
  147. ifndef JETEZ_KEY
  148. $(error JETEZ_KEY not defined)
  149. endif
  150. @echo "Writing JetEZ key"
  151. @echo "$$JETEZ_KEY" > jetez-key.pem
  152. .PHONY: publish-cloudflared-junos
  153. publish-cloudflared-junos: cloudflared-junos cloudflared-x86-64.latest.s3
  154. ifndef S3_ENDPOINT
  155. $(error S3_HOST not defined)
  156. endif
  157. ifndef S3_URI
  158. $(error S3_URI not defined)
  159. endif
  160. ifndef S3_ACCESS_KEY
  161. $(error S3_ACCESS_KEY not defined)
  162. endif
  163. ifndef S3_SECRET_KEY
  164. $(error S3_SECRET_KEY not defined)
  165. endif
  166. sha256sum cloudflared-x86-64-$(VERSION).tgz | awk '{printf $$1}' > cloudflared-x86-64-$(VERSION).tgz.shasum
  167. s4cmd --endpoint-url $(S3_ENDPOINT) --force --API-GrantRead=uri=http://acs.amazonaws.com/groups/global/AllUsers \
  168. put cloudflared-x86-64-$(VERSION).tgz $(S3_URI)/cloudflared-x86-64-$(VERSION).tgz
  169. s4cmd --endpoint-url $(S3_ENDPOINT) --force --API-GrantRead=uri=http://acs.amazonaws.com/groups/global/AllUsers \
  170. put cloudflared-x86-64-$(VERSION).tgz.shasum $(S3_URI)/cloudflared-x86-64-$(VERSION).tgz.shasum
  171. dpkg --compare-versions "$(VERSION)" gt "$(shell cat cloudflared-x86-64.latest.s3)" && \
  172. echo -n "$(VERSION)" > cloudflared-x86-64.latest && \
  173. s4cmd --endpoint-url $(S3_ENDPOINT) --force --API-GrantRead=uri=http://acs.amazonaws.com/groups/global/AllUsers \
  174. put cloudflared-x86-64.latest $(S3_URI)/cloudflared-x86-64.latest || \
  175. echo "Latest version not updated"
  176. cloudflared-x86-64.latest.s3:
  177. s4cmd --endpoint-url $(S3_ENDPOINT) --force \
  178. get $(S3_URI)/cloudflared-x86-64.latest cloudflared-x86-64.latest.s3
  179. .PHONY: homebrew-upload
  180. homebrew-upload: cloudflared-darwin-amd64.tgz
  181. aws s3 --endpoint-url $(S3_ENDPOINT) cp --acl public-read $$^ $(S3_URI)/cloudflared-$$(VERSION)-$1.tgz
  182. aws s3 --endpoint-url $(S3_ENDPOINT) cp --acl public-read $(S3_URI)/cloudflared-$$(VERSION)-$1.tgz $(S3_URI)/cloudflared-stable-$1.tgz
  183. .PHONY: homebrew-release
  184. homebrew-release: homebrew-upload
  185. ./publish-homebrew-formula.sh cloudflared-darwin-amd64.tgz $(VERSION) homebrew-cloudflare
  186. .PHONY: release
  187. release: bin/equinox
  188. bin/equinox release $(EQUINOX_FLAGS) -- $(VERSION_FLAGS) $(IMPORT_PATH)/cmd/cloudflared
  189. .PHONY: github-release
  190. github-release: cloudflared
  191. python3 github_release.py --path $(EXECUTABLE_PATH) --release-version $(VERSION)
  192. .PHONY: github-message
  193. github-message:
  194. python3 github_message.py --release-version $(VERSION)
  195. .PHONY: github-mac-upload
  196. github-mac-upload:
  197. python3 github_release.py --path artifacts/cloudflared-darwin-amd64.tgz --release-version $(VERSION) --name cloudflared-darwin-amd64.tgz
  198. python3 github_release.py --path artifacts/cloudflared-amd64.pkg --release-version $(VERSION) --name cloudflared-amd64.pkg
  199. bin/equinox:
  200. mkdir -p bin
  201. curl -s https://bin.equinox.io/c/75JtLRTsJ3n/release-tool-beta-$(EQUINOX_PLATFORM).tgz | tar xz -C bin/
  202. .PHONY: tunnel-deps
  203. tunnel-deps: tunnelrpc/tunnelrpc.capnp.go
  204. tunnelrpc/tunnelrpc.capnp.go: tunnelrpc/tunnelrpc.capnp
  205. which capnp # https://capnproto.org/install.html
  206. which capnpc-go # go get zombiezen.com/go/capnproto2/capnpc-go
  207. capnp compile -ogo tunnelrpc/tunnelrpc.capnp
  208. .PHONY: vet
  209. vet:
  210. go vet -mod=vendor ./...
  211. which go-sumtype # go get github.com/BurntSushi/go-sumtype (don't do this in build directory or this will cause vendor issues)
  212. go-sumtype $$(go list -mod=vendor ./...)
  213. .PHONY: msi
  214. msi: cloudflared
  215. go-msi make --msi cloudflared.msi --version $(MSI_VERSION)