cloudflare/cloudflared

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
2024.4.1

Branches

Tags

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

Clone

HTTPS

Download ZIP

Makefile

272lines · modecode

1# The targets cannot be run in parallel
2.NOTPARALLEL:
3
4VERSION := $(shell git describe --tags --always --match "[0-9][0-9][0-9][0-9].*.*")
5MSI_VERSION := $(shell git tag -l --sort=v:refname | grep "w" | tail -1 | cut -c2-)
6#MSI_VERSION expects the format of the tag to be: (wX.X.X). Starts with the w character to not break cfsetup.
7#e.g. w3.0.1 or w4.2.10. It trims off the w character when creating the MSI.
8
9ifeq ($(ORIGINAL_NAME), true)
10 # Used for builds that want FIPS compilation but want the artifacts generated to still have the original name.
11 BINARY_NAME := cloudflared
12else ifeq ($(FIPS), true)
13 # Used for FIPS compliant builds that do not match the case above.
14 BINARY_NAME := cloudflared-fips
15else
16 # Used for all other (non-FIPS) builds.
17 BINARY_NAME := cloudflared
18endif
19
20ifeq ($(NIGHTLY), true)
21 DEB_PACKAGE_NAME := $(BINARY_NAME)-nightly
22 NIGHTLY_FLAGS := --conflicts cloudflared --replaces cloudflared
23else
24 DEB_PACKAGE_NAME := $(BINARY_NAME)
25endif
26
27DATE := $(shell date -u '+%Y-%m-%d-%H%M UTC')
28VERSION_FLAGS := -X "main.Version=$(VERSION)" -X "main.BuildTime=$(DATE)"
29ifdef PACKAGE_MANAGER
30 VERSION_FLAGS := $(VERSION_FLAGS) -X "github.com/cloudflare/cloudflared/cmd/cloudflared/updater.BuiltForPackageManager=$(PACKAGE_MANAGER)"
31endif
32
33LINK_FLAGS :=
34ifeq ($(FIPS), true)
35 LINK_FLAGS := -linkmode=external -extldflags=-static $(LINK_FLAGS)
36 # Prevent linking with libc regardless of CGO enabled or not.
37 GO_BUILD_TAGS := $(GO_BUILD_TAGS) osusergo netgo fips
38 VERSION_FLAGS := $(VERSION_FLAGS) -X "main.BuildType=FIPS"
39endif
40
41LDFLAGS := -ldflags='$(VERSION_FLAGS) $(LINK_FLAGS)'
42ifneq ($(GO_BUILD_TAGS),)
43 GO_BUILD_TAGS := -tags "$(GO_BUILD_TAGS)"
44endif
45
46ifeq ($(debug), 1)
47 GO_BUILD_TAGS += -gcflags="all=-N -l"
48endif
49
50IMPORT_PATH := github.com/cloudflare/cloudflared
51PACKAGE_DIR := $(CURDIR)/packaging
52PREFIX := /usr
53INSTALL_BINDIR := $(PREFIX)/bin/
54INSTALL_MANDIR := $(PREFIX)/share/man/man1/
55CF_GO_PATH := /tmp/go
56PATH := $(CF_GO_PATH)/bin:$(PATH)
57
58LOCAL_ARCH ?= $(shell uname -m)
59ifneq ($(GOARCH),)
60 TARGET_ARCH ?= $(GOARCH)
61else ifeq ($(LOCAL_ARCH),x86_64)
62 TARGET_ARCH ?= amd64
63else ifeq ($(LOCAL_ARCH),amd64)
64 TARGET_ARCH ?= amd64
65else ifeq ($(LOCAL_ARCH),i686)
66 TARGET_ARCH ?= amd64
67else ifeq ($(shell echo $(LOCAL_ARCH) | head -c 5),armv8)
68 TARGET_ARCH ?= arm64
69else ifeq ($(LOCAL_ARCH),aarch64)
70 TARGET_ARCH ?= arm64
71else ifeq ($(LOCAL_ARCH),arm64)
72 TARGET_ARCH ?= arm64
73else ifeq ($(shell echo $(LOCAL_ARCH) | head -c 4),armv)
74 TARGET_ARCH ?= arm
75else ifeq ($(LOCAL_ARCH),s390x)
76 TARGET_ARCH ?= s390x
77else
78 $(error This system's architecture $(LOCAL_ARCH) isn't supported)
79endif
80
81LOCAL_OS ?= $(shell go env GOOS)
82ifeq ($(LOCAL_OS),linux)
83 TARGET_OS ?= linux
84else ifeq ($(LOCAL_OS),darwin)
85 TARGET_OS ?= darwin
86else ifeq ($(LOCAL_OS),windows)
87 TARGET_OS ?= windows
88else ifeq ($(LOCAL_OS),freebsd)
89 TARGET_OS ?= freebsd
90else ifeq ($(LOCAL_OS),openbsd)
91 TARGET_OS ?= openbsd
92else
93 $(error This system's OS $(LOCAL_OS) isn't supported)
94endif
95
96ifeq ($(TARGET_OS), windows)
97 EXECUTABLE_PATH=./$(BINARY_NAME).exe
98else
99 EXECUTABLE_PATH=./$(BINARY_NAME)
100endif
101
102ifeq ($(FLAVOR), centos-7)
103 TARGET_PUBLIC_REPO ?= el7
104else
105 TARGET_PUBLIC_REPO ?= $(FLAVOR)
106endif
107
108ifneq ($(TARGET_ARM), )
109 ARM_COMMAND := GOARM=$(TARGET_ARM)
110endif
111
112ifeq ($(TARGET_ARM), 7)
113 PACKAGE_ARCH := armhf
114else
115 PACKAGE_ARCH := $(TARGET_ARCH)
116endif
117
118#for FIPS compliance, FPM defaults to MD5.
119RPM_DIGEST := --rpm-digest sha256
120
121.PHONY: all
122all: cloudflared test
123
124.PHONY: clean
125clean:
126 go clean
127
128.PHONY: cloudflared
129cloudflared:
130ifeq ($(FIPS), true)
131 $(info Building cloudflared with go-fips)
132 cp -f fips/fips.go.linux-amd64 cmd/cloudflared/fips.go
133endif
134 GOOS=$(TARGET_OS) GOARCH=$(TARGET_ARCH) $(ARM_COMMAND) go build -mod=vendor $(GO_BUILD_TAGS) $(LDFLAGS) $(IMPORT_PATH)/cmd/cloudflared
135ifeq ($(FIPS), true)
136 rm -f cmd/cloudflared/fips.go
137 ./check-fips.sh cloudflared
138endif
139
140.PHONY: container
141container:
142 docker build --build-arg=TARGET_ARCH=$(TARGET_ARCH) --build-arg=TARGET_OS=$(TARGET_OS) -t cloudflare/cloudflared-$(TARGET_OS)-$(TARGET_ARCH):"$(VERSION)" .
143
144.PHONY: generate-docker-version
145generate-docker-version:
146 echo latest $(VERSION) > versions
147
148
149.PHONY: test
150test: vet
151ifndef CI
152 go test -v -mod=vendor -race $(LDFLAGS) ./...
153else
154 @mkdir -p .cover
155 go test -v -mod=vendor -race $(LDFLAGS) -coverprofile=".cover/c.out" ./...
156endif
157
158.PHONY: cover
159cover:
160 @echo ""
161 @echo "=====> Total test coverage: <====="
162 @echo ""
163 # Print the overall coverage here for quick access.
164 $Q go tool cover -func ".cover/c.out" | grep "total:" | awk '{print $$3}'
165 # Generate the HTML report that can be viewed from the browser in CI.
166 $Q go tool cover -html ".cover/c.out" -o .cover/all.html
167
168.PHONY: test-ssh-server
169test-ssh-server:
170 docker-compose -f ssh_server_tests/docker-compose.yml up
171
172.PHONY: install-go
173install-go:
174 rm -rf ${CF_GO_PATH}
175 ./.teamcity/install-cloudflare-go.sh
176
177.PHONY: cleanup-go
178cleanup-go:
179 rm -rf ${CF_GO_PATH}
180
181cloudflared.1: cloudflared_man_template
182 sed -e 's/\$${VERSION}/$(VERSION)/; s/\$${DATE}/$(DATE)/' cloudflared_man_template > cloudflared.1
183
184install: install-go cloudflared cloudflared.1 cleanup-go
185 mkdir -p $(DESTDIR)$(INSTALL_BINDIR) $(DESTDIR)$(INSTALL_MANDIR)
186 install -m755 cloudflared $(DESTDIR)$(INSTALL_BINDIR)/cloudflared
187 install -m644 cloudflared.1 $(DESTDIR)$(INSTALL_MANDIR)/cloudflared.1
188
189# When we build packages, the package name will be FIPS-aware.
190# But we keep the binary installed by it to be named "cloudflared" regardless.
191define build_package
192 mkdir -p $(PACKAGE_DIR)
193 cp cloudflared $(PACKAGE_DIR)/cloudflared
194 cp cloudflared.1 $(PACKAGE_DIR)/cloudflared.1
195 fpm -C $(PACKAGE_DIR) -s dir -t $(1) \
196 --description 'Cloudflare Tunnel daemon' \
197 --vendor 'Cloudflare' \
198 --license 'Apache License Version 2.0' \
199 --url 'https://github.com/cloudflare/cloudflared' \
200 -m 'Cloudflare <support@cloudflare.com>' \
201 -a $(PACKAGE_ARCH) -v $(VERSION) -n $(DEB_PACKAGE_NAME) $(RPM_DIGEST) $(NIGHTLY_FLAGS) --after-install postinst.sh --after-remove postrm.sh \
202 cloudflared=$(INSTALL_BINDIR) cloudflared.1=$(INSTALL_MANDIR)
203endef
204
205.PHONY: cloudflared-deb
206cloudflared-deb: cloudflared cloudflared.1
207 $(call build_package,deb)
208
209.PHONY: cloudflared-rpm
210cloudflared-rpm: cloudflared cloudflared.1
211 $(call build_package,rpm)
212
213.PHONY: cloudflared-pkg
214cloudflared-pkg: cloudflared cloudflared.1
215 $(call build_package,osxpkg)
216
217.PHONY: cloudflared-msi
218cloudflared-msi:
219 wixl --define Version=$(VERSION) --define Path=$(EXECUTABLE_PATH) --output cloudflared-$(VERSION)-$(TARGET_ARCH).msi cloudflared.wxs
220
221.PHONY: cloudflared-darwin-amd64.tgz
222cloudflared-darwin-amd64.tgz: cloudflared
223 tar czf cloudflared-darwin-amd64.tgz cloudflared
224 rm cloudflared
225
226.PHONY: github-release
227github-release: cloudflared
228 python3 github_release.py --path $(EXECUTABLE_PATH) --release-version $(VERSION)
229
230.PHONY: github-release-built-pkgs
231github-release-built-pkgs:
232 python3 github_release.py --path $(PWD)/built_artifacts --release-version $(VERSION)
233
234.PHONY: release-pkgs-linux
235release-pkgs-linux:
236 python3 ./release_pkgs.py
237
238.PHONY: github-message
239github-message:
240 python3 github_message.py --release-version $(VERSION)
241
242.PHONY: github-mac-upload
243github-mac-upload:
244 python3 github_release.py --path artifacts/cloudflared-darwin-amd64.tgz --release-version $(VERSION) --name cloudflared-darwin-amd64.tgz
245 python3 github_release.py --path artifacts/cloudflared-amd64.pkg --release-version $(VERSION) --name cloudflared-amd64.pkg
246
247.PHONY: github-windows-upload
248github-windows-upload:
249 python3 github_release.py --path built_artifacts/cloudflared-windows-amd64.exe --release-version $(VERSION) --name cloudflared-windows-amd64.exe
250 python3 github_release.py --path built_artifacts/cloudflared-windows-amd64.msi --release-version $(VERSION) --name cloudflared-windows-amd64.msi
251 python3 github_release.py --path built_artifacts/cloudflared-windows-386.exe --release-version $(VERSION) --name cloudflared-windows-386.exe
252 python3 github_release.py --path built_artifacts/cloudflared-windows-386.msi --release-version $(VERSION) --name cloudflared-windows-386.msi
253
254.PHONY: tunnelrpc-deps
255tunnelrpc-deps:
256 which capnp # https://capnproto.org/install.html
257 which capnpc-go # go install zombiezen.com/go/capnproto2/capnpc-go@latest
258 capnp compile -ogo tunnelrpc/tunnelrpc.capnp
259
260.PHONY: quic-deps
261quic-deps:
262 which capnp
263 which capnpc-go
264 capnp compile -ogo quic/schema/quic_metadata_protocol.capnp
265
266.PHONY: vet
267vet:
268 go vet -mod=vendor github.com/cloudflare/cloudflared/...
269
270.PHONY: fmt
271fmt:
272 goimports -l -w -local github.com/cloudflare/cloudflared $$(go list -mod=vendor -f '{{.Dir}}' -a ./... | fgrep -v tunnelrpc)
273