cloudflare/cloudflared

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
a278753bbfddec4ef250fd1fb33d3d797c8ccda8

Branches

Tags

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

Clone

HTTPS

Download ZIP

Makefile

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