cloudflare/cloudflared

Public

mirrored from https://github.com/cloudflare/cloudflaredAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
2021.10.5

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

Makefile

266lines · modecode

1VERSION := $(shell git describe --tags --always --dirty="-dev" --match "[0-9][0-9][0-9][0-9].*.*")
2MSI_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
6ifeq ($(FIPS), true)
7 GO_BUILD_TAGS := $(GO_BUILD_TAGS) fips
8endif
9
10ifneq ($(GO_BUILD_TAGS),)
11 GO_BUILD_TAGS := -tags $(GO_BUILD_TAGS)
12endif
13
14ifeq ($(NIGHTLY), true)
15 DEB_PACKAGE_NAME := cloudflared-nightly
16 NIGHTLY_FLAGS := --conflicts cloudflared --replaces cloudflared
17else
18 DEB_PACKAGE_NAME := cloudflared
19endif
20
21DATE := $(shell date -u '+%Y-%m-%d-%H%M UTC')
22VERSION_FLAGS := -ldflags='-X "main.Version=$(VERSION)" -X "main.BuildTime=$(DATE)"'
23
24IMPORT_PATH := github.com/cloudflare/cloudflared
25PACKAGE_DIR := $(CURDIR)/packaging
26INSTALL_BINDIR := /usr/bin/
27MAN_DIR := /usr/share/man/man1/
28
29LOCAL_ARCH ?= $(shell uname -m)
30ifneq ($(GOARCH),)
31 TARGET_ARCH ?= $(GOARCH)
32else ifeq ($(LOCAL_ARCH),x86_64)
33 TARGET_ARCH ?= amd64
34else ifeq ($(LOCAL_ARCH),amd64)
35 TARGET_ARCH ?= amd64
36else ifeq ($(LOCAL_ARCH),i686)
37 TARGET_ARCH ?= amd64
38else ifeq ($(shell echo $(LOCAL_ARCH) | head -c 5),armv8)
39 TARGET_ARCH ?= arm64
40else ifeq ($(LOCAL_ARCH),aarch64)
41 TARGET_ARCH ?= arm64
42else ifeq ($(LOCAL_ARCH),arm64)
43 TARGET_ARCH ?= arm64
44else ifeq ($(shell echo $(LOCAL_ARCH) | head -c 4),armv)
45 TARGET_ARCH ?= arm
46else
47 $(error This system's architecture $(LOCAL_ARCH) isn't supported)
48endif
49
50LOCAL_OS ?= $(shell go env GOOS)
51ifeq ($(LOCAL_OS),linux)
52 TARGET_OS ?= linux
53else ifeq ($(LOCAL_OS),darwin)
54 TARGET_OS ?= darwin
55else ifeq ($(LOCAL_OS),windows)
56 TARGET_OS ?= windows
57else ifeq ($(LOCAL_OS),freebsd)
58 TARGET_OS ?= freebsd
59else
60 $(error This system's OS $(LOCAL_OS) isn't supported)
61endif
62
63ifeq ($(TARGET_OS), windows)
64 EXECUTABLE_PATH=./cloudflared.exe
65else
66 EXECUTABLE_PATH=./cloudflared
67endif
68
69ifeq ($(FLAVOR), centos-7)
70 TARGET_PUBLIC_REPO ?= el7
71else
72 TARGET_PUBLIC_REPO ?= $(FLAVOR)
73endif
74
75.PHONY: all
76all: cloudflared test
77
78.PHONY: clean
79clean:
80 go clean
81
82.PHONY: cloudflared
83cloudflared:
84ifeq ($(FIPS), true)
85 $(info Building cloudflared with go-fips)
86 -test -f fips/fips.go && mv fips/fips.go fips/fips.go.linux-amd64
87 mv fips/fips.go.linux-amd64 fips/fips.go
88endif
89
90 GOOS=$(TARGET_OS) GOARCH=$(TARGET_ARCH) go build -v -mod=vendor $(GO_BUILD_TAGS) $(VERSION_FLAGS) $(IMPORT_PATH)/cmd/cloudflared
91
92ifeq ($(FIPS), true)
93 mv fips/fips.go fips/fips.go.linux-amd64
94endif
95
96.PHONY: container
97container:
98 docker build --build-arg=TARGET_ARCH=$(TARGET_ARCH) --build-arg=TARGET_OS=$(TARGET_OS) -t cloudflare/cloudflared-$(TARGET_OS)-$(TARGET_ARCH):"$(VERSION)" .
99
100.PHONY: test
101test: vet
102ifndef CI
103 go test -v -mod=vendor -race $(VERSION_FLAGS) ./...
104else
105 @mkdir -p .cover
106 go test -v -mod=vendor -race $(VERSION_FLAGS) -coverprofile=".cover/c.out" ./...
107 go tool cover -html ".cover/c.out" -o .cover/all.html
108endif
109
110.PHONY: test-ssh-server
111test-ssh-server:
112 docker-compose -f ssh_server_tests/docker-compose.yml up
113
114define publish_package
115 chmod 664 cloudflared*.$(1); \
116 for HOST in $(CF_PKG_HOSTS); do \
117 ssh-keyscan -t rsa $$HOST >> ~/.ssh/known_hosts; \
118 scp -p -4 cloudflared*.$(1) cfsync@$$HOST:/state/cf-pkg/staging/$(2)/$(TARGET_PUBLIC_REPO)/cloudflared/; \
119 done
120endef
121
122.PHONY: publish-deb
123publish-deb: cloudflared-deb
124 $(call publish_package,deb,apt)
125
126.PHONY: publish-rpm
127publish-rpm: cloudflared-rpm
128 $(call publish_package,rpm,yum)
129
130define build_package
131 mkdir -p $(PACKAGE_DIR)
132 cp cloudflared $(PACKAGE_DIR)/cloudflared
133 cat cloudflared_man_template | sed -e 's/\$${VERSION}/$(VERSION)/; s/\$${DATE}/$(DATE)/' > $(PACKAGE_DIR)/cloudflared.1
134 fakeroot fpm -C $(PACKAGE_DIR) -s dir -t $(1) \
135 --description 'Cloudflare Tunnel daemon' \
136 --vendor 'Cloudflare' \
137 --license 'Cloudflare Service Agreement' \
138 --url 'https://github.com/cloudflare/cloudflared' \
139 -m 'Cloudflare <support@cloudflare.com>' \
140 -a $(TARGET_ARCH) -v $(VERSION) -n $(DEB_PACKAGE_NAME) $(NIGHTLY_FLAGS) --after-install postinst.sh --after-remove postrm.sh \
141 cloudflared=$(INSTALL_BINDIR) cloudflared.1=$(MAN_DIR)
142endef
143
144.PHONY: cloudflared-deb
145cloudflared-deb: cloudflared
146 $(call build_package,deb)
147
148.PHONY: cloudflared-rpm
149cloudflared-rpm: cloudflared
150 $(call build_package,rpm)
151
152.PHONY: cloudflared-pkg
153cloudflared-pkg: cloudflared
154 $(call build_package,osxpkg)
155
156.PHONY: cloudflared-msi
157cloudflared-msi: cloudflared
158 wixl --define Version=$(VERSION) --define Path=$(EXECUTABLE_PATH) --output cloudflared-$(VERSION)-$(TARGET_ARCH).msi cloudflared.wxs
159
160.PHONY: cloudflared-darwin-amd64.tgz
161cloudflared-darwin-amd64.tgz: cloudflared
162 tar czf cloudflared-darwin-amd64.tgz cloudflared
163 rm cloudflared
164
165.PHONY: cloudflared-junos
166cloudflared-junos: cloudflared jetez-certificate.pem jetez-key.pem
167 jetez --source . \
168 -j jet.yaml \
169 --key jetez-key.pem \
170 --cert jetez-certificate.pem \
171 --version $(VERSION)
172 rm jetez-*.pem
173
174jetez-certificate.pem:
175ifndef JETEZ_CERT
176 $(error JETEZ_CERT not defined)
177endif
178 @echo "Writing JetEZ certificate"
179 @echo "$$JETEZ_CERT" > jetez-certificate.pem
180
181jetez-key.pem:
182ifndef JETEZ_KEY
183 $(error JETEZ_KEY not defined)
184endif
185 @echo "Writing JetEZ key"
186 @echo "$$JETEZ_KEY" > jetez-key.pem
187
188.PHONY: publish-cloudflared-junos
189publish-cloudflared-junos: cloudflared-junos cloudflared-x86-64.latest.s3
190ifndef S3_ENDPOINT
191 $(error S3_HOST not defined)
192endif
193ifndef S3_URI
194 $(error S3_URI not defined)
195endif
196ifndef S3_ACCESS_KEY
197 $(error S3_ACCESS_KEY not defined)
198endif
199ifndef S3_SECRET_KEY
200 $(error S3_SECRET_KEY not defined)
201endif
202 sha256sum cloudflared-x86-64-$(VERSION).tgz | awk '{printf $$1}' > cloudflared-x86-64-$(VERSION).tgz.shasum
203 s4cmd --endpoint-url $(S3_ENDPOINT) --force --API-GrantRead=uri=http://acs.amazonaws.com/groups/global/AllUsers \
204 put cloudflared-x86-64-$(VERSION).tgz $(S3_URI)/cloudflared-x86-64-$(VERSION).tgz
205 s4cmd --endpoint-url $(S3_ENDPOINT) --force --API-GrantRead=uri=http://acs.amazonaws.com/groups/global/AllUsers \
206 put cloudflared-x86-64-$(VERSION).tgz.shasum $(S3_URI)/cloudflared-x86-64-$(VERSION).tgz.shasum
207 dpkg --compare-versions "$(VERSION)" gt "$(shell cat cloudflared-x86-64.latest.s3)" && \
208 echo -n "$(VERSION)" > cloudflared-x86-64.latest && \
209 s4cmd --endpoint-url $(S3_ENDPOINT) --force --API-GrantRead=uri=http://acs.amazonaws.com/groups/global/AllUsers \
210 put cloudflared-x86-64.latest $(S3_URI)/cloudflared-x86-64.latest || \
211 echo "Latest version not updated"
212
213cloudflared-x86-64.latest.s3:
214 s4cmd --endpoint-url $(S3_ENDPOINT) --force \
215 get $(S3_URI)/cloudflared-x86-64.latest cloudflared-x86-64.latest.s3
216
217.PHONY: homebrew-upload
218homebrew-upload: cloudflared-darwin-amd64.tgz
219 aws s3 --endpoint-url $(S3_ENDPOINT) cp --acl public-read $$^ $(S3_URI)/cloudflared-$$(VERSION)-$1.tgz
220 aws s3 --endpoint-url $(S3_ENDPOINT) cp --acl public-read $(S3_URI)/cloudflared-$$(VERSION)-$1.tgz $(S3_URI)/cloudflared-stable-$1.tgz
221
222.PHONY: homebrew-release
223homebrew-release: homebrew-upload
224 ./publish-homebrew-formula.sh cloudflared-darwin-amd64.tgz $(VERSION) homebrew-cloudflare
225
226.PHONY: github-release
227github-release: cloudflared
228 python3 github_release.py --path $(EXECUTABLE_PATH) --release-version $(VERSION)
229
230.PHONY: github-release-built-pkgs
231github-release-built-pkgs:
232 python3 github_release.py --path $(PWD)/built_artifacts --release-version $(VERSION)
233
234.PHONY: github-message
235github-message:
236 python3 github_message.py --release-version $(VERSION)
237
238.PHONY: github-mac-upload
239github-mac-upload:
240 python3 github_release.py --path artifacts/cloudflared-darwin-amd64.tgz --release-version $(VERSION) --name cloudflared-darwin-amd64.tgz
241 python3 github_release.py --path artifacts/cloudflared-amd64.pkg --release-version $(VERSION) --name cloudflared-amd64.pkg
242
243.PHONY: tunnelrpc-deps
244tunnelrpc-deps:
245 which capnp # https://capnproto.org/install.html
246 which capnpc-go # go get zombiezen.com/go/capnproto2/capnpc-go
247 capnp compile -ogo tunnelrpc/tunnelrpc.capnp
248
249.PHONY: quic-deps
250quic-deps:
251 which capnp
252 which capnpc-go
253 capnp compile -ogo quic/schema/quic_metadata_protocol.capnp
254
255.PHONY: vet
256vet:
257 go vet -mod=vendor ./...
258 # go get github.com/sudarshan-reddy/go-sumtype (don't do this in build directory or this will cause vendor issues)
259 # Note: If you have github.com/BurntSushi/go-sumtype then you might have to use the repo above instead
260 # for now because it uses an older version of golang.org/x/tools.
261 which go-sumtype
262 go-sumtype $$(go list -mod=vendor ./...)
263
264.PHONY: goimports
265goimports:
266 for d in $$(go list -mod=readonly -f '{{.Dir}}' -a ./... | fgrep -v tunnelrpc) ; do goimports -format-only -local github.com/cloudflare/cloudflared -w $$d ; done