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