open-nomad/scripts/release/mac-remote-build

94 lines
2.4 KiB
Plaintext
Raw Normal View History

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"
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'
ssh ${remote_macos_host} mkdir -p "${REPO_REMOTE_PATH}"
2019-03-15 13:55:13 +00:00
rsync -az \
"${REPO}/.git" \
"${remote_macos_host}:${REPO_REMOTE_PATH}"
2019-03-15 13:55:13 +00:00
echo '=======>>>> Compiling Mac Binaries'
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"
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() {
2019-08-23 13:44:40 +00:00
local go_version="1.12.9"
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
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
echo '=======>>>> Retreiving mac compiled binaries'
rsync -avz --ignore-existing ${remote_macos_host}:"${REPO_REMOTE_PATH}/pkg/" "${REPO}/pkg"
2019-03-15 13:55:13 +00:00
ssh ${remote_macos_host} rm -rf "${TMP_WORKSPACE}"