github.com/smithx10/nomad@v0.9.1-rc1/scripts/release/mac-remote-build (about)

     1  #!/usr/bin/env bash
     2  
     3  # A script for building macOS binary on a remote macOS host
     4  #
     5  # The helper is expected to be invoked with nomad repo as a first argument, e.g.
     6  # `mac-remote-build ~/go/src/github.com/hashicorp/nomad`.
     7  #
     8  # The repository is required to have a HEAD with all generated files and udpated version committed.
     9  #
    10  # The script runs a host on `sharedmac-bot` host (assumes a corresponding entry in ~/.ssh/config).
    11  # `REMOTE_MACOS_HOST` envvar can be set to point to another macOS host
    12  #
    13  # The script operates by creating a temporary workspace in the remote host to
    14  # contain a clean go installation and gopath with the repository content.
    15  # It should install all dependencies worth pinning, and *not* use system binaries
    16  # that may influence the integrity of the release.
    17  #
    18  
    19  set -o errexit
    20  
    21  REPO="$1"
    22  RELEASE_TARGET="${2:-release}"
    23  
    24  if [[ -z "${REPO}" ]]
    25  then
    26      echo "repo path is required"
    27      echo "Usage: $0 <repo_path>"
    28      exit 1
    29  fi
    30  
    31  TMP_WORKSPACE="/tmp/nomad-workspace/$(date +%Y-%m-%d-%s)"
    32  REPO_REMOTE_PATH="${TMP_WORKSPACE}/gopath/src/github.com/hashicorp/nomad"
    33  
    34  readonly remote_macos_host=${REMOTE_MACOS_HOST:-sharedmac-bot}
    35  
    36  echo "Using temp workspace: ${TMP_WORKSPACE}"
    37  echo
    38  
    39  echo '=======>>>> Transfering repository'
    40  ssh ${remote_macos_host} mkdir -p "${REPO_REMOTE_PATH}"
    41  rsync -az \
    42        "${REPO}/.git" \
    43        "${remote_macos_host}:${REPO_REMOTE_PATH}"
    44  
    45  echo '=======>>>> Compiling Mac Binaries'
    46  cat <<'EOF' | ssh ${remote_macos_host} /bin/bash -s "${TMP_WORKSPACE}" "${RELEASE_TARGET}"
    47  
    48  set -o errexit
    49  set -o xtrace
    50  
    51  TMP_WORKSPACE="$1"
    52  RELEASE_TARGET="$2"
    53  REPO_PATH="${TMP_WORKSPACE}/gopath/src/github.com/hashicorp/nomad"
    54  
    55  
    56  mkdir -p "${TMP_WORKSPACE}/tmp"
    57  
    58  install_go() {
    59    local go_version="1.11.6"
    60    local download=
    61  
    62    download="https://storage.googleapis.com/golang/go${go_version}.darwin-amd64.tar.gz"
    63    curl -sSL --fail -o "${TMP_WORKSPACE}/tmp/go.tar.gz" ${download}
    64  
    65    tar -C "${TMP_WORKSPACE}" -xf "${TMP_WORKSPACE}/tmp/go.tar.gz"
    66  }
    67  
    68  install_release_deps() {
    69    go get -u github.com/a8m/tree/cmd/tree
    70  }
    71  
    72  compile() {
    73    cd "${REPO_PATH}"
    74    git checkout .
    75    git status
    76    git log -1
    77    make ${RELEASE_TARGET}
    78  }
    79  
    80  install_go
    81  
    82  export GOPATH="${TMP_WORKSPACE}/gopath"
    83  export PATH="${TMP_WORKSPACE}/go/bin:${GOPATH}/bin:$PATH"
    84  
    85  install_release_deps
    86  compile
    87  
    88  EOF
    89  
    90  echo '=======>>>> Retreiving mac compiled binaries'
    91  rsync -avz --ignore-existing ${remote_macos_host}:"${REPO_REMOTE_PATH}/pkg/" "${REPO}/pkg"
    92  
    93  ssh ${remote_macos_host} rm -rf "${TMP_WORKSPACE}"