2019-02-21 18:55:42 +01:00
|
|
|
#!/bin/bash
|
2019-04-26 15:56:14 +02:00
|
|
|
set -euxo pipefail
|
2019-02-21 18:55:42 +01:00
|
|
|
|
2019-06-06 20:42:10 +02:00
|
|
|
# Build using a Docker container using the specified image and version.
|
2019-04-26 15:56:14 +02:00
|
|
|
function docker_build() {
|
2019-06-06 20:42:10 +02:00
|
|
|
local image="${1}" ; shift
|
|
|
|
local version="${1}" ; shift
|
2019-04-26 15:56:14 +02:00
|
|
|
|
2019-06-06 20:42:10 +02:00
|
|
|
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 "$@"
|
2019-04-26 15:56:14 +02:00
|
|
|
}
|
|
|
|
|
2019-06-06 20:42:10 +02:00
|
|
|
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}"
|
2019-04-26 15:56:14 +02:00
|
|
|
}
|
|
|
|
|
2019-06-06 20:42:10 +02:00
|
|
|
function main() {
|
|
|
|
local version=${VERSION:-}
|
|
|
|
local ostype=${OSTYPE:-}
|
|
|
|
|
|
|
|
if [[ -z "${version}" ]] ; then
|
|
|
|
>&2 echo "Must set VERSION environment variable"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ "${ostype}" == "darwin"* ]]; then
|
|
|
|
NODE_ENV=production VERSION="${version}" yarn task build:server:binary
|
|
|
|
yarn task package "${version}"
|
2019-04-26 15:56:14 +02:00
|
|
|
else
|
2019-06-06 20:42:10 +02:00
|
|
|
local image
|
|
|
|
if [[ "$TARGET" == "alpine" ]]; then
|
|
|
|
image="codercom/nbin-alpine"
|
|
|
|
else
|
|
|
|
image="codercom/nbin-centos"
|
|
|
|
fi
|
|
|
|
docker_build "${image}" "${version}"
|
2019-04-26 15:56:14 +02:00
|
|
|
fi
|
2019-06-06 20:42:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
main "$@"
|