2016-07-05 17:48:14 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
set -o errexit
|
|
|
|
set -o pipefail
|
|
|
|
|
|
|
|
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'"
|
2016-07-06 09:25:48 +00:00
|
|
|
echo " run [options] build dind host container, run it, then pull the configured 'SUPERVISOR_IMAGE' into the dind host and run it"
|
2016-07-06 08:47:25 +00:00
|
|
|
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"
|
2016-07-06 09:25:48 +00:00
|
|
|
echo " logs [-f] print out supervisor log files - use '-f' to follow instead"
|
2016-07-05 17:48:14 +00:00
|
|
|
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"
|
2016-09-26 18:17:12 +00:00
|
|
|
SUPERVISOR_EXTRA_MOUNTS="$SUPERVISOR_EXTRA_MOUNTS -v /resin-supervisor/src:/usr/src/app/src"
|
2016-07-05 17:48:14 +00:00
|
|
|
shift
|
|
|
|
;;
|
|
|
|
--mount-nm)
|
2016-09-26 18:17:12 +00:00
|
|
|
SUPERVISOR_EXTRA_MOUNTS="$SUPERVISOR_EXTRA_MOUNTS -v /resin-supervisor/node_modules:/usr/src/app/node_modules"
|
2016-07-05 17:48:14 +00:00
|
|
|
shift
|
|
|
|
;;
|
|
|
|
*)
|
2016-07-06 09:25:48 +00:00
|
|
|
echo "Warning: unknown argument: $arg"
|
2016-07-05 17:48:14 +00:00
|
|
|
;;
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2016-07-06 09:25:48 +00:00
|
|
|
function logs {
|
2016-09-28 23:43:21 +00:00
|
|
|
docker exec -ti resin_supervisor_1 journalctl $@
|
2016-07-06 09:25:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
action="$1"
|
|
|
|
shift || true
|
|
|
|
|
|
|
|
case $action in
|
2016-07-05 17:48:14 +00:00
|
|
|
deploy)
|
|
|
|
deploySupervisor
|
|
|
|
;;
|
|
|
|
run)
|
|
|
|
runDind "$@"
|
|
|
|
;;
|
|
|
|
deployrun)
|
|
|
|
deploySupervisor && runDind "$@"
|
|
|
|
;;
|
|
|
|
refresh)
|
2016-07-06 09:25:48 +00:00
|
|
|
make -C "$SUPERVISOR_BASE_DIR" refresh-supervisor-src
|
|
|
|
;;
|
|
|
|
logs)
|
|
|
|
logs "$@"
|
2016-07-05 17:48:14 +00:00
|
|
|
;;
|
|
|
|
stop)
|
|
|
|
make -C "$SUPERVISOR_BASE_DIR" stop-supervisor
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
showHelp
|
|
|
|
esac
|
|
|
|
|