From 17e7869150bf4c5fe426ed833575f5bcbaaffb3b Mon Sep 17 00:00:00 2001 From: Michael Hobbs Date: Tue, 5 Jan 2016 11:55:07 -0800 Subject: [PATCH] label all dokku containers --- CONTRIBUTING.md | 2 +- docs/development/plugin-creation.md | 1 + docs/development/plugin-triggers.md | 8 ++++---- dokku | 9 ++++++--- plugins/00_dokku-standard/commands | 10 +++++----- plugins/apps/commands | 2 +- plugins/apps/pre-delete | 2 +- plugins/build-env/pre-build-buildpack | 4 ++-- plugins/common/functions | 4 ++-- 9 files changed, 23 insertions(+), 19 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index d9b814f71..799fd84db 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -58,7 +58,7 @@ etc). Please include: * The output of `free -m` * The output of `docker version`. * The output of `docker -D info`. -* The output of `docker run -ti gliderlabs/herokuish:latest herokuish version` +* The output of `docker run --rm -ti gliderlabs/herokuish:latest herokuish version` * The output of `dokku version`. * The output of `dokku plugin`. diff --git a/docs/development/plugin-creation.md b/docs/development/plugin-creation.md index 2791cafc2..96355bee2 100644 --- a/docs/development/plugin-creation.md +++ b/docs/development/plugin-creation.md @@ -90,3 +90,4 @@ A few notes: ``` - From time to time you may want to allow other plugins access to (some of) your plugin's functionality. You can expose this by including a `functions` file in your plugin for others to source. Consider all functions in that file to be publicly accessible by other plugins. Any functions not wished to be made "public" should reside within your plugin trigger or commands files. - As of 0.4.0, we allow image tagging and deployment of said tagged images. Therefore, hard-coding of `$IMAGE` as `dokku/$APP` is no longer sufficient. Instead, for non `pre/post-build-*` plugins, use `get_running_image_tag()` & `get_app_image_name()` as sourced from common/functions. See the [plugin triggers](http://dokku.viewdocs.io/dokku/development/plugin-triggers) doc for examples. +- As of 0.5.0, we will be using container labels to help cleanup intermediate containers with `dokku cleanup`. If calling `docker run`, include `$DOKKU_GLOBAL_RUN_ARGS`. This will ensure you intermediate containers labelled correctly. diff --git a/docs/development/plugin-triggers.md b/docs/development/plugin-triggers.md index 903d65c6e..e3a8d6ed9 100644 --- a/docs/development/plugin-triggers.md +++ b/docs/development/plugin-triggers.md @@ -263,7 +263,7 @@ CMD="cat > gm && \ dpkg -s graphicsmagick > /dev/null 2>&1 || \ (apt-get update && apt-get install -y graphicsmagick && apt-get clean)" -ID=$(docker run -i -a stdin $IMAGE /bin/bash -c "$CMD") +ID=$(docker run $DOKKU_GLOBAL_RUN_ARGS -i -a stdin $IMAGE /bin/bash -c "$CMD") test $(docker wait $ID) -eq 0 docker commit $ID $IMAGE > /dev/null ``` @@ -290,7 +290,7 @@ CMD="cat > gm && \ dpkg -s CONTAINER_PACKAGE > /dev/null 2>&1 || \ (apt-get update && apt-get install -y CONTAINER_PACKAGE && apt-get clean)" -ID=$(docker run -i -a stdin $IMAGE /bin/bash -c "$CMD") +ID=$(docker run $DOKKU_GLOBAL_RUN_ARGS -i -a stdin $IMAGE /bin/bash -c "$CMD") test $(docker wait $ID) -eq 0 docker commit $ID $IMAGE > /dev/null ``` @@ -374,7 +374,7 @@ APP="$1"; IMAGE_TAG="$2"; IMAGE=$(get_app_image_name $APP $IMAGE_TAG) verify_app_name "$APP" dokku_log_info1 "Running gulp" -id=$(docker run -d $IMAGE /bin/bash -c "cd /app && gulp default") +id=$(docker run $DOKKU_GLOBAL_RUN_ARGS -d $IMAGE /bin/bash -c "cd /app && gulp default") test $(docker wait $id) -eq 0 docker commit $id $IMAGE > /dev/null dokku_log_info1 "Building UI Complete" @@ -435,7 +435,7 @@ APP="$1"; GULP_CACHE_DIR="$DOKKU_ROOT/$APP/gulp"; IMAGE=$(get_app_image_name $AP verify_app_name "$APP" if [[ -d $GULP_CACHE_DIR ]]; then - docker run --rm -v "$GULP_CACHE_DIR:/gulp" "$IMAGE" find /gulp -depth -mindepth 1 -maxdepth 1 -exec rm -Rf {} \; || true + docker run $DOKKU_GLOBAL_RUN_ARGS --rm -v "$GULP_CACHE_DIR:/gulp" "$IMAGE" find /gulp -depth -mindepth 1 -maxdepth 1 -exec rm -Rf {} \; || true fi ``` diff --git a/dokku b/dokku index 2df18deee..3001623ce 100755 --- a/dokku +++ b/dokku @@ -29,6 +29,9 @@ export DOKKU_VALID_EXIT=0 export DOKKU_LOGS_DIR=${DOKKU_LOGS_DIR:="/var/log/dokku"} export DOKKU_EVENTS_LOGFILE=${DOKKU_EVENTS_LOGFILE:="$DOKKU_LOGS_DIR/events.log"} +export DOKKU_CONTAINER_LABEL=dokku +export DOKKU_GLOBAL_RUN_ARGS="--label=$DOKKU_CONTAINER_LABEL" + source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" [[ -f $DOKKU_ROOT/dokkurc ]] && source $DOKKU_ROOT/dokkurc @@ -136,11 +139,11 @@ case "$1" in if [[ "$PROC_TYPE" == "web" ]]; then port=${DOKKU_DOCKERFILE_PORT:=5000} if [[ "$BIND_EXTERNAL" = "true" ]]; then - id=$(docker run -d -p $port -e PORT=$port $DOCKER_ARGS $IMAGE $START_CMD) + id=$(docker run $DOKKU_GLOBAL_RUN_ARGS -d -p $port -e PORT=$port $DOCKER_ARGS $IMAGE $START_CMD) port=$(docker port $id $port | sed 's/[0-9.]*://') ipaddr=127.0.0.1 else - id=$(docker run -d -e PORT=$port $DOCKER_ARGS $IMAGE $START_CMD) + id=$(docker run $DOKKU_GLOBAL_RUN_ARGS -d -e PORT=$port $DOCKER_ARGS $IMAGE $START_CMD) ipaddr=$(docker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $id) # Docker < 1.9 compatibility if [[ -z $ipaddr ]]; then @@ -148,7 +151,7 @@ case "$1" in fi fi else - id=$(docker run -d $DOCKER_ARGS $IMAGE $START_CMD) + id=$(docker run $DOKKU_GLOBAL_RUN_ARGS -d $DOCKER_ARGS $IMAGE $START_CMD) fi # if we can't post-deploy successfully, kill new container diff --git a/plugins/00_dokku-standard/commands b/plugins/00_dokku-standard/commands index b8ff20bef..4ffadc3a8 100755 --- a/plugins/00_dokku-standard/commands +++ b/plugins/00_dokku-standard/commands @@ -17,7 +17,7 @@ case "$1" in case "$IMAGE_SOURCE_TYPE" in herokuish) - id=$(tar -c . | docker run -i -a stdin $DOKKU_IMAGE /bin/bash -c "mkdir -p /app && tar -xC /app") + id=$(tar -c . | docker run $DOKKU_GLOBAL_RUN_ARGS -i -a stdin $DOKKU_IMAGE /bin/bash -c "mkdir -p /app && tar -xC /app") test "$(docker wait $id)" -eq 0 docker commit $id $IMAGE > /dev/null [[ -d $CACHE_DIR ]] || mkdir $CACHE_DIR @@ -25,7 +25,7 @@ case "$1" in DOCKER_ARGS=$(: | plugn trigger docker-args-build $APP $IMAGE_SOURCE_TYPE) [[ "$DOKKU_TRACE" ]] && DOCKER_ARGS+=" -e TRACE=true " - id=$(docker run -d -v $CACHE_DIR:/cache -e CACHE_PATH=/cache $DOCKER_ARGS $IMAGE /build) + id=$(docker run $DOKKU_GLOBAL_RUN_ARGS -d -v $CACHE_DIR:/cache -e CACHE_PATH=/cache $DOCKER_ARGS $IMAGE /build) docker attach $id test "$(docker wait $id)" -eq 0 docker commit $id $IMAGE > /dev/null @@ -60,12 +60,12 @@ case "$1" in herokuish) plugn trigger pre-release-buildpack "$APP" "$IMAGE_TAG" if [[ -n $(config_export global) ]]; then - id=$(config_export global | docker run -i -a stdin $IMAGE /bin/bash -c "mkdir -p /app/.profile.d && cat > /app/.profile.d/00-global-env.sh") + id=$(config_export global | docker run $DOKKU_GLOBAL_RUN_ARGS -i -a stdin $IMAGE /bin/bash -c "mkdir -p /app/.profile.d && cat > /app/.profile.d/00-global-env.sh") test "$(docker wait $id)" -eq 0 docker commit $id $IMAGE > /dev/null fi if [[ -n $(config_export app $APP) ]]; then - id=$(config_export app $APP | docker run -i -a stdin $IMAGE /bin/bash -c "mkdir -p /app/.profile.d && cat > /app/.profile.d/01-app-env.sh") + id=$(config_export app $APP | docker run $DOKKU_GLOBAL_RUN_ARGS -i -a stdin $IMAGE /bin/bash -c "mkdir -p /app/.profile.d && cat > /app/.profile.d/01-app-env.sh") test "$(docker wait $id)" -eq 0 docker commit $id $IMAGE > /dev/null fi @@ -144,7 +144,7 @@ case "$1" in has_tty && DOKKU_RUN_OPTS+=" -i -t" is_image_herokuish_based "$IMAGE" && EXEC_CMD="/exec" - docker run $DOKKU_RUN_OPTS $DOCKER_ARGS $IMAGE $EXEC_CMD "$@" + docker run $DOKKU_GLOBAL_RUN_ARGS $DOKKU_RUN_OPTS $DOCKER_ARGS $IMAGE $EXEC_CMD "$@" ;; url | urls) diff --git a/plugins/apps/commands b/plugins/apps/commands index 12f7ed9b0..4f9d612d7 100755 --- a/plugins/apps/commands +++ b/plugins/apps/commands @@ -23,7 +23,7 @@ case "$1" in NEW_APP="$3" mkdir -p "$DOKKU_ROOT/$NEW_APP" - docker run --rm -v "$DOKKU_ROOT/$OLD_APP/cache:/cache" "dokku/$OLD_APP" chmod 777 -R /cache + docker run $DOKKU_GLOBAL_RUN_ARGS --rm -v "$DOKKU_ROOT/$OLD_APP/cache:/cache" "dokku/$OLD_APP" chmod 777 -R /cache rm -rf "$DOKKU_ROOT/$OLD_APP/cache" cp -a "$DOKKU_ROOT/$OLD_APP/." "$DOKKU_ROOT/$NEW_APP" dokku apps:destroy $OLD_APP --force diff --git a/plugins/apps/pre-delete b/plugins/apps/pre-delete index 376baa94b..29fdc5fb3 100755 --- a/plugins/apps/pre-delete +++ b/plugins/apps/pre-delete @@ -6,5 +6,5 @@ APP="$1"; IMAGE_TAG="$2"; IMAGE=$(get_app_image_name $APP $IMAGE_TAG); CACHE_DIR verify_app_name "$APP" if [[ -d $CACHE_DIR ]]; then - docker run --rm -v "$CACHE_DIR:/cache" "$IMAGE" find /cache -depth -mindepth 1 -maxdepth 1 -exec rm -Rf {} \; || true + docker run $DOKKU_GLOBAL_RUN_ARGS --rm -v "$CACHE_DIR:/cache" "$IMAGE" find /cache -depth -mindepth 1 -maxdepth 1 -exec rm -Rf {} \; || true fi diff --git a/plugins/build-env/pre-build-buildpack b/plugins/build-env/pre-build-buildpack index a3966b962..48de40d73 100755 --- a/plugins/build-env/pre-build-buildpack +++ b/plugins/build-env/pre-build-buildpack @@ -24,12 +24,12 @@ if [[ ! -z "$BUILD_ENV" ]]; then dokku_log_info1 "Adding BUILD_ENV to build environment..." # create build env files for use in buildpacks like this: # https://github.com/niteoweb/heroku-buildpack-buildout/blob/5879fa3418f7d8e079f1aa5816ba1adde73f4948/bin/compile#L34 - id=$(echo $BUILD_ENV |sed -e 's@export @@g' -e 's@\\n@ @g' | docker run -i -a stdin $IMAGE /bin/bash -c "for ENV_VAR in $(cat); do echo \$ENV_VAR |sed 's@^\([^=]*\)=\(.*\)\$@echo \\\"\2\\\" >/tmp/env/\1@g' >>/tmp/set_env.sh; done && mkdir -p /tmp/env && /bin/bash /tmp/set_env.sh") + id=$(echo $BUILD_ENV |sed -e 's@export @@g' -e 's@\\n@ @g' | docker run $DOKKU_GLOBAL_RUN_ARGS -i -a stdin $IMAGE /bin/bash -c "for ENV_VAR in $(cat); do echo \$ENV_VAR |sed 's@^\([^=]*\)=\(.*\)\$@echo \\\"\2\\\" >/tmp/env/\1@g' >>/tmp/set_env.sh; done && mkdir -p /tmp/env && /bin/bash /tmp/set_env.sh") test "$(docker wait $id)" -eq 0 docker commit $id $IMAGE > /dev/null # create build env for 'old style' buildpacks and dokku plugins - id=$(echo -e "$BUILD_ENV" | docker run -i -a stdin $IMAGE /bin/bash -c "cat >> /app/.env") + id=$(echo -e "$BUILD_ENV" | docker run $DOKKU_GLOBAL_RUN_ARGS -i -a stdin $IMAGE /bin/bash -c "cat >> /app/.env") test "$(docker wait $id)" -eq 0 docker commit $id $IMAGE > /dev/null fi diff --git a/plugins/common/functions b/plugins/common/functions index 9f216cfa2..4bb1ea785 100755 --- a/plugins/common/functions +++ b/plugins/common/functions @@ -174,7 +174,7 @@ get_running_image_tag() { is_image_herokuish_based() { # circleci can't support --rm as they run lxc in lxc [[ ! -f "/home/ubuntu/.circlerc" ]] && local DOCKER_ARGS="--rm" - docker run --entrypoint="/bin/sh" $DOCKER_ARGS "$@" -c "test -f /exec" + docker run $DOKKU_GLOBAL_RUN_ARGS --entrypoint="/bin/sh" $DOCKER_ARGS "$@" -c "test -f /exec" } is_number() { @@ -211,7 +211,7 @@ copy_from_image() { verify_app_name $APP if verify_image "$IMAGE"; then - CID=$(docker run -d $IMAGE bash) + CID=$(docker run $DOKKU_GLOBAL_RUN_ARGS -d $IMAGE bash) docker cp "$CID:$SRC_FILE" "$DST_DIR" docker rm -f "$CID" &> /dev/null else