cloudflare/cloudflared

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
2023.5.1

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 ifeq ($(LOCAL_OS),openbsd)
86 TARGET_OS ?= openbsd
87else
88 $(error This system's OS $(LOCAL_OS) isn't supported)
89endif
90
91ifeq ($(TARGET_OS), windows)
92 EXECUTABLE_PATH=./$(BINARY_NAME).exe
93else
94 EXECUTABLE_PATH=./$(BINARY_NAME)
95endif
96
97ifeq ($(FLAVOR), centos-7)
98 TARGET_PUBLIC_REPO ?= el7
99else
100 TARGET_PUBLIC_REPO ?= $(FLAVOR)
101endif
102
103ifneq ($(TARGET_ARM), )
104 ARM_COMMAND := GOARM=$(TARGET_ARM)
105endif
106
107ifeq ($(TARGET_ARM), 7)
108 PACKAGE_ARCH := armhf
109else
110 PACKAGE_ARCH := $(TARGET_ARCH)
111endif
112
113#for FIPS compliance, FPM defaults to MD5.
114RPM_DIGEST := --rpm-digest sha256
115
116.PHONY: all
117all: cloudflared test
118
119.PHONY: clean
120clean:
121 go clean
122
123.PHONY: cloudflared
124cloudflared:
125ifeq ($(FIPS), true)
126 $(info Building cloudflared with go-fips)
127 cp -f fips/fips.go.linux-amd64 cmd/cloudflared/fips.go
128endif
129 GOOS=$(TARGET_OS) GOARCH=$(TARGET_ARCH) $(ARM_COMMAND) go build -v -mod=vendor $(GO_BUILD_TAGS) $(LDFLAGS) $(IMPORT_PATH)/cmd/cloudflared
130ifeq ($(FIPS), true)
131 rm -f cmd/cloudflared/fips.go
132 ./check-fips.sh cloudflared
133endif
134
135.PHONY: container
136container:
137 docker build --build-arg=TARGET_ARCH=$(TARGET_ARCH) --build-arg=TARGET_OS=$(TARGET_OS) -t cloudflare/cloudflared-$(TARGET_OS)-$(TARGET_ARCH):"$(VERSION)" .
138
139.PHONY: generate-docker-version
140generate-docker-version:
141 echo latest $(VERSION) > versions
142
143.PHONY: test
144test: vet
145ifndef CI
146 go test -v -mod=vendor -race $(LDFLAGS) ./...
147else
148 @mkdir -p .cover
149 go test -v -mod=vendor -race $(LDFLAGS) -coverprofile=".cover/c.out" ./...
150 go tool cover -html ".cover/c.out" -o .cover/all.html
151endif
152
153.PHONY: test-ssh-server
154test-ssh-server:
155 docker-compose -f ssh_server_tests/docker-compose.yml up
156
157cloudflared.1: cloudflared_man_template
158 sed -e 's/\$${VERSION}/$(VERSION)/; s/\$${DATE}/$(DATE)/' cloudflared_man_template > cloudflared.1
159
160install: cloudflared cloudflared.1
161 mkdir -p $(DESTDIR)$(INSTALL_BINDIR) $(DESTDIR)$(INSTALL_MANDIR)
162 install -m755 cloudflared $(DESTDIR)$(INSTALL_BINDIR)/cloudflared
163 install -m644 cloudflared.1 $(DESTDIR)$(INSTALL_MANDIR)/cloudflared.1
164
165# When we build packages, the package name will be FIPS-aware.
166# But we keep the binary installed by it to be named "cloudflared" regardless.
167define build_package
168 mkdir -p $(PACKAGE_DIR)
169 cp cloudflared $(PACKAGE_DIR)/cloudflared
170 cp cloudflared.1 $(PACKAGE_DIR)/cloudflared.1
171 fpm -C $(PACKAGE_DIR) -s dir -t $(1) \
172 --description 'Cloudflare Tunnel daemon' \
173 --vendor 'Cloudflare' \
174 --license 'Apache License Version 2.0' \
175 --url 'https://github.com/cloudflare/cloudflared' \
176 -m 'Cloudflare <support@cloudflare.com>' \
177 -a $(PACKAGE_ARCH) -v $(VERSION) -n $(DEB_PACKAGE_NAME) $(RPM_DIGEST) $(NIGHTLY_FLAGS) --after-install postinst.sh --after-remove postrm.sh \
178 cloudflared=$(INSTALL_BINDIR) cloudflared.1=$(INSTALL_MANDIR)
179endef
180
181.PHONY: cloudflared-deb
182cloudflared-deb: cloudflared cloudflared.1
183 $(call build_package,deb)
184
185.PHONY: cloudflared-rpm
186cloudflared-rpm: cloudflared cloudflared.1
187 $(call build_package,rpm)
188
189.PHONY: cloudflared-pkg
190cloudflared-pkg: cloudflared cloudflared.1
191 $(call build_package,osxpkg)
192
193.PHONY: cloudflared-msi
194cloudflared-msi:
195 wixl --define Version=$(VERSION) --define Path=$(EXECUTABLE_PATH) --output cloudflared-$(VERSION)-$(TARGET_ARCH).msi cloudflared.wxs
196
197.PHONY: cloudflared-darwin-amd64.tgz
198cloudflared-darwin-amd64.tgz: cloudflared
199 tar czf cloudflared-darwin-amd64.tgz cloudflared
200 rm cloudflared
201
202.PHONY: cloudflared-junos
203cloudflared-junos: cloudflared jetez-certificate.pem jetez-key.pem
204 jetez --source . \
205 -j jet.yaml \
206 --key jetez-key.pem \
207 --cert jetez-certificate.pem \
208 --version $(VERSION)
209 rm jetez-*.pem
210
211jetez-certificate.pem:
212ifndef JETEZ_CERT
213 $(error JETEZ_CERT not defined)
214endif
215 @echo "Writing JetEZ certificate"
216 @echo "$$JETEZ_CERT" > jetez-certificate.pem
217
218jetez-key.pem:
219ifndef JETEZ_KEY
220 $(error JETEZ_KEY not defined)
221endif
222 @echo "Writing JetEZ key"
223 @echo "$$JETEZ_KEY" > jetez-key.pem
224
225.PHONY: publish-cloudflared-junos
226publish-cloudflared-junos: cloudflared-junos cloudflared-x86-64.latest.s3
227ifndef S3_ENDPOINT
228 $(error S3_HOST not defined)
229endif
230ifndef S3_URI
231 $(error S3_URI not defined)
232endif
233ifndef S3_ACCESS_KEY
234 $(error S3_ACCESS_KEY not defined)
235endif
236ifndef S3_SECRET_KEY
237 $(error S3_SECRET_KEY not defined)
238endif
239 sha256sum cloudflared-x86-64-$(VERSION).tgz | awk '{printf $$1}' > cloudflared-x86-64-$(VERSION).tgz.shasum
240 s4cmd --endpoint-url $(S3_ENDPOINT) --force --API-GrantRead=uri=http://acs.amazonaws.com/groups/global/AllUsers \
241 put cloudflared-x86-64-$(VERSION).tgz $(S3_URI)/cloudflared-x86-64-$(VERSION).tgz
242 s4cmd --endpoint-url $(S3_ENDPOINT) --force --API-GrantRead=uri=http://acs.amazonaws.com/groups/global/AllUsers \
243 put cloudflared-x86-64-$(VERSION).tgz.shasum $(S3_URI)/cloudflared-x86-64-$(VERSION).tgz.shasum
244 dpkg --compare-versions "$(VERSION)" gt "$(shell cat cloudflared-x86-64.latest.s3)" && \
245 echo -n "$(VERSION)" > cloudflared-x86-64.latest && \
246 s4cmd --endpoint-url $(S3_ENDPOINT) --force --API-GrantRead=uri=http://acs.amazonaws.com/groups/global/AllUsers \
247 put cloudflared-x86-64.latest $(S3_URI)/cloudflared-x86-64.latest || \
248 echo "Latest version not updated"
249
250cloudflared-x86-64.latest.s3:
251 s4cmd --endpoint-url $(S3_ENDPOINT) --force \
252 get $(S3_URI)/cloudflared-x86-64.latest cloudflared-x86-64.latest.s3
253
254.PHONY: homebrew-upload
255homebrew-upload: cloudflared-darwin-amd64.tgz
256 aws s3 --endpoint-url $(S3_ENDPOINT) cp --acl public-read $$^ $(S3_URI)/cloudflared-$$(VERSION)-$1.tgz
257 aws s3 --endpoint-url $(S3_ENDPOINT) cp --acl public-read $(S3_URI)/cloudflared-$$(VERSION)-$1.tgz $(S3_URI)/cloudflared-stable-$1.tgz
258
259.PHONY: homebrew-release
260homebrew-release: homebrew-upload
261 ./publish-homebrew-formula.sh cloudflared-darwin-amd64.tgz $(VERSION) homebrew-cloudflare
262
263.PHONY: github-release
264github-release: cloudflared
265 python3 github_release.py --path $(EXECUTABLE_PATH) --release-version $(VERSION)
266
267.PHONY: github-release-built-pkgs
268github-release-built-pkgs:
269 python3 github_release.py --path $(PWD)/built_artifacts --release-version $(VERSION)
270
271.PHONY: release-pkgs-linux
272release-pkgs-linux:
273 python3 ./release_pkgs.py
274
275.PHONY: github-message
276github-message:
277 python3 github_message.py --release-version $(VERSION)
278
279.PHONY: github-mac-upload
280github-mac-upload:
281 python3 github_release.py --path artifacts/cloudflared-darwin-amd64.tgz --release-version $(VERSION) --name cloudflared-darwin-amd64.tgz
282 python3 github_release.py --path artifacts/cloudflared-amd64.pkg --release-version $(VERSION) --name cloudflared-amd64.pkg
283
284.PHONY: github-windows-upload
285github-windows-upload:
286 python3 github_release.py --path built_artifacts/cloudflared-windows-amd64.exe --release-version $(VERSION) --name cloudflared-windows-amd64.exe
287 python3 github_release.py --path built_artifacts/cloudflared-windows-amd64.msi --release-version $(VERSION) --name cloudflared-windows-amd64.msi
288 python3 github_release.py --path built_artifacts/cloudflared-windows-386.exe --release-version $(VERSION) --name cloudflared-windows-386.exe
289 python3 github_release.py --path built_artifacts/cloudflared-windows-386.msi --release-version $(VERSION) --name cloudflared-windows-386.msi
290
291.PHONY: tunnelrpc-deps
292tunnelrpc-deps:
293 which capnp # https://capnproto.org/install.html
294 which capnpc-go # go install zombiezen.com/go/capnproto2/capnpc-go@latest
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 -v -mod=vendor github.com/cloudflare/cloudflared/...
306
307.PHONY: fmt
308fmt:
309 goimports -l -w -local github.com/cloudflare/cloudflared $$(go list -mod=vendor -f '{{.Dir}}' -a ./... | fgrep -v tunnelrpc)
310