From d89033181735ac29b130d448e7c2cce1f92c4e79 Mon Sep 17 00:00:00 2001 From: Fletcher Nichol Date: Sun, 1 Nov 2015 22:45:55 -0700 Subject: [PATCH] Add `cli/scripts/build_*.sh` scripts to build CLI binaries. --- cli/scripts/build_darwin.sh | 24 ++++++++++++++++++++ cli/scripts/build_docker.sh | 45 +++++++++++++++++++++++++++++++++++++ cli/scripts/build_linux.sh | 30 +++++++++++++++++++++++++ 3 files changed, 99 insertions(+) create mode 100755 cli/scripts/build_darwin.sh create mode 100755 cli/scripts/build_docker.sh create mode 100755 cli/scripts/build_linux.sh diff --git a/cli/scripts/build_darwin.sh b/cli/scripts/build_darwin.sh new file mode 100755 index 0000000..a895f84 --- /dev/null +++ b/cli/scripts/build_darwin.sh @@ -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." diff --git a/cli/scripts/build_docker.sh b/cli/scripts/build_docker.sh new file mode 100755 index 0000000..4f24110 --- /dev/null +++ b/cli/scripts/build_docker.sh @@ -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 +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." diff --git a/cli/scripts/build_linux.sh b/cli/scripts/build_linux.sh new file mode 100755 index 0000000..2d676dc --- /dev/null +++ b/cli/scripts/build_linux.sh @@ -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."