From 04adf14146ca0f24749fe5d62da6bfeea4b21ace Mon Sep 17 00:00:00 2001 From: Asher Date: Thu, 6 Jun 2019 13:42:10 -0500 Subject: [PATCH] Move OSX package task into build script This is to match how the other binaries are built. Also made some changes to make the Docker containers clean up for when you are running this locally. --- .travis.yml | 1 - build/tasks.ts | 2 ++ scripts/build.sh | 63 +++++++++++++++++++++++++++++++----------------- 3 files changed, 43 insertions(+), 23 deletions(-) diff --git a/.travis.yml b/.travis.yml index 78fda08e5..828655abf 100644 --- a/.travis.yml +++ b/.travis.yml @@ -27,7 +27,6 @@ before_deploy: - git config --local user.name "$USER_NAME" - git config --local user.email "$USER_EMAIL" - git tag "$VERSION" "$TRAVIS_COMMIT" -- if [[ “$TRAVIS_OS_NAME” == “osx” ]]; then yarn task package $VERSION; fi deploy: provider: releases file_glob: true diff --git a/build/tasks.ts b/build/tasks.ts index 9e5a4c6da..5af1a0d24 100644 --- a/build/tasks.ts +++ b/build/tasks.ts @@ -21,6 +21,8 @@ const buildServerBinary = register("build:server:binary", async (runner) => { logger.info("Building with environment", field("env", { NODE_ENV: process.env.NODE_ENV, VERSION: process.env.VERSION, + OSTYPE: process.env.OSTYPE, + TARGET: process.env.TARGET, })); await ensureInstalled(); diff --git a/scripts/build.sh b/scripts/build.sh index 2a7fbdb56..edf534088 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -1,32 +1,51 @@ #!/bin/bash set -euxo pipefail -# Variables to be set: -# $IMAGE +# Build using a Docker container using the specified image and version. function docker_build() { - containerID=$(docker create -it -v $(pwd)/.cache:/src/.cache $IMAGE) - docker start $containerID - docker exec $containerID mkdir -p /src + local image="${1}" ; shift + local version="${1}" ; shift - function exec() { - docker exec $containerID bash -c "$@" + local containerId + containerId=$(docker create --network=host --rm -it -v "$(pwd)"/.cache:/src/.cache "${image}") + docker start "${containerId}" + docker exec "${containerId}" mkdir -p /src + + function docker_exec() { + docker exec "${containerId}" bash -c "$@" } - docker cp ./. $containerID:/src - exec "cd /src && yarn" - exec "cd /src && npm rebuild" - exec "cd /src && NODE_ENV=production VERSION=$VERSION yarn task build:server:binary" - exec "cd /src && yarn task package $VERSION" - docker cp $containerID:/src/release/. ./release/ + docker cp ./. "${containerId}":/src + docker_exec "cd /src && yarn" + docker_exec "cd /src && npm rebuild" + docker_exec "cd /src && NODE_ENV=production VERSION=${version} yarn task build:server:binary" + docker_exec "cd /src && yarn task package ${version}" + docker cp "${containerId}":/src/release/. ./release/ + + docker stop "${containerId}" } -if [[ "$OSTYPE" == "darwin"* ]]; then - NODE_ENV=production yarn task build:server:binary -else - if [[ "$TARGET" == "alpine" ]]; then - IMAGE="codercom/nbin-alpine" - else - IMAGE="codercom/nbin-centos" +function main() { + local version=${VERSION:-} + local ostype=${OSTYPE:-} + + if [[ -z "${version}" ]] ; then + >&2 echo "Must set VERSION environment variable" + exit 1 fi - docker_build -fi + + if [[ "${ostype}" == "darwin"* ]]; then + NODE_ENV=production VERSION="${version}" yarn task build:server:binary + yarn task package "${version}" + else + local image + if [[ "$TARGET" == "alpine" ]]; then + image="codercom/nbin-alpine" + else + image="codercom/nbin-centos" + fi + docker_build "${image}" "${version}" + fi +} + +main "$@"