cloudflare/cloudflared

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
2021.5.8

Branches

Tags

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

Clone

HTTPS

Download ZIP

Makefile

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