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