mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2024-12-30 10:38:55 +00:00
108 lines
3.1 KiB
Bash
Executable File
108 lines
3.1 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
set -o errexit
|
|
set -o pipefail
|
|
|
|
DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
|
|
SUPERVISOR_BASE_DIR="${DIR}/../.."
|
|
|
|
ARCH=${ARCH:-"amd64"}
|
|
SUPERVISOR_IMAGE=${SUPERVISOR_IMAGE:-"registry.resindev.io/resin/${ARCH}-supervisor:master"}
|
|
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
|
|
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"
|
|
echo " to make sure that the correct dependencies are installed."
|
|
echo
|
|
echo " Usage: [environment] $0 action [options]"
|
|
echo
|
|
echo " Environment Variables:"
|
|
echo " ARCH [=amd64]"
|
|
echo " SUPERVISOR_IMAGE [=registry.resindev.io/resin/<ARCH>-supervisor:master]"
|
|
echo " PASSWORDLESS_DROPBEAR [=false]"
|
|
echo " Actions:"
|
|
echo " deploy build and deploy local supervisor image - you can override registry/image name with 'SUPERVISOR_IMAGE'"
|
|
echo " run [options] build dind host container, run it, then pull the configured 'SUPERVISOR_IMAGE' into the dind host and run it"
|
|
echo " deployrun [options] run 'deploy' and then immediately 'run' the deployed container"
|
|
echo " refresh recompile sources in './src' with 'coffee -c' and restart supervisor container on dind host"
|
|
echo " logs [-f] print out supervisor log files - use '-f' to follow instead"
|
|
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 {
|
|
make -C "$SUPERVISOR_BASE_DIR" \
|
|
ARCH="$ARCH" \
|
|
SUPERVISOR_IMAGE="$SUPERVISOR_IMAGE" \
|
|
PASSWORDLESS_DROPBEAR="$PASSWORDLESS_DROPBEAR" \
|
|
deploy
|
|
}
|
|
|
|
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:/usr/src/app/src"
|
|
shift
|
|
;;
|
|
--mount-nm)
|
|
SUPERVISOR_EXTRA_MOUNTS="$SUPERVISOR_EXTRA_MOUNTS -v /resin-supervisor/node_modules:/usr/src/app/node_modules"
|
|
shift
|
|
;;
|
|
*)
|
|
echo "Warning: unknown argument: $arg"
|
|
;;
|
|
esac
|
|
done
|
|
|
|
make -C "$SUPERVISOR_BASE_DIR" \
|
|
ARCH="$ARCH" \
|
|
SUPERVISOR_IMAGE="$SUPERVISOR_IMAGE" \
|
|
PASSWORDLESS_DROPBEAR="$PASSWORDLESS_DROPBEAR" \
|
|
SUPERVISOR_EXTRA_MOUNTS="$SUPERVISOR_EXTRA_MOUNTS" \
|
|
run-supervisor
|
|
}
|
|
|
|
function logs {
|
|
docker exec -ti resin_supervisor_1 journalctl $@
|
|
}
|
|
|
|
action="$1"
|
|
shift || true
|
|
|
|
case $action in
|
|
deploy)
|
|
deploySupervisor
|
|
;;
|
|
run)
|
|
runDind "$@"
|
|
;;
|
|
deployrun)
|
|
deploySupervisor && runDind "$@"
|
|
;;
|
|
refresh)
|
|
make -C "$SUPERVISOR_BASE_DIR" refresh-supervisor-src
|
|
;;
|
|
logs)
|
|
logs "$@"
|
|
;;
|
|
stop)
|
|
make -C "$SUPERVISOR_BASE_DIR" stop-supervisor
|
|
;;
|
|
*)
|
|
showHelp
|
|
esac
|
|
|