cloudflare/cloudflared

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
2023.10.0

Branches

Tags

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

Clone

HTTPS

Download ZIP

Makefile

267lines · 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
144.PHONY: test
145test: vet
146ifndef CI
147 go test -v -mod=vendor -race $(LDFLAGS) ./...
148else
149 @mkdir -p .cover
150 go test -v -mod=vendor -race $(LDFLAGS) -coverprofile=".cover/c.out" ./...
151endif
152
153.PHONY: cover
154cover:
155 @echo ""
156 @echo "=====> Total test coverage: <====="
157 @echo ""
158 # Print the overall coverage here for quick access.
159 $Q go tool cover -func ".cover/c.out" | grep "total:" | awk '{print $$3}'
160 # Generate the HTML report that can be viewed from the browser in CI.
161 $Q go tool cover -html ".cover/c.out" -o .cover/all.html
162
163.PHONY: test-ssh-server
164test-ssh-server:
165 docker-compose -f ssh_server_tests/docker-compose.yml up
166
167cloudflared.1: cloudflared_man_template
168 sed -e 's/\$${VERSION}/$(VERSION)/; s/\$${DATE}/$(DATE)/' cloudflared_man_template > cloudflared.1
169
170install: cloudflared cloudflared.1
171 mkdir -p $(DESTDIR)$(INSTALL_BINDIR) $(DESTDIR)$(INSTALL_MANDIR)
172 install -m755 cloudflared $(DESTDIR)$(INSTALL_BINDIR)/cloudflared
173 install -m644 cloudflared.1 $(DESTDIR)$(INSTALL_MANDIR)/cloudflared.1
174
175# When we build packages, the package name will be FIPS-aware.
176# But we keep the binary installed by it to be named "cloudflared" regardless.
177define build_package
178 mkdir -p $(PACKAGE_DIR)
179 cp cloudflared $(PACKAGE_DIR)/cloudflared
180 cp cloudflared.1 $(PACKAGE_DIR)/cloudflared.1
181 fpm -C $(PACKAGE_DIR) -s dir -t $(1) \
182 --description 'Cloudflare Tunnel daemon' \
183 --vendor 'Cloudflare' \
184 --license 'Apache License Version 2.0' \
185 --url 'https://github.com/cloudflare/cloudflared' \
186 -m 'Cloudflare <support@cloudflare.com>' \
187 -a $(PACKAGE_ARCH) -v $(VERSION) -n $(DEB_PACKAGE_NAME) $(RPM_DIGEST) $(NIGHTLY_FLAGS) --after-install postinst.sh --after-remove postrm.sh \
188 cloudflared=$(INSTALL_BINDIR) cloudflared.1=$(INSTALL_MANDIR)
189endef
190
191.PHONY: cloudflared-deb
192cloudflared-deb: cloudflared cloudflared.1
193 $(call build_package,deb)
194
195.PHONY: cloudflared-rpm
196cloudflared-rpm: cloudflared cloudflared.1
197 $(call build_package,rpm)
198
199.PHONY: cloudflared-pkg
200cloudflared-pkg: cloudflared cloudflared.1
201 $(call build_package,osxpkg)
202
203.PHONY: cloudflared-msi
204cloudflared-msi:
205 wixl --define Version=$(VERSION) --define Path=$(EXECUTABLE_PATH) --output cloudflared-$(VERSION)-$(TARGET_ARCH).msi cloudflared.wxs
206
207.PHONY: cloudflared-darwin-amd64.tgz
208cloudflared-darwin-amd64.tgz: cloudflared
209 tar czf cloudflared-darwin-amd64.tgz cloudflared
210 rm cloudflared
211
212.PHONY: homebrew-upload
213homebrew-upload: cloudflared-darwin-amd64.tgz
214 aws s3 --endpoint-url $(S3_ENDPOINT) cp --acl public-read $$^ $(S3_URI)/cloudflared-$$(VERSION)-$1.tgz
215 aws s3 --endpoint-url $(S3_ENDPOINT) cp --acl public-read $(S3_URI)/cloudflared-$$(VERSION)-$1.tgz $(S3_URI)/cloudflared-stable-$1.tgz
216
217.PHONY: homebrew-release
218homebrew-release: homebrew-upload
219 ./publish-homebrew-formula.sh cloudflared-darwin-amd64.tgz $(VERSION) homebrew-cloudflare
220
221.PHONY: github-release
222github-release: cloudflared
223 python3 github_release.py --path $(EXECUTABLE_PATH) --release-version $(VERSION)
224
225.PHONY: github-release-built-pkgs
226github-release-built-pkgs:
227 python3 github_release.py --path $(PWD)/built_artifacts --release-version $(VERSION)
228
229.PHONY: release-pkgs-linux
230release-pkgs-linux:
231 python3 ./release_pkgs.py
232
233.PHONY: github-message
234github-message:
235 python3 github_message.py --release-version $(VERSION)
236
237.PHONY: github-mac-upload
238github-mac-upload:
239 python3 github_release.py --path artifacts/cloudflared-darwin-amd64.tgz --release-version $(VERSION) --name cloudflared-darwin-amd64.tgz
240 python3 github_release.py --path artifacts/cloudflared-amd64.pkg --release-version $(VERSION) --name cloudflared-amd64.pkg
241
242.PHONY: github-windows-upload
243github-windows-upload:
244 python3 github_release.py --path built_artifacts/cloudflared-windows-amd64.exe --release-version $(VERSION) --name cloudflared-windows-amd64.exe
245 python3 github_release.py --path built_artifacts/cloudflared-windows-amd64.msi --release-version $(VERSION) --name cloudflared-windows-amd64.msi
246 python3 github_release.py --path built_artifacts/cloudflared-windows-386.exe --release-version $(VERSION) --name cloudflared-windows-386.exe
247 python3 github_release.py --path built_artifacts/cloudflared-windows-386.msi --release-version $(VERSION) --name cloudflared-windows-386.msi
248
249.PHONY: tunnelrpc-deps
250tunnelrpc-deps:
251 which capnp # https://capnproto.org/install.html
252 which capnpc-go # go install zombiezen.com/go/capnproto2/capnpc-go@latest
253 capnp compile -ogo tunnelrpc/tunnelrpc.capnp
254
255.PHONY: quic-deps
256quic-deps:
257 which capnp
258 which capnpc-go
259 capnp compile -ogo quic/schema/quic_metadata_protocol.capnp
260
261.PHONY: vet
262vet:
263 go vet -v -mod=vendor github.com/cloudflare/cloudflared/...
264
265.PHONY: fmt
266fmt:
267 goimports -l -w -local github.com/cloudflare/cloudflared $$(go list -mod=vendor -f '{{.Dir}}' -a ./... | fgrep -v tunnelrpc)
268