TUN-8520: add macos arm64 build

- refactor build script for macos to include arm64 build
- refactor Makefile to upload all the artifacts instead of issuing one by one
- update cfsetup due to 2.
- place build files in specific folders
- cleanup build directory before/after creating build artifacts
This commit is contained in:
lneto 2024-07-05 19:39:22 +01:00
parent 75752b681b
commit c95959e845
2 changed files with 48 additions and 40 deletions

View File

@ -12,8 +12,6 @@ export GO111MODULE=on
# build 'cloudflared-darwin-amd64.tgz' # build 'cloudflared-darwin-amd64.tgz'
mkdir -p artifacts mkdir -p artifacts
FILENAME="$(pwd)/artifacts/cloudflared-darwin-amd64.tgz"
PKGNAME="$(pwd)/artifacts/cloudflared-amd64.pkg"
TARGET_DIRECTORY=".build" TARGET_DIRECTORY=".build"
BINARY_NAME="cloudflared" BINARY_NAME="cloudflared"
VERSION=$(git describe --tags --always --dirty="-dev") VERSION=$(git describe --tags --always --dirty="-dev")
@ -28,7 +26,6 @@ export PATH="$PATH:/usr/local/bin"
mkdir -p ../src/github.com/cloudflare/ mkdir -p ../src/github.com/cloudflare/
cp -r . ../src/github.com/cloudflare/cloudflared cp -r . ../src/github.com/cloudflare/cloudflared
cd ../src/github.com/cloudflare/cloudflared cd ../src/github.com/cloudflare/cloudflared
GOCACHE="$PWD/../../../../" GOPATH="$PWD/../../../../" CGO_ENABLED=1 make cloudflared
# Add code signing private key to the key chain # Add code signing private key to the key chain
if [[ ! -z "$CFD_CODE_SIGN_KEY" ]]; then if [[ ! -z "$CFD_CODE_SIGN_KEY" ]]; then
@ -138,47 +135,59 @@ else
fi fi
fi fi
# sign the cloudflared binary # cleanup the build directory because the previous execution might have failed without cleaning up.
if [[ ! -z "$CODE_SIGN_NAME" ]]; then rm -rf "${TARGET_DIRECTORY}"
codesign -s "${CODE_SIGN_NAME}" -f -v --timestamp --options runtime ${BINARY_NAME} archs=("amd64" "arm64")
export TARGET_OS=darwin
for arch in ${archs[@]}; do
# notarize the binary FILENAME="$(pwd)/artifacts/cloudflared-darwin-$arch.tgz"
# TODO: TUN-5789 PKGNAME="$(pwd)/artifacts/cloudflared-$arch.pkg"
fi TARGET_ARCH=$arch GOCACHE="$PWD/../../../../" GOPATH="$PWD/../../../../" CGO_ENABLED=1 make cloudflared
# creating build directory # sign the cloudflared binary
rm -rf $TARGET_DIRECTORY if [[ ! -z "$CODE_SIGN_NAME" ]]; then
mkdir "${TARGET_DIRECTORY}" codesign -s "${CODE_SIGN_NAME}" -f -v --timestamp --options runtime ${BINARY_NAME}
mkdir "${TARGET_DIRECTORY}/contents"
cp -r ".mac_resources/scripts" "${TARGET_DIRECTORY}/scripts" # notarize the binary
# TODO: TUN-5789
fi
# copy cloudflared into the build directory ARCH_TARGET_DIRECTORY="${TARGET_DIRECTORY}/${arch}-build"
cp ${BINARY_NAME} "${TARGET_DIRECTORY}/contents/${PRODUCT}" # creating build directory
rm -rf $ARCH_TARGET_DIRECTORY
mkdir "${ARCH_TARGET_DIRECTORY}"
mkdir "${ARCH_TARGET_DIRECTORY}/contents"
cp -r ".mac_resources/scripts" "${ARCH_TARGET_DIRECTORY}/scripts"
# compress cloudflared into a tar and gzipped file # copy cloudflared into the build directory
tar czf "$FILENAME" "${BINARY_NAME}" cp ${BINARY_NAME} "${ARCH_TARGET_DIRECTORY}/contents/${PRODUCT}"
# build the installer package # compress cloudflared into a tar and gzipped file
if [[ ! -z "$PKG_SIGN_NAME" ]]; then tar czf "$FILENAME" "${BINARY_NAME}"
pkgbuild --identifier com.cloudflare.${PRODUCT} \
--version ${VERSION} \
--scripts ${TARGET_DIRECTORY}/scripts \
--root ${TARGET_DIRECTORY}/contents \
--install-location /usr/local/bin \
--sign "${PKG_SIGN_NAME}" \
${PKGNAME}
# notarize the package # build the installer package
# TODO: TUN-5789 if [[ ! -z "$PKG_SIGN_NAME" ]]; then
else
pkgbuild --identifier com.cloudflare.${PRODUCT} \ pkgbuild --identifier com.cloudflare.${PRODUCT} \
--version ${VERSION} \ --version ${VERSION} \
--scripts ${TARGET_DIRECTORY}/scripts \ --scripts ${ARCH_TARGET_DIRECTORY}/scripts \
--root ${TARGET_DIRECTORY}/contents \ --root ${ARCH_TARGET_DIRECTORY}/contents \
--install-location /usr/local/bin \ --install-location /usr/local/bin \
${PKGNAME} --sign "${PKG_SIGN_NAME}" \
fi ${PKGNAME}
# notarize the package
# TODO: TUN-5789
else
pkgbuild --identifier com.cloudflare.${PRODUCT} \
--version ${VERSION} \
--scripts ${ARCH_TARGET_DIRECTORY}/scripts \
--root ${ARCH_TARGET_DIRECTORY}/contents \
--install-location /usr/local/bin \
${PKGNAME}
fi
done
# cleaning up the build directory # cleanup build the build directory because this script is not ran within containers,
rm -rf $TARGET_DIRECTORY # which might lead to future issues in subsequent runs.
rm -rf "${TARGET_DIRECTORY}"

View File

@ -241,8 +241,7 @@ github-message:
.PHONY: github-mac-upload .PHONY: github-mac-upload
github-mac-upload: github-mac-upload:
python3 github_release.py --path artifacts/cloudflared-darwin-amd64.tgz --release-version $(VERSION) --name cloudflared-darwin-amd64.tgz python3 github_release.py --path artifacts --release-version $(VERSION)
python3 github_release.py --path artifacts/cloudflared-amd64.pkg --release-version $(VERSION) --name cloudflared-amd64.pkg
.PHONY: github-windows-upload .PHONY: github-windows-upload
github-windows-upload: github-windows-upload: