Add `cli/scripts/build_*.sh` scripts to build CLI binaries.

This commit is contained in:
Fletcher Nichol 2015-11-01 22:45:55 -07:00
parent af0a8a71f5
commit d890331817
3 changed files with 99 additions and 0 deletions

24
cli/scripts/build_darwin.sh Executable file
View File

@ -0,0 +1,24 @@
#!/usr/bin/env bash
set -eu
if [ -n "${DEBUG:-}" ]; then set -x; fi
if [ "`uname`" != "Darwin" ]; then
echo ">>> $0 must be executed on Darwin platform, aborting"
exit 11
fi
VERSION="${1:-${VERSION}}"
echo "--> Building Darwin release artifact version $VERSION"
pushd `dirname $0`/../../
PLATFORM="`uname | tr [[:upper:]] [[:lower:]]`_`uname -m`"
BIN=target/release/names
cd cli
cargo build --verbose --release
strip "$BIN"
ZIPFILE="`pwd`/target/`basename $BIN`_${VERSION}_$PLATFORM.zip"
(cd "`dirname $BIN`"; zip -9 "$ZIPFILE" "`basename $BIN`")
cd `dirname $ZIPFILE`
shasum -a 256 `basename $ZIPFILE` > `basename $ZIPFILE`.sha256
popd
echo "--> Finished build Darwin release artifact version $VERSION."

45
cli/scripts/build_docker.sh Executable file
View File

@ -0,0 +1,45 @@
#!/usr/bin/env bash
set -eu
if [ -n "${DEBUG:-}" ]; then set -x; fi
if ! command -v docker >/dev/null; then
echo ">>> $0 must be executed on a system with Docker installed, aborting"
exit 11
fi
on_exit() {
if [ -d "${docker_context:-}" ]; then
echo "Cleaning up Docker context $docker_context"
rm -rf "$docker_context"
fi
}
trap on_exit 1 2 3 15 ERR
VERSION="${1:-${VERSION}}"
docker_context="`mktemp -d -t build_docker-XXXX`"
repo="fnichol/names"
github_repo="https://github.com/$repo/releases/download"
echo "--> Building Docker release artifact version $VERSION"
pushd "$docker_context"
curl -fsSLO \
"$github_repo/v${VERSION}/names_${VERSION}_linux_x86_64.zip"
curl -fsSLO \
"$github_repo/v${VERSION}/names_${VERSION}_linux_x86_64.zip.sha256"
shasum -a 256 -c names_*.zip.sha256
unzip names_*.zip
rm -f names_*.zip
cat <<_DOCKERFILE_ >Dockerfile
FROM scratch
MAINTAINER Fletcher Nichol <fnichol@nichol.ca>
ADD names /names
ENTRYPOINT ["/names"]
CMD ["--help"]
_DOCKERFILE_
docker build -t "$repo:$VERSION" .
if [ -n "${LATEST:-}" ]; then docker build -t "$repo:latest" .; fi
popd
echo "--> Finished build Docker release artifact version $VERSION."

30
cli/scripts/build_linux.sh Executable file
View File

@ -0,0 +1,30 @@
#!/usr/bin/env bash
set -eu
if [ -n "${DEBUG:-}" ]; then set -x; fi
if ! command -v docker >/dev/null; then
echo ">>> $0 must be executed on a system with Docker installed, aborting"
exit 11
fi
VERSION="${1:-${VERSION}}"
echo "--> Building Linux release artifact version $VERSION"
pushd `dirname $0`/../../
docker run --rm -v `pwd`:/src -e VERSION=$VERSION fnichol/rust:1.4.0-musl \
bash -c 'set -eux
apt-get update
apt-get install -y zip
PLATFORM="`uname | tr [[:upper:]] [[:lower:]]`_`uname -m`"
TARGET=x86_64-unknown-linux-musl
BIN=target/$TARGET/release/names
cd cli
cargo build --verbose --release --target=$TARGET
strip "$BIN"
ZIPFILE="`pwd`/target/`basename $BIN`_${VERSION}_$PLATFORM.zip"
(cd "`dirname $BIN`"; zip -9 "$ZIPFILE" "`basename $BIN`")
cd `dirname $ZIPFILE`
shasum -a 256 `basename $ZIPFILE` > `basename $ZIPFILE`.sha256
'
popd
echo "--> Finished build Linux release artifact version $VERSION."