From 5d88961b343a8d0f9f34d810c47ccd5cfd984074 Mon Sep 17 00:00:00 2001 From: Pablo Carranza Velez Date: Tue, 10 Oct 2017 10:01:31 -0700 Subject: [PATCH] Allow specifying a container name for the docker-in-docker development supervisor This would allow developers to run several supervisors on the same host, by choosing different container names for each. Change-Type: patch Signed-off-by: Pablo Carranza Velez --- Makefile | 10 ++++++---- dindctl | 13 ++++++++++--- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index 738b79fe..1e3d9ebf 100644 --- a/Makefile +++ b/Makefile @@ -29,6 +29,7 @@ # * PRELOADED_IMAGE: If true, will preload user app image from tools/dev/apps.json and bind mount apps.json into the docker-in-docker supervisor # * SUPERVISOR_EXTRA_MOUNTS: Additional bind mount flags for the docker-in-docker supervisor # * PASSWORDLESS_DROPBEAR: For run-supervisor - start a passwordless ssh daemon in the docker-in-docker supervisor +# * CONTAINER_NAME: For run-supervisor, specify the container name for the docker-in-docker container (default: resin_supervisor_1) # THIS_FILE := $(lastword $(MAKEFILE_LIST)) @@ -76,6 +77,7 @@ IMAGE ?= resin/$(ARCH)-supervisor:master # Default values for run-supervisor SUPERVISOR_IMAGE ?= resin/$(ARCH)-supervisor:master PASSWORDLESS_DROPBEAR ?= false +CONTAINER_NAME ?= resin_supervisor_1 # Bind mounts and variables for the run-supervisor target 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 @@ -150,14 +152,14 @@ run-supervisor: stop-supervisor supervisor-dind if [ -n "$(rt_no_proxy)" ]; then \ echo "no_proxy=$(rt_no_proxy)" >> config/localenv; \ fi \ - && docker run -d --name resin_supervisor_1 --privileged ${SUPERVISOR_DIND_MOUNTS} $(IMAGE) + && docker run -d --name $(CONTAINER_NAME) --privileged ${SUPERVISOR_DIND_MOUNTS} $(IMAGE) stop-supervisor: # Stop docker and remove volumes to prevent us from running out of loopback devices, # as per https://github.com/jpetazzo/dind/issues/19 - -docker exec resin_supervisor_1 bash -c "systemctl stop docker" || true - -docker stop resin_supervisor_1 > /dev/null || true - -docker rm -f --volumes resin_supervisor_1 > /dev/null || true + -docker exec $(CONTAINER_NAME) bash -c "systemctl stop docker" || true + -docker stop $(CONTAINER_NAME) > /dev/null || true + -docker rm -f --volumes $(CONTAINER_NAME) > /dev/null || true supervisor-image: ifneq ($(DOCKER_GE_17_05),true) diff --git a/dindctl b/dindctl index 50fb1136..6385f412 100755 --- a/dindctl +++ b/dindctl @@ -21,6 +21,7 @@ # --arch | -a [arch] architecture of the supervisor to build (default: amd64 ) # --image | -i [image] image name for supervisor image to build/use ( default: resin/$ARCH-supervisor:master ) # --dind-image [image] image name for the dind host container +# --dind-container [name] container name for the dind host container ( default: resin_supervisor_1 ) # --mount-dist bind-mount './dist/' (where webpack stores the built js) from local development environment into supervisor container. # --mount-nm bind-mount './node_modules/' from local development environment into supervisor container. # --preload | -p use tools/dev/apps.json to preload an application image into the dind host. @@ -45,6 +46,7 @@ PASSWORDLESS_DROPBEAR="false" SUPERVISOR_EXTRA_MOUNTS="" DIST_MOUNTED="false" DIND_IMAGE="resin-supervisor-dind" +CONTAINER_NAME="resin_supervisor_1" PRELOADED_IMAGE="" OPTIMIZE="true" @@ -77,6 +79,10 @@ function parseOptions { DIND_IMAGE="$2" shift || { echo "--dind-image provided not specified" && exit 1; } ;; + --dind-container) + CONTAINER_NAME="$2" + shift || { echo "--dind-container provided not specified" && exit 1; } + ;; -a|--arch) ARCH="$2" shift || { echo "--arch provided not specified" && exit 1; } @@ -113,7 +119,7 @@ function buildSupervisorSrc { function refreshSupervisorSrc { buildSupervisorSrc echo "Restarting the supervisor container" - docker exec -ti resin_supervisor_1 docker restart resin_supervisor + docker exec -ti $CONTAINER_NAME docker restart resin_supervisor } function runDind { @@ -136,16 +142,17 @@ function runDind { SUPERVISOR_EXTRA_MOUNTS="$SUPERVISOR_EXTRA_MOUNTS" \ PRELOADED_IMAGE="$PRELOADED_IMAGE" \ IMAGE="$DIND_IMAGE" \ + CONTAINER_NAME="$CONTAINER_NAME" \ run-supervisor } function stopDind { echo "Stopping dind supervisor" - make -C "$SUPERVISOR_BASE_DIR" stop-supervisor + make -C "$SUPERVISOR_BASE_DIR" CONTAINER_NAME="$CONTAINER_NAME" stop-supervisor } function logs { - docker exec -ti resin_supervisor_1 journalctl $@ + docker exec -ti $CONTAINER_NAME journalctl $@ } action="$1"