2016-07-05 17:48:14 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
set -o errexit
|
|
|
|
set -o pipefail
|
|
|
|
# set -o xtrace
|
|
|
|
|
|
|
|
DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
|
|
|
|
SUPERVISOR_BASE_DIR="${DIR}/../.."
|
|
|
|
|
|
|
|
ARCH=${ARCH:-"amd64"}
|
2016-07-06 08:47:25 +00:00
|
|
|
SUPERVISOR_IMAGE=${SUPERVISOR_IMAGE:-"registry.resindev.io/resin/${ARCH}-supervisor:master"}
|
2016-07-05 17:48:14 +00:00
|
|
|
PASSWORDLESS_DROPBEAR=${PASSWORDLESS_DROPBEAR:-"false"}
|
|
|
|
SUPERVISOR_EXTRA_MOUNTS=
|
|
|
|
|
|
|
|
function showHelp {
|
|
|
|
echo
|
|
|
|
echo " This script can be used to facilitate supervisor development. Its core feature is allowing"
|
|
|
|
echo " faster development iterations by bind-mounting the local './src' directly into the running"
|
|
|
|
echo " supervisor container."
|
|
|
|
echo
|
2016-07-06 08:47:25 +00:00
|
|
|
echo " Setting the '--mount-nm' flag in either 'run' or 'deployrun' action will bind-mount"
|
|
|
|
echo " './node_modules/' into the running supervisor. In this case, it's up to the developer"
|
2016-07-05 17:48:14 +00:00
|
|
|
echo " to make sure that the correct dependencies are installed."
|
|
|
|
echo
|
|
|
|
echo " Usage: [environment] $0 action [options]"
|
|
|
|
echo
|
|
|
|
echo " Environment Variables:"
|
|
|
|
echo " ARCH [=amd64]"
|
2016-07-06 08:47:25 +00:00
|
|
|
echo " SUPERVISOR_IMAGE [=registry.resindev.io/resin/<ARCH>-supervisor:master]"
|
2016-07-05 17:48:14 +00:00
|
|
|
echo " PASSWORDLESS_DROPBEAR [=false]"
|
|
|
|
echo " Actions:"
|
2016-07-06 08:47:25 +00:00
|
|
|
echo " deploy build and deploy local supervisor image - you can override registry/image name with 'SUPERVISOR_IMAGE'"
|
|
|
|
echo " run [options] build dind supervisor host container, run it, then pull the configured 'SUPERVISOR_IMAGE' and run it"
|
|
|
|
echo " deployrun [options] run 'deploy' and then immediately 'run' the deployed container"
|
2016-07-05 17:48:14 +00:00
|
|
|
echo " refresh recompile sources in './src' with 'coffee -c' and restart supervisor container on dind host"
|
|
|
|
echo " stop stop dind supervisor host container"
|
|
|
|
echo " Options:"
|
|
|
|
echo " --mount-src bind-mount './src/' from local development environment into supervisor container"
|
|
|
|
echo " --mount-nm bind-mount './node_modules/' from local development environment into supervisor container"
|
|
|
|
echo
|
|
|
|
}
|
|
|
|
|
|
|
|
function deploySupervisor {
|
2016-07-05 22:44:03 +00:00
|
|
|
make -C "$SUPERVISOR_BASE_DIR" \
|
|
|
|
ARCH="$ARCH" \
|
2016-07-06 08:47:25 +00:00
|
|
|
SUPERVISOR_IMAGE="$SUPERVISOR_IMAGE" \
|
2016-07-05 22:44:03 +00:00
|
|
|
PASSWORDLESS_DROPBEAR="$PASSWORDLESS_DROPBEAR" \
|
|
|
|
deploy
|
2016-07-05 17:48:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function runDind {
|
|
|
|
for arg in "$@"
|
|
|
|
do
|
|
|
|
case $arg in
|
|
|
|
--mount-src)
|
|
|
|
coffee -c "$SUPERVISOR_BASE_DIR/src"
|
|
|
|
SUPERVISOR_EXTRA_MOUNTS="$SUPERVISOR_EXTRA_MOUNTS -v /resin-supervisor/src:/app/src"
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
--mount-nm)
|
|
|
|
SUPERVISOR_EXTRA_MOUNTS="$SUPERVISOR_EXTRA_MOUNTS -v /resin-supervisor/node_modules:/app/node_modules"
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
make -C "$SUPERVISOR_BASE_DIR" \
|
2016-07-05 22:44:03 +00:00
|
|
|
ARCH="$ARCH" \
|
2016-07-06 08:47:25 +00:00
|
|
|
SUPERVISOR_IMAGE="$SUPERVISOR_IMAGE" \
|
2016-07-05 17:48:14 +00:00
|
|
|
PASSWORDLESS_DROPBEAR="$PASSWORDLESS_DROPBEAR" \
|
|
|
|
SUPERVISOR_EXTRA_MOUNTS="$SUPERVISOR_EXTRA_MOUNTS" \
|
|
|
|
run-supervisor
|
|
|
|
}
|
|
|
|
|
|
|
|
case $1 in
|
|
|
|
deploy)
|
|
|
|
deploySupervisor
|
|
|
|
;;
|
|
|
|
run)
|
|
|
|
shift
|
|
|
|
runDind "$@"
|
|
|
|
;;
|
|
|
|
deployrun)
|
|
|
|
shift
|
|
|
|
deploySupervisor && runDind "$@"
|
|
|
|
;;
|
|
|
|
refresh)
|
2016-07-06 08:47:25 +00:00
|
|
|
make -C "$SUPERVISOR_BASE_DIR" refresh-supervisor
|
2016-07-05 17:48:14 +00:00
|
|
|
;;
|
|
|
|
stop)
|
|
|
|
make -C "$SUPERVISOR_BASE_DIR" stop-supervisor
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
showHelp
|
|
|
|
esac
|
|
|
|
|