From 39af2472338d2a2543e6d8a09723f9f2a2bee642 Mon Sep 17 00:00:00 2001 From: Kostas Lekkas Date: Tue, 5 Jul 2016 20:48:14 +0300 Subject: [PATCH] dind: add helper scripts to speed-up development with bind mounts --- Makefile | 6 +- tools/dev/dev_s.sh | 96 +++++++++++++++++++ .../services/resin-supervisor-dind.service | 1 + 3 files changed, 101 insertions(+), 2 deletions(-) create mode 100755 tools/dev/dev_s.sh diff --git a/Makefile b/Makefile index 3989cfa0d..79a59bd96 100644 --- a/Makefile +++ b/Makefile @@ -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 = @@ -70,6 +70,8 @@ else PRELOADED_IMAGE= endif +SUPERVISOR_EXTRA_MOUNTS = + clean: -rm Dockerfile @@ -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: diff --git a/tools/dev/dev_s.sh b/tools/dev/dev_s.sh new file mode 100755 index 000000000..860e86da3 --- /dev/null +++ b/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 + diff --git a/tools/dind/config/services/resin-supervisor-dind.service b/tools/dind/config/services/resin-supervisor-dind.service index ce742fb17..98e3df579 100644 --- a/tools/dind/config/services/resin-supervisor-dind.service +++ b/tools/dind/config/services/resin-supervisor-dind.service @@ -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" \