cloudflare/cloudflared

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
cd4af5696d0db81caae903b33e4bbddfb5aff9ff

Branches

Tags

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

Clone

HTTPS

Download ZIP

Makefile

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