Skip to content

Commit c2183bd

Browse files
committed
TUN-8546: rework MacOS build script
The rework consists in building and packaging the cloudflared binary based on the OS & ARCH of the system. read TARGET_ARCH from export and exit if TARGET_ARCH is not set
1 parent db239e7 commit c2183bd

File tree

1 file changed

+48
-46
lines changed

1 file changed

+48
-46
lines changed

.teamcity/mac/build.sh

Lines changed: 48 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ if [[ "$(uname)" != "Darwin" ]] ; then
77
exit 1
88
fi
99

10+
if [[ "amd64" != "${TARGET_ARCH}" && "arm64" != "${TARGET_ARCH}" ]]
11+
then
12+
echo "TARGET_ARCH must be amd64 or arm64"
13+
exit 1
14+
fi
15+
1016
go version
1117
export GO111MODULE=on
1218

@@ -137,56 +143,52 @@ fi
137143

138144
# cleanup the build directory because the previous execution might have failed without cleaning up.
139145
rm -rf "${TARGET_DIRECTORY}"
140-
archs=("amd64" "arm64")
141-
export TARGET_OS=darwin
142-
for arch in ${archs[@]}; do
143-
144-
FILENAME="$(pwd)/artifacts/cloudflared-darwin-$arch.tgz"
145-
PKGNAME="$(pwd)/artifacts/cloudflared-$arch.pkg"
146-
TARGET_ARCH=$arch GOCACHE="$PWD/../../../../" GOPATH="$PWD/../../../../" CGO_ENABLED=1 make cloudflared
147-
148-
# sign the cloudflared binary
149-
if [[ ! -z "$CODE_SIGN_NAME" ]]; then
150-
codesign -s "${CODE_SIGN_NAME}" -f -v --timestamp --options runtime ${BINARY_NAME}
151-
152-
# notarize the binary
153-
# TODO: TUN-5789
154-
fi
146+
export TARGET_OS="darwin"
147+
FILENAME="$(pwd)/artifacts/cloudflared-darwin-$TARGET_ARCH.tgz"
148+
PKGNAME="$(pwd)/artifacts/cloudflared-$TARGET_ARCH.pkg"
149+
GOCACHE="$PWD/../../../../" GOPATH="$PWD/../../../../" CGO_ENABLED=1 make cloudflared
155150

156-
ARCH_TARGET_DIRECTORY="${TARGET_DIRECTORY}/${arch}-build"
157-
# creating build directory
158-
rm -rf $ARCH_TARGET_DIRECTORY
159-
mkdir -p "${ARCH_TARGET_DIRECTORY}"
160-
mkdir -p "${ARCH_TARGET_DIRECTORY}/contents"
161-
cp -r ".mac_resources/scripts" "${ARCH_TARGET_DIRECTORY}/scripts"
151+
# sign the cloudflared binary
152+
if [[ ! -z "$CODE_SIGN_NAME" ]]; then
153+
codesign -s "${CODE_SIGN_NAME}" -f -v --timestamp --options runtime ${BINARY_NAME}
162154

163-
# copy cloudflared into the build directory
164-
cp ${BINARY_NAME} "${ARCH_TARGET_DIRECTORY}/contents/${PRODUCT}"
165-
166-
# compress cloudflared into a tar and gzipped file
167-
tar czf "$FILENAME" "${BINARY_NAME}"
155+
# notarize the binary
156+
# TODO: TUN-5789
157+
fi
168158

169-
# build the installer package
170-
if [[ ! -z "$PKG_SIGN_NAME" ]]; then
159+
ARCH_TARGET_DIRECTORY="${TARGET_DIRECTORY}/${arch}-build"
160+
# creating build directory
161+
rm -rf $ARCH_TARGET_DIRECTORY
162+
mkdir -p "${ARCH_TARGET_DIRECTORY}"
163+
mkdir -p "${ARCH_TARGET_DIRECTORY}/contents"
164+
cp -r ".mac_resources/scripts" "${ARCH_TARGET_DIRECTORY}/scripts"
165+
166+
# copy cloudflared into the build directory
167+
cp ${BINARY_NAME} "${ARCH_TARGET_DIRECTORY}/contents/${PRODUCT}"
168+
169+
# compress cloudflared into a tar and gzipped file
170+
tar czf "$FILENAME" "${BINARY_NAME}"
171+
172+
# build the installer package
173+
if [[ ! -z "$PKG_SIGN_NAME" ]]; then
174+
pkgbuild --identifier com.cloudflare.${PRODUCT} \
175+
--version ${VERSION} \
176+
--scripts ${ARCH_TARGET_DIRECTORY}/scripts \
177+
--root ${ARCH_TARGET_DIRECTORY}/contents \
178+
--install-location /usr/local/bin \
179+
--sign "${PKG_SIGN_NAME}" \
180+
${PKGNAME}
181+
182+
# notarize the package
183+
# TODO: TUN-5789
184+
else
171185
pkgbuild --identifier com.cloudflare.${PRODUCT} \
172-
--version ${VERSION} \
173-
--scripts ${ARCH_TARGET_DIRECTORY}/scripts \
174-
--root ${ARCH_TARGET_DIRECTORY}/contents \
175-
--install-location /usr/local/bin \
176-
--sign "${PKG_SIGN_NAME}" \
177-
${PKGNAME}
178-
179-
# notarize the package
180-
# TODO: TUN-5789
181-
else
182-
pkgbuild --identifier com.cloudflare.${PRODUCT} \
183-
--version ${VERSION} \
184-
--scripts ${ARCH_TARGET_DIRECTORY}/scripts \
185-
--root ${ARCH_TARGET_DIRECTORY}/contents \
186-
--install-location /usr/local/bin \
187-
${PKGNAME}
188-
fi
189-
done
186+
--version ${VERSION} \
187+
--scripts ${ARCH_TARGET_DIRECTORY}/scripts \
188+
--root ${ARCH_TARGET_DIRECTORY}/contents \
189+
--install-location /usr/local/bin \
190+
${PKGNAME}
191+
fi
190192

191193
# cleanup build directory because this script is not ran within containers,
192194
# which might lead to future issues in subsequent runs.

0 commit comments

Comments
 (0)