52 lines
1.6 KiB
Bash
Executable File
52 lines
1.6 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
set -eu
|
|
|
|
assertNotEmpty() {
|
|
: "${!1:? "$1 is not set."}"
|
|
}
|
|
|
|
# Only GNU getopt supports long options. OS X comes bundled with the BSD getopt
|
|
# brew install gnu-getopt to get the GNU getopt on OS X
|
|
[[ $(uname -s) == "Darwin" ]] && GNU_GETOPT="/usr/local/opt/gnu-getopt/bin/getopt" || GNU_GETOPT="getopt"
|
|
readonly GNU_GETOPT
|
|
|
|
args=$(${GNU_GETOPT} -o "" -l "revision:" -n "$0" -- "$@")
|
|
eval set -- "${args}"
|
|
|
|
commitish="HEAD"
|
|
|
|
while true; do
|
|
case "$1" in
|
|
--revision) commitish="$2"; shift 2;;
|
|
--) break;;
|
|
*) echo "Unknown option $1"; exit 1;;
|
|
esac
|
|
done
|
|
|
|
readonly SOURCE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")"/.. && pwd)"
|
|
readonly TMPDIR=${TMPDIR:-/tmp} # why is this not set on mint?
|
|
|
|
assertNotEmpty AWS_DEV_ACCESS_KEY
|
|
assertNotEmpty AWS_DEV_SECRET_KEY
|
|
|
|
version=$(cd "${SOURCE_DIR}" && git rev-parse "${commitish}")
|
|
bundle_dir=$(mktemp -d -t box 2>/dev/null || mktemp -d box-XXXXXXXXXX --tmpdir=$TMPDIR)
|
|
bundle_file="${TMPDIR}/box-${version}.tar.gz"
|
|
|
|
chmod "o+rx,g+rx" "${bundle_dir}" # otherwise extracted tarball director won't be readable by others/group
|
|
echo "Checking out code [${version}] into ${bundle_dir}"
|
|
(cd "${SOURCE_DIR}" && git archive --format=tar HEAD | (cd "${bundle_dir}" && tar xf -))
|
|
|
|
echo "Installing modules"
|
|
cd "${bundle_dir}" && npm install --production
|
|
|
|
cd "${bundle_dir}" && tar czvf "${bundle_file}" .
|
|
|
|
echo "Uploading bundle to S3"
|
|
s3cmd --acl-public --access_key="${AWS_DEV_ACCESS_KEY}" --secret_key="${AWS_DEV_SECRET_KEY}" --no-mime-magic put "${bundle_file}" "s3://cloudron-dev-releases/box-${version}.tar.gz"
|
|
|
|
echo "Cleaning up ${bundle_dir}"
|
|
rm -rf "${bundle_dir}" "${bundle_file}"
|
|
|