cloudflare/cloudflared
Publicmirrored from https://github.com/cloudflare/cloudflaredAvailable
Makefile
272lines · modecode
| 1 | # The targets cannot be run in parallel |
| 2 | .NOTPARALLEL: |
| 3 | |
| 4 | VERSION := $(shell git describe --tags --always --match "[0-9][0-9][0-9][0-9].*.*") |
| 5 | MSI_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 | |
| 9 | ifeq ($(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 |
| 12 | else ifeq ($(FIPS), true) |
| 13 | # Used for FIPS compliant builds that do not match the case above. |
| 14 | BINARY_NAME := cloudflared-fips |
| 15 | else |
| 16 | # Used for all other (non-FIPS) builds. |
| 17 | BINARY_NAME := cloudflared |
| 18 | endif |
| 19 | |
| 20 | ifeq ($(NIGHTLY), true) |
| 21 | DEB_PACKAGE_NAME := $(BINARY_NAME)-nightly |
| 22 | NIGHTLY_FLAGS := --conflicts cloudflared --replaces cloudflared |
| 23 | else |
| 24 | DEB_PACKAGE_NAME := $(BINARY_NAME) |
| 25 | endif |
| 26 | |
| 27 | DATE := $(shell date -u '+%Y-%m-%d-%H%M UTC') |
| 28 | VERSION_FLAGS := -X "main.Version=$(VERSION)" -X "main.BuildTime=$(DATE)" |
| 29 | ifdef PACKAGE_MANAGER |
| 30 | VERSION_FLAGS := $(VERSION_FLAGS) -X "github.com/cloudflare/cloudflared/cmd/cloudflared/updater.BuiltForPackageManager=$(PACKAGE_MANAGER)" |
| 31 | endif |
| 32 | |
| 33 | LINK_FLAGS := |
| 34 | ifeq ($(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" |
| 39 | endif |
| 40 | |
| 41 | LDFLAGS := -ldflags='$(VERSION_FLAGS) $(LINK_FLAGS)' |
| 42 | ifneq ($(GO_BUILD_TAGS),) |
| 43 | GO_BUILD_TAGS := -tags "$(GO_BUILD_TAGS)" |
| 44 | endif |
| 45 | |
| 46 | ifeq ($(debug), 1) |
| 47 | GO_BUILD_TAGS += -gcflags="all=-N -l" |
| 48 | endif |
| 49 | |
| 50 | IMPORT_PATH := github.com/cloudflare/cloudflared |
| 51 | PACKAGE_DIR := $(CURDIR)/packaging |
| 52 | PREFIX := /usr |
| 53 | INSTALL_BINDIR := $(PREFIX)/bin/ |
| 54 | INSTALL_MANDIR := $(PREFIX)/share/man/man1/ |
| 55 | CF_GO_PATH := /tmp/go |
| 56 | PATH := $(CF_GO_PATH)/bin:$(PATH) |
| 57 | |
| 58 | LOCAL_ARCH ?= $(shell uname -m) |
| 59 | ifneq ($(GOARCH),) |
| 60 | TARGET_ARCH ?= $(GOARCH) |
| 61 | else ifeq ($(LOCAL_ARCH),x86_64) |
| 62 | TARGET_ARCH ?= amd64 |
| 63 | else ifeq ($(LOCAL_ARCH),amd64) |
| 64 | TARGET_ARCH ?= amd64 |
| 65 | else ifeq ($(LOCAL_ARCH),i686) |
| 66 | TARGET_ARCH ?= amd64 |
| 67 | else ifeq ($(shell echo $(LOCAL_ARCH) | head -c 5),armv8) |
| 68 | TARGET_ARCH ?= arm64 |
| 69 | else ifeq ($(LOCAL_ARCH),aarch64) |
| 70 | TARGET_ARCH ?= arm64 |
| 71 | else ifeq ($(LOCAL_ARCH),arm64) |
| 72 | TARGET_ARCH ?= arm64 |
| 73 | else ifeq ($(shell echo $(LOCAL_ARCH) | head -c 4),armv) |
| 74 | TARGET_ARCH ?= arm |
| 75 | else ifeq ($(LOCAL_ARCH),s390x) |
| 76 | TARGET_ARCH ?= s390x |
| 77 | else |
| 78 | $(error This system's architecture $(LOCAL_ARCH) isn't supported) |
| 79 | endif |
| 80 | |
| 81 | LOCAL_OS ?= $(shell go env GOOS) |
| 82 | ifeq ($(LOCAL_OS),linux) |
| 83 | TARGET_OS ?= linux |
| 84 | else ifeq ($(LOCAL_OS),darwin) |
| 85 | TARGET_OS ?= darwin |
| 86 | else ifeq ($(LOCAL_OS),windows) |
| 87 | TARGET_OS ?= windows |
| 88 | else ifeq ($(LOCAL_OS),freebsd) |
| 89 | TARGET_OS ?= freebsd |
| 90 | else ifeq ($(LOCAL_OS),openbsd) |
| 91 | TARGET_OS ?= openbsd |
| 92 | else |
| 93 | $(error This system's OS $(LOCAL_OS) isn't supported) |
| 94 | endif |
| 95 | |
| 96 | ifeq ($(TARGET_OS), windows) |
| 97 | EXECUTABLE_PATH=./$(BINARY_NAME).exe |
| 98 | else |
| 99 | EXECUTABLE_PATH=./$(BINARY_NAME) |
| 100 | endif |
| 101 | |
| 102 | ifeq ($(FLAVOR), centos-7) |
| 103 | TARGET_PUBLIC_REPO ?= el7 |
| 104 | else |
| 105 | TARGET_PUBLIC_REPO ?= $(FLAVOR) |
| 106 | endif |
| 107 | |
| 108 | ifneq ($(TARGET_ARM), ) |
| 109 | ARM_COMMAND := GOARM=$(TARGET_ARM) |
| 110 | endif |
| 111 | |
| 112 | ifeq ($(TARGET_ARM), 7) |
| 113 | PACKAGE_ARCH := armhf |
| 114 | else |
| 115 | PACKAGE_ARCH := $(TARGET_ARCH) |
| 116 | endif |
| 117 | |
| 118 | #for FIPS compliance, FPM defaults to MD5. |
| 119 | RPM_DIGEST := --rpm-digest sha256 |
| 120 | |
| 121 | .PHONY: all |
| 122 | all: cloudflared test |
| 123 | |
| 124 | .PHONY: clean |
| 125 | clean: |
| 126 | go clean |
| 127 | |
| 128 | .PHONY: cloudflared |
| 129 | cloudflared: |
| 130 | ifeq ($(FIPS), true) |
| 131 | $(info Building cloudflared with go-fips) |
| 132 | cp -f fips/fips.go.linux-amd64 cmd/cloudflared/fips.go |
| 133 | endif |
| 134 | GOOS=$(TARGET_OS) GOARCH=$(TARGET_ARCH) $(ARM_COMMAND) go build -mod=vendor $(GO_BUILD_TAGS) $(LDFLAGS) $(IMPORT_PATH)/cmd/cloudflared |
| 135 | ifeq ($(FIPS), true) |
| 136 | rm -f cmd/cloudflared/fips.go |
| 137 | ./check-fips.sh cloudflared |
| 138 | endif |
| 139 | |
| 140 | .PHONY: container |
| 141 | container: |
| 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 |
| 145 | generate-docker-version: |
| 146 | echo latest $(VERSION) > versions |
| 147 | |
| 148 | |
| 149 | .PHONY: test |
| 150 | test: vet |
| 151 | ifndef CI |
| 152 | go test -v -mod=vendor -race $(LDFLAGS) ./... |
| 153 | else |
| 154 | @mkdir -p .cover |
| 155 | go test -v -mod=vendor -race $(LDFLAGS) -coverprofile=".cover/c.out" ./... |
| 156 | endif |
| 157 | |
| 158 | .PHONY: cover |
| 159 | cover: |
| 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 |
| 169 | test-ssh-server: |
| 170 | docker-compose -f ssh_server_tests/docker-compose.yml up |
| 171 | |
| 172 | .PHONY: install-go |
| 173 | install-go: |
| 174 | rm -rf ${CF_GO_PATH} |
| 175 | ./.teamcity/install-cloudflare-go.sh |
| 176 | |
| 177 | .PHONY: cleanup-go |
| 178 | cleanup-go: |
| 179 | rm -rf ${CF_GO_PATH} |
| 180 | |
| 181 | cloudflared.1: cloudflared_man_template |
| 182 | sed -e 's/\$${VERSION}/$(VERSION)/; s/\$${DATE}/$(DATE)/' cloudflared_man_template > cloudflared.1 |
| 183 | |
| 184 | install: 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. |
| 191 | define 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) |
| 203 | endef |
| 204 | |
| 205 | .PHONY: cloudflared-deb |
| 206 | cloudflared-deb: cloudflared cloudflared.1 |
| 207 | $(call build_package,deb) |
| 208 | |
| 209 | .PHONY: cloudflared-rpm |
| 210 | cloudflared-rpm: cloudflared cloudflared.1 |
| 211 | $(call build_package,rpm) |
| 212 | |
| 213 | .PHONY: cloudflared-pkg |
| 214 | cloudflared-pkg: cloudflared cloudflared.1 |
| 215 | $(call build_package,osxpkg) |
| 216 | |
| 217 | .PHONY: cloudflared-msi |
| 218 | cloudflared-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 |
| 222 | cloudflared-darwin-amd64.tgz: cloudflared |
| 223 | tar czf cloudflared-darwin-amd64.tgz cloudflared |
| 224 | rm cloudflared |
| 225 | |
| 226 | .PHONY: github-release |
| 227 | github-release: cloudflared |
| 228 | python3 github_release.py --path $(EXECUTABLE_PATH) --release-version $(VERSION) |
| 229 | |
| 230 | .PHONY: github-release-built-pkgs |
| 231 | github-release-built-pkgs: |
| 232 | python3 github_release.py --path $(PWD)/built_artifacts --release-version $(VERSION) |
| 233 | |
| 234 | .PHONY: release-pkgs-linux |
| 235 | release-pkgs-linux: |
| 236 | python3 ./release_pkgs.py |
| 237 | |
| 238 | .PHONY: github-message |
| 239 | github-message: |
| 240 | python3 github_message.py --release-version $(VERSION) |
| 241 | |
| 242 | .PHONY: github-mac-upload |
| 243 | github-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 |
| 248 | github-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 |
| 255 | tunnelrpc-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 |
| 261 | quic-deps: |
| 262 | which capnp |
| 263 | which capnpc-go |
| 264 | capnp compile -ogo quic/schema/quic_metadata_protocol.capnp |
| 265 | |
| 266 | .PHONY: vet |
| 267 | vet: |
| 268 | go vet -mod=vendor github.com/cloudflare/cloudflared/... |
| 269 | |
| 270 | .PHONY: fmt |
| 271 | fmt: |
| 272 | goimports -l -w -local github.com/cloudflare/cloudflared $$(go list -mod=vendor -f '{{.Dir}}' -a ./... | fgrep -v tunnelrpc) |
| 273 | |