2021-11-16 10:37:59 +00:00
VERSION := $( shell git describe --tags --always --match "[0-9][0-9][0-9][0-9].*.*" )
2020-07-07 15:44:07 +00:00
MSI_VERSION := $( shell git tag -l --sort= v:refname | grep "w" | tail -1 | cut -c2-)
2020-09-22 21:56:23 +00:00
#MSI_VERSION expects the format of the tag to be: (wX.X.X). Starts with the w character to not break cfsetup.
2020-07-07 15:44:07 +00:00
#e.g. w3.0.1 or w4.2.10. It trims off the w character when creating the MSI.
2018-07-24 19:55:18 +00:00
2022-01-03 18:39:08 +00:00
i f e q ( $( ORIGINAL_NAME ) , t r u e )
# Used for builds that want FIPS compilation but want the artifacts generated to still have the original name.
BINARY_NAME := cloudflared
e l s e i f e q ( $( FIPS ) , t r u e )
# Used for FIPS compliant builds that do not match the case above.
2021-11-09 11:37:51 +00:00
BINARY_NAME := cloudflared-fips
e l s e
2022-01-03 18:39:08 +00:00
# Used for all other (non-FIPS) builds.
2021-11-09 11:37:51 +00:00
BINARY_NAME := cloudflared
2021-12-16 00:26:05 +00:00
e n d i f
2021-07-14 19:45:29 +00:00
i f e q ( $( NIGHTLY ) , t r u e )
2022-01-03 18:39:08 +00:00
DEB_PACKAGE_NAME := $( BINARY_NAME) -nightly
2021-07-14 19:45:29 +00:00
NIGHTLY_FLAGS := --conflicts cloudflared --replaces cloudflared
e l s e
2021-11-09 11:37:51 +00:00
DEB_PACKAGE_NAME := $( BINARY_NAME)
2021-07-14 19:45:29 +00:00
e n d i f
2021-01-28 16:10:19 +00:00
DATE := $( shell date -u '+%Y-%m-%d-%H%M UTC' )
2021-11-09 11:37:51 +00:00
VERSION_FLAGS := -X " main.Version= $( VERSION) " -X " main.BuildTime= $( DATE) "
2022-03-08 00:05:48 +00:00
i f d e f P A C K A G E _ M A N A G E R
VERSION_FLAGS := $( VERSION_FLAGS) -X " github.com/cloudflare/cloudflared/cmd/cloudflared/updater.BuiltForPackageManager= $( PACKAGE_MANAGER) "
e n d i f
2021-11-09 11:37:51 +00:00
LINK_FLAGS :=
i f e q ( $( FIPS ) , t r u e )
LINK_FLAGS := -linkmode= external -extldflags= -static $( LINK_FLAGS)
# Prevent linking with libc regardless of CGO enabled or not.
GO_BUILD_TAGS := $( GO_BUILD_TAGS) osusergo netgo fips
2021-12-27 19:05:14 +00:00
VERSION_FLAGS := $( VERSION_FLAGS) -X "main.BuildType=FIPS"
2021-11-09 11:37:51 +00:00
e n d i f
LDFLAGS := -ldflags= '$(VERSION_FLAGS) $(LINK_FLAGS)'
i f n e q ( $( GO_BUILD_TAGS ) , )
GO_BUILD_TAGS := -tags " $( GO_BUILD_TAGS) "
e n d i f
2021-01-28 16:10:19 +00:00
2022-05-26 17:52:39 +00:00
i f e q ( $( debug ) , 1 )
GO_BUILD_TAGS += -gcflags= "all=-N -l"
e n d i f
2022-03-08 00:05:48 +00:00
IMPORT_PATH := github.com/cloudflare/cloudflared
PACKAGE_DIR := $( CURDIR) /packaging
PREFIX := /usr
INSTALL_BINDIR := $( PREFIX) /bin/
INSTALL_MANDIR := $( PREFIX) /share/man/man1/
2018-07-25 21:05:46 +00:00
2020-05-29 01:06:27 +00:00
LOCAL_ARCH ?= $( shell uname -m)
2020-06-30 19:46:05 +00:00
i f n e q ( $( GOARCH ) , )
TARGET_ARCH ?= $( GOARCH)
e l s e i f e q ( $( LOCAL_ARCH ) , x 8 6 _ 6 4 )
2020-05-29 01:06:27 +00:00
TARGET_ARCH ?= amd64
2021-03-01 17:43:08 +00:00
e l s e i f e q ( $( LOCAL_ARCH ) , a m d 6 4 )
TARGET_ARCH ?= amd64
2020-07-07 15:44:07 +00:00
e l s e i f e q ( $( LOCAL_ARCH ) , i 6 8 6 )
TARGET_ARCH ?= amd64
2020-05-29 01:06:27 +00:00
e l s e i f e q ( $( shell echo $ ( LOCAL_ARCH ) | head -c 5) , a r m v 8 )
TARGET_ARCH ?= arm64
e l s e i f e q ( $( LOCAL_ARCH ) , a a r c h 6 4 )
TARGET_ARCH ?= arm64
2021-08-10 02:24:34 +00:00
e l s e i f e q ( $( LOCAL_ARCH ) , a r m 6 4 )
TARGET_ARCH ?= arm64
2020-05-29 01:06:27 +00:00
e l s e i f e q ( $( shell echo $ ( LOCAL_ARCH ) | head -c 4) , a r m v )
TARGET_ARCH ?= arm
2022-04-06 09:43:58 +00:00
e l s e i f e q ( $( LOCAL_ARCH ) , s 3 9 0 x )
TARGET_ARCH ?= s390x
2020-05-29 01:06:27 +00:00
e l s e
$( error This system's architecture $(LOCAL_ARCH) isn' t supported)
e n d i f
LOCAL_OS ?= $( shell go env GOOS)
i f e q ( $( LOCAL_OS ) , l i n u x )
TARGET_OS ?= linux
e l s e i f e q ( $( LOCAL_OS ) , d a r w i n )
TARGET_OS ?= darwin
2020-06-09 19:15:12 +00:00
e l s e i f e q ( $( LOCAL_OS ) , w i n d o w s )
TARGET_OS ?= windows
2020-09-22 21:56:23 +00:00
e l s e i f e q ( $( LOCAL_OS ) , f r e e b s d )
TARGET_OS ?= freebsd
2020-05-29 01:06:27 +00:00
e l s e
$( error This system's OS $(LOCAL_OS) isn' t supported)
2018-10-19 19:01:08 +00:00
e n d i f
2020-06-23 21:23:40 +00:00
i f e q ( $( TARGET_OS ) , w i n d o w s )
2021-11-09 11:37:51 +00:00
EXECUTABLE_PATH = ./$( BINARY_NAME) .exe
2020-06-23 21:23:40 +00:00
e l s e
2021-11-09 11:37:51 +00:00
EXECUTABLE_PATH = ./$( BINARY_NAME)
2020-06-23 21:23:40 +00:00
e n d i f
2020-07-06 19:44:39 +00:00
i f e q ( $( FLAVOR ) , c e n t o s - 7 )
TARGET_PUBLIC_REPO ?= el7
e l s e
TARGET_PUBLIC_REPO ?= $( FLAVOR)
e n d i f
2022-06-20 11:05:03 +00:00
i f n e q ( $( TARGET_ARM ) , )
ARM_COMMAND := GOARM = $( TARGET_ARM)
e n d i f
i f e q ( $( TARGET_ARM ) , 7 )
PACKAGE_ARCH := armhf
e l s e
PACKAGE_ARCH := $( TARGET_ARCH)
e n d i f
2018-07-24 19:55:18 +00:00
.PHONY : all
all : cloudflared test
2018-10-18 22:26:21 +00:00
.PHONY : clean
clean :
go clean
2018-07-24 19:55:18 +00:00
.PHONY : cloudflared
2021-11-09 11:37:51 +00:00
cloudflared :
2021-03-02 15:43:35 +00:00
i f e q ( $( FIPS ) , t r u e )
$( info Building cloudflared with go-fips)
2021-11-09 11:37:51 +00:00
cp -f fips/fips.go.linux-amd64 cmd/cloudflared/fips.go
2021-03-02 15:43:35 +00:00
e n d i f
2022-06-20 11:05:03 +00:00
GOOS = $( TARGET_OS) GOARCH = $( TARGET_ARCH) $( ARM_COMMAND) go build -v -mod= vendor $( GO_BUILD_TAGS) $( LDFLAGS) $( IMPORT_PATH) /cmd/cloudflared
2021-03-02 15:43:35 +00:00
i f e q ( $( FIPS ) , t r u e )
2021-11-09 11:37:51 +00:00
rm -f cmd/cloudflared/fips.go
./check-fips.sh cloudflared
2021-03-02 15:43:35 +00:00
e n d i f
2019-04-29 21:25:34 +00:00
.PHONY : container
container :
2020-05-29 01:06:27 +00:00
docker build --build-arg= TARGET_ARCH = $( TARGET_ARCH) --build-arg= TARGET_OS = $( TARGET_OS) -t cloudflare/cloudflared-$( TARGET_OS) -$( TARGET_ARCH) :" $( VERSION) " .
2019-04-29 21:25:34 +00:00
2018-07-24 19:55:18 +00:00
.PHONY : test
2019-03-29 23:05:11 +00:00
test : vet
2021-02-08 21:31:51 +00:00
i f n d e f C I
2021-11-09 11:37:51 +00:00
go test -v -mod= vendor -race $( LDFLAGS) ./...
2021-02-08 21:31:51 +00:00
e l s e
@mkdir -p .cover
2021-11-09 11:37:51 +00:00
go test -v -mod= vendor -race $( LDFLAGS) -coverprofile= ".cover/c.out" ./...
2021-02-08 21:31:51 +00:00
go tool cover -html ".cover/c.out" -o .cover/all.html
e n d i f
2018-07-25 21:05:46 +00:00
2019-09-18 16:33:13 +00:00
.PHONY : test -ssh -server
test-ssh-server :
docker-compose -f ssh_server_tests/docker-compose.yml up
2022-03-08 00:05:48 +00:00
cloudflared.1 : cloudflared_man_template
cat cloudflared_man_template | sed -e 's/\$${VERSION}/$(VERSION)/; s/\$${DATE}/$(DATE)/' > cloudflared.1
install : cloudflared cloudflared .1
mkdir -p $( DESTDIR) $( INSTALL_BINDIR) $( DESTDIR) $( INSTALL_MANDIR)
install -m755 cloudflared $( DESTDIR) $( INSTALL_BINDIR) /cloudflared
install -m644 cloudflared.1 $( DESTDIR) $( INSTALL_MANDIR) /cloudflared.1
2021-11-09 11:37:51 +00:00
# When we build packages, the package name will be FIPS-aware.
# But we keep the binary installed by it to be named "cloudflared" regardless.
2020-07-02 18:23:54 +00:00
d e f i n e b u i l d _ p a c k a g e
2018-07-25 21:05:46 +00:00
mkdir -p $( PACKAGE_DIR)
cp cloudflared $( PACKAGE_DIR) /cloudflared
2022-03-08 00:05:48 +00:00
cp cloudflared.1 $( PACKAGE_DIR) /cloudflared.1
2020-11-21 11:54:18 +00:00
fakeroot fpm -C $( PACKAGE_DIR) -s dir -t $( 1) \
2021-09-28 07:39:40 +00:00
--description 'Cloudflare Tunnel daemon' \
2020-07-08 14:36:42 +00:00
--vendor 'Cloudflare' \
2022-03-08 14:59:53 +00:00
--license 'Apache License Version 2.0' \
2020-07-08 14:36:42 +00:00
--url 'https://github.com/cloudflare/cloudflared' \
-m 'Cloudflare <support@cloudflare.com>' \
2022-06-20 11:05:03 +00:00
-a $( PACKAGE_ARCH) -v $( VERSION) -n $( DEB_PACKAGE_NAME) $( NIGHTLY_FLAGS) --after-install postinst.sh --after-remove postrm.sh \
2022-03-08 00:05:48 +00:00
cloudflared = $( INSTALL_BINDIR) cloudflared.1= $( INSTALL_MANDIR)
2020-07-02 18:23:54 +00:00
e n d e f
.PHONY : cloudflared -deb
2022-03-08 00:05:48 +00:00
cloudflared-deb : cloudflared cloudflared .1
2020-07-02 18:23:54 +00:00
$( call build_package,deb)
2018-07-26 20:45:18 +00:00
2020-06-30 15:43:54 +00:00
.PHONY : cloudflared -rpm
2022-03-08 00:05:48 +00:00
cloudflared-rpm : cloudflared cloudflared .1
2020-07-02 18:23:54 +00:00
$( call build_package,rpm)
2020-06-30 15:43:54 +00:00
2021-07-22 15:36:49 +00:00
.PHONY : cloudflared -pkg
2022-03-08 00:05:48 +00:00
cloudflared-pkg : cloudflared cloudflared .1
2021-07-22 15:36:49 +00:00
$( call build_package,osxpkg)
.PHONY : cloudflared -msi
2022-09-15 21:26:02 +00:00
cloudflared-msi :
2021-07-22 15:36:49 +00:00
wixl --define Version = $( VERSION) --define Path = $( EXECUTABLE_PATH) --output cloudflared-$( VERSION) -$( TARGET_ARCH) .msi cloudflared.wxs
2018-08-16 00:11:30 +00:00
.PHONY : cloudflared -darwin -amd 64.tgz
cloudflared-darwin-amd64.tgz : cloudflared
tar czf cloudflared-darwin-amd64.tgz cloudflared
rm cloudflared
2020-09-22 21:56:23 +00:00
.PHONY : cloudflared -junos
cloudflared-junos : cloudflared jetez -certificate .pem jetez -key .pem
jetez --source . \
-j jet.yaml \
--key jetez-key.pem \
--cert jetez-certificate.pem \
--version $( VERSION)
rm jetez-*.pem
jetez-certificate.pem :
i f n d e f J E T E Z _ C E R T
$( error JETEZ_CERT not defined)
e n d i f
@echo "Writing JetEZ certificate"
@echo " $$ JETEZ_CERT " > jetez-certificate.pem
jetez-key.pem :
i f n d e f J E T E Z _ K E Y
$( error JETEZ_KEY not defined)
e n d i f
@echo "Writing JetEZ key"
@echo " $$ JETEZ_KEY " > jetez-key.pem
.PHONY : publish -cloudflared -junos
publish-cloudflared-junos : cloudflared -junos cloudflared -x 86-64.latest .s 3
i f n d e f S 3 _ E N D P O I N T
$( error S3_HOST not defined)
e n d i f
i f n d e f S 3 _ U R I
$( error S3_URI not defined)
e n d i f
i f n d e f S 3 _ A C C E S S _ K E Y
$( error S3_ACCESS_KEY not defined)
e n d i f
i f n d e f S 3 _ S E C R E T _ K E Y
$( error S3_SECRET_KEY not defined)
e n d i f
sha256sum cloudflared-x86-64-$( VERSION) .tgz | awk '{printf $$1}' > cloudflared-x86-64-$( VERSION) .tgz.shasum
s4cmd --endpoint-url $( S3_ENDPOINT) --force --API-GrantRead= uri = http://acs.amazonaws.com/groups/global/AllUsers \
put cloudflared-x86-64-$( VERSION) .tgz $( S3_URI) /cloudflared-x86-64-$( VERSION) .tgz
s4cmd --endpoint-url $( S3_ENDPOINT) --force --API-GrantRead= uri = http://acs.amazonaws.com/groups/global/AllUsers \
put cloudflared-x86-64-$( VERSION) .tgz.shasum $( S3_URI) /cloudflared-x86-64-$( VERSION) .tgz.shasum
dpkg --compare-versions " $( VERSION) " gt " $( shell cat cloudflared-x86-64.latest.s3) " && \
echo -n " $( VERSION) " > cloudflared-x86-64.latest && \
s4cmd --endpoint-url $( S3_ENDPOINT) --force --API-GrantRead= uri = http://acs.amazonaws.com/groups/global/AllUsers \
put cloudflared-x86-64.latest $( S3_URI) /cloudflared-x86-64.latest || \
echo "Latest version not updated"
cloudflared-x86-64.latest.s3 :
s4cmd --endpoint-url $( S3_ENDPOINT) --force \
get $( S3_URI) /cloudflared-x86-64.latest cloudflared-x86-64.latest.s3
2018-08-16 00:11:30 +00:00
.PHONY : homebrew -upload
homebrew-upload : cloudflared -darwin -amd 64.tgz
aws s3 --endpoint-url $( S3_ENDPOINT) cp --acl public-read $$ ^ $( S3_URI) /cloudflared-$$ ( VERSION) -$1 .tgz
aws s3 --endpoint-url $( S3_ENDPOINT) cp --acl public-read $( S3_URI) /cloudflared-$$ ( VERSION) -$1 .tgz $( S3_URI) /cloudflared-stable-$1 .tgz
2019-03-29 23:05:11 +00:00
.PHONY : homebrew -release
2018-08-16 00:11:30 +00:00
homebrew-release : homebrew -upload
./publish-homebrew-formula.sh cloudflared-darwin-amd64.tgz $( VERSION) homebrew-cloudflare
2020-06-23 21:23:40 +00:00
.PHONY : github -release
github-release : cloudflared
python3 github_release.py --path $( EXECUTABLE_PATH) --release-version $( VERSION)
2021-07-26 12:49:17 +00:00
.PHONY : github -release -built -pkgs
github-release-built-pkgs :
python3 github_release.py --path $( PWD) /built_artifacts --release-version $( VERSION)
2022-05-12 07:32:09 +00:00
.PHONY : release -pkgs -linux
release-pkgs-linux :
python3 ./release_pkgs.py
2020-07-29 17:50:25 +00:00
.PHONY : github -message
github-message :
python3 github_message.py --release-version $( VERSION)
2020-08-07 19:01:38 +00:00
.PHONY : github -mac -upload
github-mac-upload :
2020-09-17 15:56:18 +00:00
python3 github_release.py --path artifacts/cloudflared-darwin-amd64.tgz --release-version $( VERSION) --name cloudflared-darwin-amd64.tgz
python3 github_release.py --path artifacts/cloudflared-amd64.pkg --release-version $( VERSION) --name cloudflared-amd64.pkg
2020-08-07 19:01:38 +00:00
2022-09-15 21:26:02 +00:00
.PHONY : github -windows -upload
github-windows-upload :
python3 github_release.py --path built_artifacts/cloudflared-windows-amd64.exe --release-version $( VERSION) --name cloudflared-windows-amd64.exe
python3 github_release.py --path built_artifacts/cloudflared-windows-amd64.msi --release-version $( VERSION) --name cloudflared-windows-amd64.msi
python3 github_release.py --path built_artifacts/cloudflared-windows-386.exe --release-version $( VERSION) --name cloudflared-windows-386.exe
python3 github_release.py --path built_artifacts/cloudflared-windows-386.msi --release-version $( VERSION) --name cloudflared-windows-386.msi
2021-07-22 15:36:49 +00:00
.PHONY : tunnelrpc -deps
tunnelrpc-deps :
2019-03-29 23:05:11 +00:00
which capnp # https://capnproto.org/install.html
2022-09-07 22:06:06 +00:00
which capnpc-go # go install zombiezen.com/go/capnproto2/capnpc-go@latest
2019-05-17 14:23:05 +00:00
capnp compile -ogo tunnelrpc/tunnelrpc.capnp
2019-03-29 23:05:11 +00:00
2021-07-08 09:29:49 +00:00
.PHONY : quic -deps
2021-11-09 11:37:51 +00:00
quic-deps :
which capnp
2021-07-08 09:29:49 +00:00
which capnpc-go
capnp compile -ogo quic/schema/quic_metadata_protocol.capnp
2019-03-29 23:05:11 +00:00
.PHONY : vet
vet :
2022-09-02 18:29:46 +00:00
go vet -v -mod= vendor ./...
2020-07-07 15:44:07 +00:00
2021-03-23 14:30:43 +00:00
.PHONY : goimports
goimports :
2022-04-06 09:43:58 +00:00
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