Skip to content

Commit 60de05b

Browse files
author
Dalton Cherry
committed
AUTH-2712 added MSI build for a windows agent
1 parent 3deef61 commit 60de05b

File tree

5 files changed

+103
-37
lines changed

5 files changed

+103
-37
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ cscope.*
1111
cloudflared
1212
cloudflared.pkg
1313
cloudflared.exe
14+
cloudflared.msi
1415
!cmd/cloudflared/
1516
.DS_Store
1617
*-session.log

.teamcity/build-macos.sh

Lines changed: 89 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,97 @@ export GO111MODULE=on
1313
# build 'cloudflared-darwin-amd64.tgz'
1414
mkdir -p artifacts
1515
FILENAME="$(pwd)/artifacts/cloudflared-darwin-amd64.tgz"
16+
PKGNAME="$(pwd)/artifacts/cloudflared-amd64.pkg"
17+
TARGET_DIRECTORY=".build"
18+
BINARY_NAME="cloudflared"
19+
VERSION=$(git describe --tags --always --dirty="-dev")
20+
PRODUCT="cloudflared"
21+
CODE_SIGN_PRIV="code_sign.pk12"
22+
CODE_SIGN_CERT="code_sign.cer"
23+
INSTALLER_PRIV="installer.pk12"
24+
INSTALLER_CERT="installer.cer"
1625
export PATH="$PATH:/usr/local/bin"
1726
mkdir -p ../src/github.com/cloudflare/
1827
cp -r . ../src/github.com/cloudflare/cloudflared
1928
cd ../src/github.com/cloudflare/cloudflared
2029
GOCACHE="$PWD/../../../../" GOPATH="$PWD/../../../../" CGO_ENABLED=1 make cloudflared
21-
tar czf "$FILENAME" cloudflared
30+
31+
# Add code signing private key to the key chain
32+
if [[ -z "${CFD_CODE_SIGN_KEY}" ]]; then
33+
# write private key to disk and then import it keychain
34+
echo -n -e ${CFD_CODE_SIGN_KEY} | base64 -D > ${CODE_SIGN_PRIV}
35+
security import ${CODE_SIGN_PRIV} -A -P "${CFD_CODE_SIGN_PASS}"
36+
rm ${CODE_SIGN_PRIV}
37+
else
38+
exit 1
39+
fi
40+
41+
# Add code signing certificate to the key chain
42+
if [[ -z "${CFD_CODE_SIGN_CERT}" ]]; then
43+
# write certificate to disk and then import it keychain
44+
echo -n -e ${CFD_CODE_SIGN_CERT} | base64 -D > ${CODE_SIGN_CERT}
45+
security import ${CODE_SIGN_CERT}
46+
rm ${CODE_SIGN_CERT}
47+
else
48+
exit 1
49+
fi
50+
51+
# Add package signing private key to the key chain
52+
if [[ -z "${CFD_INSTALLER_KEY}" ]]; then
53+
# write private key to disk and then import it into the keychain
54+
echo -n -e ${CFD_INSTALLER_KEY} | base64 -D > ${INSTALLER_PRIV}
55+
security import ${INSTALLER_PRIV} -A -P "${CFD_INSTALLER_PASS}"
56+
rm ${INSTALLER_PRIV}
57+
else
58+
exit 1
59+
fi
60+
61+
# Add package signing certificate to the key chain
62+
if [[ -z "${CFD_INSTALLER_CERT}" ]]; then
63+
# write certificate to disk and then import it keychain
64+
echo -n -e ${CFD_INSTALLER_CERT} | base64 -D > ${INSTALLER_CERT}
65+
security import ${INSTALLER_CERT}
66+
rm ${INSTALLER_CERT}
67+
else
68+
exit 1
69+
fi
70+
71+
# get the code signing certificate name
72+
if [[ -z "${CFD_CODE_SIGN_NAME}" ]]; then
73+
CODE_SIGN_NAME=$(security find-identity -v | cut -d'"' -f 2 -s | grep "Developer ID Application:")
74+
else
75+
CODE_SIGN_NAME="${CFD_CODE_SIGN_NAME}"
76+
fi
77+
78+
# get the package signing certificate name
79+
if [[ -z "${CFD_INSTALLER_NAME}" ]]; then
80+
PKG_SIGN_NAME=$(security find-identity -v | cut -d'"' -f 2 -s | grep "Developer ID Installer:")
81+
else
82+
PKG_SIGN_NAME="${CFD_INSTALLER_NAME}"
83+
fi
84+
85+
# sign the cloudflared binary
86+
codesign -s "${CODE_SIGN_NAME}" -f -v --timestamp --options runtime ${BINARY_NAME}
87+
88+
# creating build directory
89+
mkdir ${TARGET_DIRECTORY}
90+
mkdir ${TARGET_DIRECTORY}/contents
91+
cp -r .mac_resources/scripts ${TARGET_DIRECTORY}/scripts
92+
93+
# copy cloudflared into the build directory
94+
cp ${BINARY_NAME} {$TARGET_DIRECTORY}/contents/${PRODUCT}
95+
96+
# compress cloudflared into a tar and gzipped file
97+
tar czf "$FILENAME" ${BINARY_NAME}
98+
99+
# build the installer package
100+
pkgbuild --identifier com.cloudflare.${PRODUCT} \
101+
--version ${VERSION} \
102+
--scripts ${TARGET_DIRECTORY}/scripts \
103+
--root ${TARGET_DIRECTORY}/contents \
104+
--install-location /usr/local/bin \
105+
--sign "${PKG_SIGN_NAME}" \
106+
${PKGNAME}
107+
108+
# cleaning up the build directory
109+
rm -rf $TARGET_DIRECTORY

