2019-03-15 13:55:13 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2019-03-20 01:18:27 +00:00
|
|
|
# A script for building macOS binary on a remote macOS host
|
|
|
|
#
|
|
|
|
# The helper is expected to be invoked with nomad repo as a first argument, e.g.
|
|
|
|
# `mac-remote-build ~/go/src/github.com/hashicorp/nomad`.
|
|
|
|
#
|
|
|
|
# The repository is required to have a HEAD with all generated files and udpated version committed.
|
|
|
|
#
|
|
|
|
# The script runs a host on `sharedmac-bot` host (assumes a corresponding entry in ~/.ssh/config).
|
|
|
|
# `REMOTE_MACOS_HOST` envvar can be set to point to another macOS host
|
|
|
|
#
|
|
|
|
# The script operates by creating a temporary workspace in the remote host to
|
|
|
|
# contain a clean go installation and gopath with the repository content.
|
|
|
|
# It should install all dependencies worth pinning, and *not* use system binaries
|
|
|
|
# that may influence the integrity of the release.
|
|
|
|
#
|
|
|
|
|
2019-03-18 18:34:09 +00:00
|
|
|
set -o errexit
|
2019-03-15 13:55:13 +00:00
|
|
|
|
|
|
|
REPO="$1"
|
|
|
|
RELEASE_TARGET="${2:-release}"
|
|
|
|
|
|
|
|
if [[ -z "${REPO}" ]]
|
|
|
|
then
|
|
|
|
echo "repo path is required"
|
2019-03-20 01:18:27 +00:00
|
|
|
echo "Usage: $0 <repo_path>"
|
2019-03-15 13:55:13 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
TMP_WORKSPACE="/tmp/nomad-workspace/$(date +%Y-%m-%d-%s)"
|
|
|
|
REPO_REMOTE_PATH="${TMP_WORKSPACE}/gopath/src/github.com/hashicorp/nomad"
|
|
|
|
|
2019-03-18 19:05:32 +00:00
|
|
|
readonly remote_macos_host=${REMOTE_MACOS_HOST:-sharedmac-bot}
|
|
|
|
|
2019-03-15 13:55:13 +00:00
|
|
|
echo "Using temp workspace: ${TMP_WORKSPACE}"
|
|
|
|
echo
|
|
|
|
|
|
|
|
echo '=======>>>> Transfering repository'
|
2019-03-18 19:05:32 +00:00
|
|
|
ssh ${remote_macos_host} mkdir -p "${REPO_REMOTE_PATH}"
|
2019-03-15 13:55:13 +00:00
|
|
|
rsync -az \
|
|
|
|
"${REPO}/.git" \
|
2019-03-18 19:05:32 +00:00
|
|
|
"${remote_macos_host}:${REPO_REMOTE_PATH}"
|
2019-03-15 13:55:13 +00:00
|
|
|
|
|
|
|
echo '=======>>>> Compiling Mac Binaries'
|
2019-03-21 18:46:35 +00:00
|
|
|
cat <<'EOF' | ssh ${remote_macos_host} /bin/bash -s "${TMP_WORKSPACE}" "${RELEASE_TARGET}"
|
2019-03-15 13:55:13 +00:00
|
|
|
|
2019-03-18 18:34:09 +00:00
|
|
|
set -o errexit
|
|
|
|
set -o xtrace
|
2019-03-15 13:55:13 +00:00
|
|
|
|
|
|
|
TMP_WORKSPACE="$1"
|
2019-03-21 18:46:35 +00:00
|
|
|
RELEASE_TARGET="$2"
|
2019-03-15 13:55:13 +00:00
|
|
|
REPO_PATH="${TMP_WORKSPACE}/gopath/src/github.com/hashicorp/nomad"
|
|
|
|
|
|
|
|
|
|
|
|
mkdir -p "${TMP_WORKSPACE}/tmp"
|
|
|
|
|
|
|
|
install_go() {
|
2020-06-16 15:45:16 +00:00
|
|
|
local go_version="1.14.4"
|
2019-03-15 13:55:13 +00:00
|
|
|
local download=
|
|
|
|
|
|
|
|
download="https://storage.googleapis.com/golang/go${go_version}.darwin-amd64.tar.gz"
|
|
|
|
curl -sSL --fail -o "${TMP_WORKSPACE}/tmp/go.tar.gz" ${download}
|
|
|
|
|
|
|
|
tar -C "${TMP_WORKSPACE}" -xf "${TMP_WORKSPACE}/tmp/go.tar.gz"
|
|
|
|
}
|
|
|
|
|
|
|
|
install_release_deps() {
|
|
|
|
go get -u github.com/a8m/tree/cmd/tree
|
|
|
|
}
|
|
|
|
|
|
|
|
compile() {
|
|
|
|
cd "${REPO_PATH}"
|
|
|
|
git checkout .
|
|
|
|
git status
|
|
|
|
git log -1
|
2019-03-21 18:46:35 +00:00
|
|
|
make ${RELEASE_TARGET}
|
2019-03-15 13:55:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
install_go
|
|
|
|
|
|
|
|
export GOPATH="${TMP_WORKSPACE}/gopath"
|
|
|
|
export PATH="${TMP_WORKSPACE}/go/bin:${GOPATH}/bin:$PATH"
|
|
|
|
|
|
|
|
install_release_deps
|
|
|
|
compile
|
|
|
|
|
|
|
|
EOF
|
|
|
|
|
2020-04-20 13:28:19 +00:00
|
|
|
echo '=======>>>> Retrieving mac compiled binaries'
|
2019-03-18 19:05:32 +00:00
|
|
|
rsync -avz --ignore-existing ${remote_macos_host}:"${REPO_REMOTE_PATH}/pkg/" "${REPO}/pkg"
|
2019-03-15 13:55:13 +00:00
|
|
|
|
2019-03-18 19:05:32 +00:00
|
|
|
ssh ${remote_macos_host} rm -rf "${TMP_WORKSPACE}"
|