cloudflare/cloudflared

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
2022.6.3

Branches

Tags

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

Clone

HTTPS

Download ZIP

Makefile

309lines · modecode

1VERSION := $(shell git describe --tags --always --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 ($(ORIGINAL_NAME), true)
7 # Used for builds that want FIPS compilation but want the artifacts generated to still have the original name.
8 BINARY_NAME := cloudflared
9else ifeq ($(FIPS), true)
10 # Used for FIPS compliant builds that do not match the case above.
11 BINARY_NAME := cloudflared-fips
12else
13 # Used for all other (non-FIPS) builds.
14 BINARY_NAME := cloudflared
15endif
16
17ifeq ($(NIGHTLY), true)
18 DEB_PACKAGE_NAME := $(BINARY_NAME)-nightly
19 NIGHTLY_FLAGS := --conflicts cloudflared --replaces cloudflared
20else
21 DEB_PACKAGE_NAME := $(BINARY_NAME)
22endif
23
24DATE := $(shell date -u '+%Y-%m-%d-%H%M UTC')
25VERSION_FLAGS := -X "main.Version=$(VERSION)" -X "main.BuildTime=$(DATE)"
26ifdef PACKAGE_MANAGER
27 VERSION_FLAGS := $(VERSION_FLAGS) -X "github.com/cloudflare/cloudflared/cmd/cloudflared/updater.BuiltForPackageManager=$(PACKAGE_MANAGER)"
28endif
29
30LINK_FLAGS :=
31ifeq ($(FIPS), true)
32 LINK_FLAGS := -linkmode=external -extldflags=-static $(LINK_FLAGS)
33 # Prevent linking with libc regardless of CGO enabled or not.
34 GO_BUILD_TAGS := $(GO_BUILD_TAGS) osusergo netgo fips
35 VERSION_FLAGS := $(VERSION_FLAGS) -X "main.BuildType=FIPS"
36endif
37
38LDFLAGS := -ldflags='$(VERSION_FLAGS) $(LINK_FLAGS)'
39ifneq ($(GO_BUILD_TAGS),)
40 GO_BUILD_TAGS := -tags "$(GO_BUILD_TAGS)"
41endif
42
43ifeq ($(debug), 1)
44 GO_BUILD_TAGS += -gcflags="all=-N -l"
45endif
46
47IMPORT_PATH := github.com/cloudflare/cloudflared
48PACKAGE_DIR := $(CURDIR)/packaging
49PREFIX := /usr
50INSTALL_BINDIR := $(PREFIX)/bin/
51INSTALL_MANDIR := $(PREFIX)/share/man/man1/
52
53LOCAL_ARCH ?= $(shell uname -m)
54ifneq ($(GOARCH),)
55 TARGET_ARCH ?= $(GOARCH)
56else ifeq ($(LOCAL_ARCH),x86_64)
57 TARGET_ARCH ?= amd64
58else ifeq ($(LOCAL_ARCH),amd64)
59 TARGET_ARCH ?= amd64
60else ifeq ($(LOCAL_ARCH),i686)
61 TARGET_ARCH ?= amd64
62else ifeq ($(shell echo $(LOCAL_ARCH) | head -c 5),armv8)
63 TARGET_ARCH ?= arm64
64else ifeq ($(LOCAL_ARCH),aarch64)
65 TARGET_ARCH ?= arm64
66else ifeq ($(LOCAL_ARCH),arm64)
67 TARGET_ARCH ?= arm64
68else ifeq ($(shell echo $(LOCAL_ARCH) | head -c 4),armv)
69 TARGET_ARCH ?= arm
70else ifeq ($(LOCAL_ARCH),s390x)
71 TARGET_ARCH ?= s390x
72else
73 $(error This system's architecture $(LOCAL_ARCH) isn't supported)
74endif
75
76LOCAL_OS ?= $(shell go env GOOS)
77ifeq ($(LOCAL_OS),linux)
78 TARGET_OS ?= linux
79else ifeq ($(LOCAL_OS),darwin)
80 TARGET_OS ?= darwin
81else ifeq ($(LOCAL_OS),windows)
82 TARGET_OS ?= windows
83else ifeq ($(LOCAL_OS),freebsd)
84 TARGET_OS ?= freebsd
85else
86 $(error This system's OS $(LOCAL_OS) isn't supported)
87endif
88
89ifeq ($(TARGET_OS), windows)
90 EXECUTABLE_PATH=./$(BINARY_NAME).exe
91else
92 EXECUTABLE_PATH=./$(BINARY_NAME)
93endif
94
95ifeq ($(FLAVOR), centos-7)
96 TARGET_PUBLIC_REPO ?= el7
97else
98 TARGET_PUBLIC_REPO ?= $(FLAVOR)
99endif
100
101ifneq ($(TARGET_ARM), )
102 ARM_COMMAND := GOARM=$(TARGET_ARM)
103endif
104
105ifeq ($(TARGET_ARM), 7)
106 PACKAGE_ARCH := armhf
107else
108 PACKAGE_ARCH := $(TARGET_ARCH)
109endif
110
111.PHONY: all
112all: cloudflared test
113
114.PHONY: clean
115clean:
116 go clean
117
118.PHONY: cloudflared
119cloudflared:
120ifeq ($(FIPS), true)
121 $(info Building cloudflared with go-fips)
122 cp -f fips/fips.go.linux-amd64 cmd/cloudflared/fips.go
123endif
124 GOOS=$(TARGET_OS) GOARCH=$(TARGET_ARCH) $(ARM_COMMAND) go build -v -mod=vendor $(GO_BUILD_TAGS) $(LDFLAGS) $(IMPORT_PATH)/cmd/cloudflared
125ifeq ($(FIPS), true)
126 rm -f cmd/cloudflared/fips.go
127 ./check-fips.sh cloudflared
128endif
129
130.PHONY: container
131container:
132 docker build --build-arg=TARGET_ARCH=$(TARGET_ARCH) --build-arg=TARGET_OS=$(TARGET_OS) -t cloudflare/cloudflared-$(TARGET_OS)-$(TARGET_ARCH):"$(VERSION)" .
133
134.PHONY: test
135test: vet
136ifndef CI
137 go test -v -mod=vendor -race $(LDFLAGS) ./...
138else
139 @mkdir -p .cover
140 go test -v -mod=vendor -race $(LDFLAGS) -coverprofile=".cover/c.out" ./...
141 go tool cover -html ".cover/c.out" -o .cover/all.html
142endif
143
144.PHONY: test-ssh-server
145test-ssh-server:
146 docker-compose -f ssh_server_tests/docker-compose.yml up
147
148define publish_package
149 chmod 664 $(BINARY_NAME)*.$(1); \
150 for HOST in $(CF_PKG_HOSTS); do \
151 ssh-keyscan -t ecdsa $$HOST >> ~/.ssh/known_hosts; \
152 scp -p -4 $(BINARY_NAME)*.$(1) cfsync@$$HOST:/state/cf-pkg/staging/$(2)/$(TARGET_PUBLIC_REPO)/$(BINARY_NAME)/; \
153 done
154endef
155
156.PHONY: publish-deb
157publish-deb: cloudflared-deb
158 $(call publish_package,deb,apt)
159
160.PHONY: publish-rpm
161publish-rpm: cloudflared-rpm
162 $(call publish_package,rpm,yum)
163
164cloudflared.1: cloudflared_man_template
165 cat cloudflared_man_template | sed -e 's/\$${VERSION}/$(VERSION)/; s/\$${DATE}/$(DATE)/' > cloudflared.1
166
167install: cloudflared cloudflared.1
168 mkdir -p $(DESTDIR)$(INSTALL_BINDIR) $(DESTDIR)$(INSTALL_MANDIR)
169 install -m755 cloudflared $(DESTDIR)$(INSTALL_BINDIR)/cloudflared
170 install -m644 cloudflared.1 $(DESTDIR)$(INSTALL_MANDIR)/cloudflared.1
171
172# When we build packages, the package name will be FIPS-aware.
173# But we keep the binary installed by it to be named "cloudflared" regardless.
174define build_package
175 mkdir -p $(PACKAGE_DIR)
176 cp cloudflared $(PACKAGE_DIR)/cloudflared
177 cp cloudflared.1 $(PACKAGE_DIR)/cloudflared.1
178 fakeroot fpm -C $(PACKAGE_DIR) -s dir -t $(1) \
179 --description 'Cloudflare Tunnel daemon' \
180 --vendor 'Cloudflare' \
181 --license 'Apache License Version 2.0' \
182 --url 'https://github.com/cloudflare/cloudflared' \
183 -m 'Cloudflare <support@cloudflare.com>' \
184 -a $(PACKAGE_ARCH) -v $(VERSION) -n $(DEB_PACKAGE_NAME) $(NIGHTLY_FLAGS) --after-install postinst.sh --after-remove postrm.sh \
185 cloudflared=$(INSTALL_BINDIR) cloudflared.1=$(INSTALL_MANDIR)
186endef
187
188.PHONY: cloudflared-deb
189cloudflared-deb: cloudflared cloudflared.1
190 $(call build_package,deb)
191
192.PHONY: cloudflared-rpm
193cloudflared-rpm: cloudflared cloudflared.1
194 $(call build_package,rpm)
195
196.PHONY: cloudflared-pkg
197cloudflared-pkg: cloudflared cloudflared.1
198 $(call build_package,osxpkg)
199
200.PHONY: cloudflared-msi
201cloudflared-msi: cloudflared
202 wixl --define Version=$(VERSION) --define Path=$(EXECUTABLE_PATH) --output cloudflared-$(VERSION)-$(TARGET_ARCH).msi cloudflared.wxs
203
204.PHONY: cloudflared-darwin-amd64.tgz
205cloudflared-darwin-amd64.tgz: cloudflared
206 tar czf cloudflared-darwin-amd64.tgz cloudflared
207 rm cloudflared
208
209.PHONY: cloudflared-junos
210cloudflared-junos: cloudflared jetez-certificate.pem jetez-key.pem
211 jetez --source . \
212 -j jet.yaml \
213 --key jetez-key.pem \
214 --cert jetez-certificate.pem \
215 --version $(VERSION)
216 rm jetez-*.pem
217
218jetez-certificate.pem:
219ifndef JETEZ_CERT
220 $(error JETEZ_CERT not defined)
221endif
222 @echo "Writing JetEZ certificate"
223 @echo "$$JETEZ_CERT" > jetez-certificate.pem
224
225jetez-key.pem:
226ifndef JETEZ_KEY
227 $(error JETEZ_KEY not defined)
228endif
229 @echo "Writing JetEZ key"
230 @echo "$$JETEZ_KEY" > jetez-key.pem
231
232.PHONY: publish-cloudflared-junos
233publish-cloudflared-junos: cloudflared-junos cloudflared-x86-64.latest.s3
234ifndef S3_ENDPOINT
235 $(error S3_HOST not defined)
236endif
237ifndef S3_URI
238 $(error S3_URI not defined)
239endif
240ifndef S3_ACCESS_KEY
241 $(error S3_ACCESS_KEY not defined)
242endif
243ifndef S3_SECRET_KEY
244 $(error S3_SECRET_KEY not defined)
245endif
246 sha256sum cloudflared-x86-64-$(VERSION).tgz | awk '{printf $$1}' > cloudflared-x86-64-$(VERSION).tgz.shasum
247 s4cmd --endpoint-url $(S3_ENDPOINT) --force --API-GrantRead=uri=http://acs.amazonaws.com/groups/global/AllUsers \
248 put cloudflared-x86-64-$(VERSION).tgz $(S3_URI)/cloudflared-x86-64-$(VERSION).tgz
249 s4cmd --endpoint-url $(S3_ENDPOINT) --force --API-GrantRead=uri=http://acs.amazonaws.com/groups/global/AllUsers \
250 put cloudflared-x86-64-$(VERSION).tgz.shasum $(S3_URI)/cloudflared-x86-64-$(VERSION).tgz.shasum
251 dpkg --compare-versions "$(VERSION)" gt "$(shell cat cloudflared-x86-64.latest.s3)" && \
252 echo -n "$(VERSION)" > cloudflared-x86-64.latest && \
253 s4cmd --endpoint-url $(S3_ENDPOINT) --force --API-GrantRead=uri=http://acs.amazonaws.com/groups/global/AllUsers \
254 put cloudflared-x86-64.latest $(S3_URI)/cloudflared-x86-64.latest || \
255 echo "Latest version not updated"
256
257cloudflared-x86-64.latest.s3:
258 s4cmd --endpoint-url $(S3_ENDPOINT) --force \
259 get $(S3_URI)/cloudflared-x86-64.latest cloudflared-x86-64.latest.s3
260
261.PHONY: homebrew-upload
262homebrew-upload: cloudflared-darwin-amd64.tgz
263 aws s3 --endpoint-url $(S3_ENDPOINT) cp --acl public-read $$^ $(S3_URI)/cloudflared-$$(VERSION)-$1.tgz
264 aws s3 --endpoint-url $(S3_ENDPOINT) cp --acl public-read $(S3_URI)/cloudflared-$$(VERSION)-$1.tgz $(S3_URI)/cloudflared-stable-$1.tgz
265
266.PHONY: homebrew-release
267homebrew-release: homebrew-upload
268 ./publish-homebrew-formula.sh cloudflared-darwin-amd64.tgz $(VERSION) homebrew-cloudflare
269
270.PHONY: github-release
271github-release: cloudflared
272 python3 github_release.py --path $(EXECUTABLE_PATH) --release-version $(VERSION)
273
274.PHONY: github-release-built-pkgs
275github-release-built-pkgs:
276 python3 github_release.py --path $(PWD)/built_artifacts --release-version $(VERSION)
277
278.PHONY: release-pkgs-linux
279release-pkgs-linux:
280 python3 ./release_pkgs.py
281
282.PHONY: github-message
283github-message:
284 python3 github_message.py --release-version $(VERSION)
285
286.PHONY: github-mac-upload
287github-mac-upload:
288 python3 github_release.py --path artifacts/cloudflared-darwin-amd64.tgz --release-version $(VERSION) --name cloudflared-darwin-amd64.tgz
289 python3 github_release.py --path artifacts/cloudflared-amd64.pkg --release-version $(VERSION) --name cloudflared-amd64.pkg
290
291.PHONY: tunnelrpc-deps
292tunnelrpc-deps:
293 which capnp # https://capnproto.org/install.html
294 which capnpc-go # go get zombiezen.com/go/capnproto2/capnpc-go
295 capnp compile -ogo tunnelrpc/tunnelrpc.capnp
296
297.PHONY: quic-deps
298quic-deps:
299 which capnp
300 which capnpc-go
301 capnp compile -ogo quic/schema/quic_metadata_protocol.capnp
302
303.PHONY: vet
304vet:
305 go vet -mod=vendor ./...
306
307.PHONY: goimports
308goimports:
309 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
310