Makefile

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
VERSION := $(shell git describe --tags --always --dirty="-dev")
1+
VERSION := $(shell git describe --tags --always --dirty="-dev" --exclude "w*")
22
DATE := $(shell date -u '+%Y-%m-%d-%H%M UTC')
33
VERSION_FLAGS := -ldflags='-X "main.Version=$(VERSION)" -X "main.BuildTime=$(DATE)"'
4+
MSI_VERSION := $(shell git tag -l --sort=v:refname | grep "w" | tail -1 | cut -c2-)
5+
#MSI_VERSION expects the format of the tag to be: (wX.X.X). Starts with the w character to not break cfsetup.
6+
#e.g. w3.0.1 or w4.2.10. It trims off the w character when creating the MSI.
47

58
IMPORT_PATH := github.com/cloudflare/cloudflared
69
PACKAGE_DIR := $(CURDIR)/packaging
@@ -22,6 +25,8 @@ ifneq ($(GOARCH),)
2225
TARGET_ARCH ?= $(GOARCH)
2326
else ifeq ($(LOCAL_ARCH),x86_64)
2427
TARGET_ARCH ?= amd64
28+
else ifeq ($(LOCAL_ARCH),i686)
29+
TARGET_ARCH ?= amd64
2530
else ifeq ($(shell echo $(LOCAL_ARCH) | head -c 5),armv8)
2631
TARGET_ARCH ?= arm64
2732
else ifeq ($(LOCAL_ARCH),aarch64)
@@ -158,3 +163,7 @@ vet:
158163
go vet -mod=vendor ./...
159164
which go-sumtype # go get github.com/BurntSushi/go-sumtype
160165
go-sumtype $$(go list -mod=vendor ./...)
166+
167+
.PHONY: msi
168+
msi: cloudflared
169+
go-msi make --msi cloudflared.msi --version $(MSI_VERSION)

cmd/cloudflared/windows_service.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,12 +150,11 @@ func (s *windowsService) Execute(serviceArgs []string, r <-chan svc.ChangeReques
150150
switch c.Cmd {
151151
case svc.Interrogate:
152152
statusChan <- c.CurrentStatus
153-
case svc.Stop:
153+
case svc.Stop, svc.Shutdown:
154154
close(s.graceShutdownC)
155+
statusChan <- svc.Status{State: svc.Stopped, Accepts: cmdsAccepted}
155156
statusChan <- svc.Status{State: svc.StopPending}
156-
case svc.Shutdown:
157-
close(s.shutdownC)
158-
statusChan <- svc.Status{State: svc.StopPending}
157+
return
159158
default:
160159
elog.Error(1, fmt.Sprintf("unexpected control request #%d", c))
161160
}

make-mac-pkg.sh

Lines changed: 0 additions & 31 deletions
This file was deleted.

0 commit comments

Comments
 (0)