Skip to content

Commit

Permalink
dind: add helper scripts to speed-up development with bind mounts
Browse files Browse the repository at this point in the history
  • Loading branch information
lekkas committed Jul 5, 2016
1 parent 59cf4fd commit 39af247
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 2 deletions.
6 changes: 4 additions & 2 deletions Makefile
Expand Up @@ -16,7 +16,7 @@ ifdef use_proxy_at_runtime
rt_no_proxy=$(no_proxy)
endif

DISABLE_CACHE= 'false'
DISABLE_CACHE = 'false'

ARCH = rpi# rpi/amd64/i386/armv7hf/armel
BASE_DISTRO =
Expand Down Expand Up @@ -70,6 +70,8 @@ else
PRELOADED_IMAGE=
endif

SUPERVISOR_EXTRA_MOUNTS =

clean:
-rm Dockerfile

Expand All @@ -78,7 +80,7 @@ supervisor-dind:

run-supervisor: supervisor-dind stop-supervisor
cd tools/dind \
&& echo "SUPERVISOR_IMAGE=$(SUPERVISOR_IMAGE)\nPRELOADED_IMAGE=$(PRELOADED_IMAGE)" > config/localenv \
&& echo "SUPERVISOR_IMAGE=$(SUPERVISOR_IMAGE)\nPRELOADED_IMAGE=$(PRELOADED_IMAGE)\nSUPERVISOR_EXTRA_MOUNTS=$(SUPERVISOR_EXTRA_MOUNTS)" > config/localenv \
&& docker run -d --name resin_supervisor_1 --privileged ${SUPERVISOR_DIND_MOUNTS} resin/resin-supervisor-dind:$(SUPERVISOR_VERSION)

stop-supervisor:
Expand Down
96 changes: 96 additions & 0 deletions tools/dev/dev_s.sh
@@ -0,0 +1,96 @@
#!/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"}
DEPLOY_REGISTRY=${DEPLOY_REGISTRY:-"registry.resindev.io/"}
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 'bindrun' or 'deploybindrun' action will bind-mount"
echo " './node_modules/' into the running supervisor as well. 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 " DEPLOY_REGISTRY [=registry.resindev.io/]"
echo " PASSWORDLESS_DROPBEAR [=false]"
echo " Actions:"
echo " deploy build supervisor image and deploy it to the registry"
echo " run [options] build dind supervisor host container, run it, then pull supervisor container and run it as well"
echo " deployrun [options] run 'deploy' and 'run'"
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 {
make -C "$SUPERVISOR_BASE_DIR" 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:/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" \
PASSWORDLESS_DROPBEAR="$PASSWORDLESS_DROPBEAR" \
SUPERVISOR_EXTRA_MOUNTS="$SUPERVISOR_EXTRA_MOUNTS" \
SUPERVISOR_IMAGE="registry.resindev.io/resin/${ARCH}-supervisor:master" \
run-supervisor
}

case $1 in
deploy)
deploySupervisor
;;
run)
shift
runDind "$@"
;;
deployrun)
shift
deploySupervisor && runDind "$@"
;;
refresh)
echo " * Compiling CoffeeScript.." \
&& coffee -c "$SUPERVISOR_BASE_DIR/src" \
&& echo " * Restarting supervisor container.." \
&& docker exec -ti resin_supervisor_1 docker restart resin_supervisor
;;
stop)
make -C "$SUPERVISOR_BASE_DIR" stop-supervisor
;;
*)
showHelp
esac

1 change: 1 addition & 0 deletions tools/dind/config/services/resin-supervisor-dind.service
Expand Up @@ -24,6 +24,7 @@ ExecStart=/bin/bash -c 'source /usr/src/app/resin-vars && \
-v /var/log/supervisor-log:/var/log \
-v /:/mnt/root \
-v /etc/resolv.conf:/etc/resolv.conf:rw \
${SUPERVISOR_EXTRA_MOUNTS} \
-e "API_ENDPOINT=$API_ENDPOINT" \
-e "REGISTRY_ENDPOINT=$REGISTRY_ENDPOINT" \
-e "PUBNUB_SUBSCRIBE_KEY=$PUBNUB_SUBSCRIBE_KEY" \
Expand Down

0 comments on commit 39af247

Please sign in to comment.