mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2025-02-21 02:01:35 +00:00
Merge pull request #192 from resin-io/184-dind-dev-bind-mount
dind: add helper scripts to speed-up development with bind mounts
This commit is contained in:
commit
8cc68e2245
22
Makefile
22
Makefile
@ -1,3 +1,5 @@
|
||||
OS := $(shell uname)
|
||||
|
||||
ifdef http_proxy
|
||||
DOCKER_HTTP_PROXY=--build-arg http_proxy=$(http_proxy)
|
||||
endif
|
||||
@ -16,7 +18,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 =
|
||||
@ -33,6 +35,7 @@ PUBNUB_PUBLISH_KEY = pub-c-bananas
|
||||
MIXPANEL_TOKEN = bananasbananas
|
||||
|
||||
PASSWORDLESS_DROPBEAR = false
|
||||
|
||||
ifdef BASE_DISTRO
|
||||
$(info BASE_DISTRO SPECIFIED. START BUILDING ALPINE SUPERVISOR)
|
||||
IMAGE = "resin/$(ARCH)-supervisor:$(SUPERVISOR_VERSION)-alpine"
|
||||
@ -63,13 +66,18 @@ endif
|
||||
ifeq ($(ARCH),amd64)
|
||||
GOARCH = amd64
|
||||
endif
|
||||
SUPERVISOR_DIND_MOUNTS := -v $$(pwd)/../../:/resin-supervisor -v $$(pwd)/config.json:/mnt/conf/config.json -v $$(pwd)/config/env:/usr/src/app/config/env -v $$(pwd)/config/localenv:/usr/src/app/config/localenv -v /sys/fs/cgroup:/sys/fs/cgroup:ro
|
||||
SUPERVISOR_DIND_MOUNTS := -v $$(pwd)/../../:/resin-supervisor -v $$(pwd)/config.json:/mnt/conf/config.json -v $$(pwd)/config/env:/usr/src/app/config/env -v $$(pwd)/config/localenv:/usr/src/app/config/localenv
|
||||
ifeq ($(OS), Linux)
|
||||
SUPERVISOR_DIND_MOUNTS := ${SUPERVISOR_DIND_MOUNTS} -v /sys/fs/cgroup:/sys/fs/cgroup:ro
|
||||
endif
|
||||
ifdef PRELOADED_IMAGE
|
||||
SUPERVISOR_DIND_MOUNTS := ${SUPERVISOR_DIND_MOUNTS} -v $$(pwd)/apps.json:/usr/src/app/config/apps.json
|
||||
else
|
||||
PRELOADED_IMAGE=
|
||||
endif
|
||||
|
||||
SUPERVISOR_EXTRA_MOUNTS =
|
||||
|
||||
clean:
|
||||
-rm Dockerfile
|
||||
|
||||
@ -78,7 +86,9 @@ 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)" > config/localenv \
|
||||
&& echo "PRELOADED_IMAGE=$(PRELOADED_IMAGE)" >> config/localenv \
|
||||
&& echo "SUPERVISOR_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:
|
||||
@ -88,6 +98,12 @@ stop-supervisor:
|
||||
-docker stop resin_supervisor_1 > /dev/null || true
|
||||
-docker rm -f --volumes resin_supervisor_1 > /dev/null || true
|
||||
|
||||
refresh-supervisor-src:
|
||||
echo " * Compiling CoffeeScript.." \
|
||||
&& coffee -c ./src \
|
||||
&& echo " * Restarting supervisor container.." \
|
||||
&& docker exec -ti resin_supervisor_1 docker restart resin_supervisor
|
||||
|
||||
supervisor: gosuper
|
||||
cp Dockerfile.$(DOCKERFILE) Dockerfile
|
||||
echo "ENV VERSION "`jq -r .version package.json` >> Dockerfile
|
||||
|
120
tools/dev/dindctl
Executable file
120
tools/dev/dindctl
Executable file
@ -0,0 +1,120 @@
|
||||
#!/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=
|
||||
|
||||
SUPERVISOR_LOGS=(
|
||||
'/var/log/supervisor-log/go_supervisor_stdout.log'
|
||||
'/var/log/supervisor-log/resin_supervisor_stdout.log'
|
||||
'/var/log/supervisor-log/supervisor/supervisord.log'
|
||||
)
|
||||
|
||||
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:/app/src"
|
||||
shift
|
||||
;;
|
||||
--mount-nm)
|
||||
SUPERVISOR_EXTRA_MOUNTS="$SUPERVISOR_EXTRA_MOUNTS -v /resin-supervisor/node_modules:/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 {
|
||||
if [ "$1" = "-f" ]; then
|
||||
docker exec -ti resin_supervisor_1 tail -f ${SUPERVISOR_LOGS[@]}
|
||||
else
|
||||
for log in "${SUPERVISOR_LOGS[@]}"; do
|
||||
echo " == ${log} =="
|
||||
docker exec -ti resin_supervisor_1 cat "$log"
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
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
|
||||
|
@ -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" \
|
||||
|
Loading…
x
Reference in New Issue
Block a user