refactor: add global docker build and run args

This reduces duplication and allows users to rely on global arguments to generate most labels needed.

The 'commit' command cannot have global arguments because the whitespace within the label change breaks string-based interpolation, and shell arrays cannot be exported.
This commit is contained in:
Jose Diaz-Gonzalez
2019-07-19 15:50:55 -04:00
parent 193e40b4c3
commit 6836e56b24
15 changed files with 59 additions and 45 deletions

View File

@@ -165,15 +165,26 @@ Certain systems may require a wrapper function around the `docker` binary for pr
docker run -d $IMAGE /bin/bash -e -c "$COMMAND" docker run -d $IMAGE /bin/bash -e -c "$COMMAND"
``` ```
## Include labels for all temporary containers ## Include labels for all temporary containers and images
> New as of 0.5.0 > New as of 0.5.0
As of 0.5.0, labels are used to help cleanup intermediate containers with `dokku cleanup`. Plugins that create containers should add the correct labels to `run` docker commands. As of 0.5.0, labels are used to help cleanup intermediate containers with `dokku cleanup`. Plugins that create containers and images should add the correct labels to the `build`, `commit`, and `run` docker commands.
Note that where possible, a label `com.dokku.app-name=$APP` - where `$APP` is the name of the app - should also be included. This enables `dokku cleanup APP` to cleanup the specific containers for a given app.
```shell ```shell
# `docker build` example
"$DOCKER_BIN" build "--label=com.dokku.app-name=${APP}" $DOKKU_GLOBAL_BUILD_ARGS ...
# `docker commit` example
# Note that the arguments must be set as a local array
# as arrays cannot be exported in shell
local DOKKU_COMMIT_ARGS=("--change" "LABEL org.label-schema.schema-version=1.0" "--change" "LABEL org.label-schema.vendor=dokku" "--change" "LABEL $DOKKU_CONTAINER_LABEL")
"$DOCKER_BIN" commit --change "LABEL com.dokku.app-name=$APP" "${DOKKU_COMMIT_ARGS[@]}" ...
# `docker run` example # `docker run` example
"$DOCKER_BIN" run "${DOKKU_GLOBAL_RUN_ARGS[@]}" ... "$DOCKER_BIN" run "--label=com.dokku.app-name=${APP}" $DOKKU_GLOBAL_RUN_ARGS ...
``` ```
## Avoid calling the `dokku` binary directly ## Avoid calling the `dokku` binary directly

View File

@@ -899,9 +899,10 @@ CMD="cat > gm && \
dpkg -s CONTAINER_PACKAGE >/dev/null 2>&1 || \ dpkg -s CONTAINER_PACKAGE >/dev/null 2>&1 || \
(apt-get update && apt-get install -y CONTAINER_PACKAGE && apt-get clean)" (apt-get update && apt-get install -y CONTAINER_PACKAGE && apt-get clean)"
ID=$(docker run $DOKKU_GLOBAL_RUN_ARGS -i -a stdin $IMAGE /bin/bash -c "$CMD") CID=$(docker run $DOKKU_GLOBAL_RUN_ARGS -i -a stdin $IMAGE /bin/bash -c "$CMD")
test $(docker wait $ID) -eq 0 test $(docker wait $CID) -eq 0
docker commit $ID $IMAGE >/dev/null DOCKER_COMMIT_LABEL_ARGS=("--change" "LABEL org.label-schema.schema-version=1.0" "--change" "LABEL org.label-schema.vendor=dokku" "--change" "LABEL com.dokku.app-name=$APP")
docker commit "${DOCKER_COMMIT_LABEL_ARGS[@]}" $CID $IMAGE >/dev/null
``` ```
### `post-release-dockerfile` ### `post-release-dockerfile`
@@ -988,7 +989,7 @@ APP="$1"; GULP_CACHE_DIR="$DOKKU_ROOT/$APP/gulp"; IMAGE=$(get_app_image_name $AP
verify_app_name "$APP" verify_app_name "$APP"
if [[ -d $GULP_CACHE_DIR ]]; then if [[ -d $GULP_CACHE_DIR ]]; then
docker run $DOKKU_GLOBAL_RUN_ARGS --rm -v "$GULP_CACHE_DIR:/gulp" "$IMAGE" find /gulp -depth -mindepth 1 -maxdepth 1 -exec rm -Rf {} \; || true docker run "${DOCKER_COMMIT_LABEL_ARGS[@]}" --rm -v "$GULP_CACHE_DIR:/gulp" "$IMAGE" find /gulp -depth -mindepth 1 -maxdepth 1 -exec rm -Rf {} \; || true
fi fi
``` ```
@@ -1009,10 +1010,10 @@ APP="$1"; IMAGE_TAG="$2"; IMAGE=$(get_app_image_name $APP $IMAGE_TAG)
verify_app_name "$APP" verify_app_name "$APP"
dokku_log_info1 "Running gulp" dokku_log_info1 "Running gulp"
id=$(docker run $DOKKU_GLOBAL_RUN_ARGS -d $IMAGE /bin/bash -c "cd /app && gulp default") CID=$(docker run "${DOCKER_COMMIT_LABEL_ARGS[@]}" -d $IMAGE /bin/bash -c "cd /app && gulp default")
test $(docker wait $id) -eq 0 test $(docker wait $CID) -eq 0
docker commit $id $IMAGE >/dev/null DOCKER_COMMIT_LABEL_ARGS=("--change" "LABEL org.label-schema.schema-version=1.0" "--change" "LABEL org.label-schema.vendor=dokku" "--change" "LABEL com.dokku.app-name=$APP")
dokku_log_info1 "Building UI Complete" docker commit "${DOCKER_COMMIT_LABEL_ARGS[@]}" $CID $IMAGE >/dev/null
``` ```
### `pre-disable-vhost` ### `pre-disable-vhost`
@@ -1090,9 +1091,10 @@ CMD="cat > gm && \
dpkg -s graphicsmagick >/dev/null 2>&1 || \ dpkg -s graphicsmagick >/dev/null 2>&1 || \
(apt-get update && apt-get install -y graphicsmagick && apt-get clean)" (apt-get update && apt-get install -y graphicsmagick && apt-get clean)"
ID=$(docker run $DOKKU_GLOBAL_RUN_ARGS -i -a stdin $IMAGE /bin/bash -c "$CMD") CID=$(docker run "${DOCKER_COMMIT_LABEL_ARGS[@]}" -i -a stdin $IMAGE /bin/bash -c "$CMD")
test $(docker wait $ID) -eq 0 DOCKER_COMMIT_LABEL_ARGS=("--change" "LABEL org.label-schema.schema-version=1.0" "--change" "LABEL org.label-schema.vendor=dokku" "--change" "LABEL com.dokku.app-name=$APP")
docker commit $ID $IMAGE >/dev/null test $(docker wait $CID) -eq 0
docker commit "${DOCKER_COMMIT_LABEL_ARGS[@]}" $CID $IMAGE >/dev/null
``` ```
### `pre-release-dockerfile` ### `pre-release-dockerfile`

3
dokku
View File

@@ -61,7 +61,8 @@ export DOKKU_LOGS_DIR=${DOKKU_LOGS_DIR:="/var/log/dokku"}
export DOKKU_EVENTS_LOGFILE=${DOKKU_EVENTS_LOGFILE:="$DOKKU_LOGS_DIR/events.log"} export DOKKU_EVENTS_LOGFILE=${DOKKU_EVENTS_LOGFILE:="$DOKKU_LOGS_DIR/events.log"}
export DOKKU_CONTAINER_LABEL=dokku export DOKKU_CONTAINER_LABEL=dokku
export DOKKU_GLOBAL_RUN_ARGS="--label=$DOKKU_CONTAINER_LABEL" export DOKKU_GLOBAL_BUILD_ARGS="--label=org.label-schema.schema-version=1.0 --label=org.label-schema.vendor=dokku --label=$DOKKU_CONTAINER_LABEL"
export DOKKU_GLOBAL_RUN_ARGS="--label=org.label-schema.schema-version=1.0 --label=org.label-schema.vendor=dokku --label=$DOKKU_CONTAINER_LABEL"
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"

View File

@@ -17,7 +17,7 @@ dokku_report_cmd() {
"$DOCKER_BIN" -D info | sed "s/^/ /" "$DOCKER_BIN" -D info | sed "s/^/ /"
dokku_log_info1 "sigil version: $(sigil -v)" dokku_log_info1 "sigil version: $(sigil -v)"
dokku_log_info1 "herokuish version: " dokku_log_info1 "herokuish version: "
"$DOCKER_BIN" run --rm "$DOKKU_IMAGE" herokuish version | sed "s/^/ /" "$DOCKER_BIN" run $DOKKU_GLOBAL_RUN_ARGS --rm "$DOKKU_IMAGE" herokuish version | sed "s/^/ /"
dokku_log_info1 "dokku version: $(dokku version)" dokku_log_info1 "dokku version: $(dokku version)"
dokku_log_info1 "dokku plugins: " dokku_log_info1 "dokku plugins: "
dokku plugin:list | sed "s/^/ /" dokku plugin:list | sed "s/^/ /"

View File

@@ -37,7 +37,7 @@ execute_script() {
local IMAGE id SCRIPT_CMD local IMAGE id SCRIPT_CMD
local DOCKER_COMMIT_LABEL_ARGS=("--change" "\"LABEL org.label-schema.schema-version=1.0\"" "--change" "\"LABEL org.label-schema.vendor=dokku\"" "--change" "\"LABEL com.dokku.app-name=$APP\"") local DOCKER_COMMIT_LABEL_ARGS=("--change" "\"LABEL org.label-schema.schema-version=1.0\"" "--change" "\"LABEL org.label-schema.vendor=dokku\"" "--change" "\"LABEL com.dokku.app-name=$APP\"")
local DOCKER_RUN_LABEL_ARGS="--label=org.label-schema.schema-version=1.0 --label=org.label-schema.vendor=dokku --label=com.dokku.app-name=$APP" local DOCKER_RUN_LABEL_ARGS="--label=com.dokku.app-name=$APP"
IMAGE=$(get_deploying_app_image_name "$APP" "$IMAGE_TAG") IMAGE=$(get_deploying_app_image_name "$APP" "$IMAGE_TAG")
if [[ "$PHASE_SCRIPT_KEY" == "release" ]]; then if [[ "$PHASE_SCRIPT_KEY" == "release" ]]; then
@@ -99,7 +99,7 @@ execute_script() {
DOKKU_APP_SHELL="$(config_get "$APP" DOKKU_APP_SHELL || echo "$DOKKU_APP_SHELL")" DOKKU_APP_SHELL="$(config_get "$APP" DOKKU_APP_SHELL || echo "$DOKKU_APP_SHELL")"
[[ -z "$DOKKU_APP_SHELL" ]] && DOKKU_APP_SHELL="/bin/bash" [[ -z "$DOKKU_APP_SHELL" ]] && DOKKU_APP_SHELL="/bin/bash"
id=$("$DOCKER_BIN" run "${DOCKER_RUN_LABEL_ARGS[@]}" "${DOKKU_GLOBAL_RUN_ARGS[@]}" -e DOKKU_TRACE="$DOKKU_TRACE" --label=dokku_phase_script="${PHASE_SCRIPT_KEY}" -d -v "$CACHE_HOST_DIR:/cache" "${ARG_ARRAY[@]}" "$IMAGE" "$DOKKU_APP_SHELL" -c "$COMMAND") id=$("$DOCKER_BIN" run "${DOCKER_RUN_LABEL_ARGS[@]}" $DOKKU_GLOBAL_RUN_ARGS -e DOKKU_TRACE="$DOKKU_TRACE" --label=dokku_phase_script="${PHASE_SCRIPT_KEY}" -d -v "$CACHE_HOST_DIR:/cache" "${ARG_ARRAY[@]}" "$IMAGE" "$DOKKU_APP_SHELL" -c "$COMMAND")
if test "$("$DOCKER_BIN" wait "$id")" -ne 0; then if test "$("$DOCKER_BIN" wait "$id")" -ne 0; then
dokku_container_log_verbose_quiet "$id" dokku_container_log_verbose_quiet "$id"
dokku_log_fail "execution of '$SCRIPT_CMD' failed!" dokku_log_fail "execution of '$SCRIPT_CMD' failed!"

View File

@@ -22,7 +22,7 @@ apps_clone_cmd() {
OLD_APP="$1" NEW_APP="$2" OLD_APP="$1" NEW_APP="$2"
[[ -z "$OLD_APP" ]] && dokku_log_fail "Please specify an app to run the command on" [[ -z "$OLD_APP" ]] && dokku_log_fail "Please specify an app to run the command on"
local DOCKER_RUN_LABEL_ARGS="--label=org.label-schema.schema-version=1.0 --label=org.label-schema.vendor=dokku --label=com.dokku.app-name=$NEW_APP" local DOCKER_RUN_LABEL_ARGS="--label=com.dokku.app-name=$NEW_APP"
is_valid_app_name "$OLD_APP" is_valid_app_name "$OLD_APP"
is_valid_app_name "$NEW_APP" is_valid_app_name "$NEW_APP"
@@ -46,7 +46,7 @@ apps_clone_cmd() {
plugn trigger post-app-clone-setup "$OLD_APP" "$NEW_APP" plugn trigger post-app-clone-setup "$OLD_APP" "$NEW_APP"
if [[ -d "$NEW_CACHE_DIR" ]] && ! rmdir "$NEW_CACHE_DIR"; then if [[ -d "$NEW_CACHE_DIR" ]] && ! rmdir "$NEW_CACHE_DIR"; then
"$DOCKER_BIN" run "${DOCKER_RUN_LABEL_ARGS[@]}" "${DOKKU_GLOBAL_RUN_ARGS[@]}" --rm -v "$NEW_CACHE_HOST_DIR:/cache" "dokku/$OLD_APP" chmod 777 -R /cache "$DOCKER_BIN" run "${DOCKER_RUN_LABEL_ARGS[@]}" $DOKKU_GLOBAL_RUN_ARGS --rm -v "$NEW_CACHE_HOST_DIR:/cache" "dokku/$OLD_APP" chmod 777 -R /cache
fi fi
rm -rf "$NEW_CACHE_DIR" rm -rf "$NEW_CACHE_DIR"

View File

@@ -15,10 +15,10 @@ apps_rename_cmd() {
local OLD_CACHE_DIR="$DOKKU_ROOT/$OLD_APP/cache" local OLD_CACHE_DIR="$DOKKU_ROOT/$OLD_APP/cache"
local OLD_CACHE_HOST_DIR="$DOKKU_HOST_ROOT/$OLD_APP/cache" local OLD_CACHE_HOST_DIR="$DOKKU_HOST_ROOT/$OLD_APP/cache"
local DOCKER_RUN_LABEL_ARGS="--label=org.label-schema.schema-version=1.0 --label=org.label-schema.vendor=dokku --label=com.dokku.app-name=$OLD_APP" local DOCKER_RUN_LABEL_ARGS="--label=com.dokku.app-name=$OLD_APP"
if [[ -d "$OLD_CACHE_DIR" ]] && ! rmdir "$OLD_CACHE_DIR" >/dev/null 2>&1; then if [[ -d "$OLD_CACHE_DIR" ]] && ! rmdir "$OLD_CACHE_DIR" >/dev/null 2>&1; then
"$DOCKER_BIN" run "${DOCKER_RUN_LABEL_ARGS[@]}" "${DOKKU_GLOBAL_RUN_ARGS[@]}" --rm -v "$OLD_CACHE_HOST_DIR:/cache" "dokku/$OLD_APP" chmod 777 -R /cache "$DOCKER_BIN" run "${DOCKER_RUN_LABEL_ARGS[@]}" $DOKKU_GLOBAL_RUN_ARGS --rm -v "$OLD_CACHE_HOST_DIR:/cache" "dokku/$OLD_APP" chmod 777 -R /cache
fi fi
rm -rf "$OLD_CACHE_DIR" rm -rf "$OLD_CACHE_DIR"
apps_create "$NEW_APP" apps_create "$NEW_APP"

View File

@@ -11,7 +11,7 @@ build_env_pre_build_buildpack() {
local IMAGE id local IMAGE id
local DOCKER_COMMIT_LABEL_ARGS=("--change" "LABEL org.label-schema.schema-version=1.0" "--change" "LABEL org.label-schema.vendor=dokku" "--change" "LABEL com.dokku.app-name=$APP") local DOCKER_COMMIT_LABEL_ARGS=("--change" "LABEL org.label-schema.schema-version=1.0" "--change" "LABEL org.label-schema.vendor=dokku" "--change" "LABEL com.dokku.app-name=$APP")
local DOCKER_RUN_LABEL_ARGS="--label=org.label-schema.schema-version=1.0 --label=org.label-schema.vendor=dokku --label=com.dokku.app-name=$APP" local DOCKER_RUN_LABEL_ARGS="--label=com.dokku.app-name=$APP"
verify_app_name "$APP" verify_app_name "$APP"
IMAGE=$(get_app_image_name "$APP") IMAGE=$(get_app_image_name "$APP")
@@ -22,13 +22,13 @@ build_env_pre_build_buildpack() {
dokku_log_info1 "Adding BUILD_ENV to build environment..." dokku_log_info1 "Adding BUILD_ENV to build environment..."
# create build env files for use in buildpacks like this: # create build env files for use in buildpacks like this:
# https://github.com/niteoweb/heroku-buildpack-buildout/blob/5879fa3418f7d8e079f1aa5816ba1adde73f4948/bin/compile#L34 # https://github.com/niteoweb/heroku-buildpack-buildout/blob/5879fa3418f7d8e079f1aa5816ba1adde73f4948/bin/compile#L34
id=$(config_bundle --merged "$APP" | "$DOCKER_BIN" run "${DOCKER_RUN_LABEL_ARGS[@]}" "${DOKKU_GLOBAL_RUN_ARGS[@]}" -i -a stdin "$IMAGE" /bin/bash -c "mkdir -p /tmp/env; cat | tar -x -C /tmp/env") id=$(config_bundle --merged "$APP" | "$DOCKER_BIN" run "${DOCKER_RUN_LABEL_ARGS[@]}" $DOKKU_GLOBAL_RUN_ARGS -i -a stdin "$IMAGE" /bin/bash -c "mkdir -p /tmp/env; cat | tar -x -C /tmp/env")
test "$("$DOCKER_BIN" wait "$id")" -eq 0 test "$("$DOCKER_BIN" wait "$id")" -eq 0
"$DOCKER_BIN" commit "${DOCKER_COMMIT_LABEL_ARGS[@]}" "$id" "$IMAGE" >/dev/null "$DOCKER_BIN" commit "${DOCKER_COMMIT_LABEL_ARGS[@]}" "$id" "$IMAGE" >/dev/null
# create build env for 'old style' buildpacks and dokku plugins # create build env for 'old style' buildpacks and dokku plugins
id=$(config_export app "$APP" --format envfile --merged | "$DOCKER_BIN" run "${DOCKER_RUN_LABEL_ARGS[@]}" "${DOKKU_GLOBAL_RUN_ARGS[@]}" -i -a stdin "$IMAGE" /bin/bash -c "cat >> /app/.env") id=$(config_export app "$APP" --format envfile --merged | "$DOCKER_BIN" run "${DOCKER_RUN_LABEL_ARGS[@]}" $DOKKU_GLOBAL_RUN_ARGS -i -a stdin "$IMAGE" /bin/bash -c "cat >> /app/.env")
test "$("$DOCKER_BIN" wait "$id")" -eq 0 test "$("$DOCKER_BIN" wait "$id")" -eq 0
"$DOCKER_BIN" commit "${DOCKER_COMMIT_LABEL_ARGS[@]}" "$id" "$IMAGE" >/dev/null "$DOCKER_BIN" commit "${DOCKER_COMMIT_LABEL_ARGS[@]}" "$id" "$IMAGE" >/dev/null

View File

@@ -375,7 +375,7 @@ copy_from_image() {
local WORK_DIR="" local WORK_DIR=""
verify_app_name "$APP" verify_app_name "$APP"
local DOCKER_CREATE_LABEL_ARGS="--label=org.label-schema.schema-version=1.0 --label=org.label-schema.vendor=dokku --label=com.dokku.app-name=$APP" local DOCKER_CREATE_LABEL_ARGS="--label=com.dokku.app-name=$APP"
if verify_image "$IMAGE"; then if verify_image "$IMAGE"; then
if ! is_abs_path "$SRC_FILE"; then if ! is_abs_path "$SRC_FILE"; then
@@ -389,7 +389,7 @@ copy_from_image() {
SRC_FILE="${WORKDIR}/${SRC_FILE}" SRC_FILE="${WORKDIR}/${SRC_FILE}"
fi fi
fi fi
local CID=$("$DOCKER_BIN" create "${DOCKER_CREATE_LABEL_ARGS[@]}" "${DOKKU_GLOBAL_RUN_ARGS[@]}" "$IMAGE") local CID=$("$DOCKER_BIN" create "${DOCKER_CREATE_LABEL_ARGS[@]}" $DOKKU_GLOBAL_RUN_ARGS "$IMAGE")
if ! "$DOCKER_BIN" cp "$CID:$SRC_FILE" "$DST_DIR"; then if ! "$DOCKER_BIN" cp "$CID:$SRC_FILE" "$DST_DIR"; then
"$DOCKER_BIN" rm -f "$CID" &>/dev/null "$DOCKER_BIN" rm -f "$CID" &>/dev/null
return 1 return 1
@@ -528,7 +528,7 @@ dokku_build() {
local DOCKER_COMMIT_LABEL_ARGS=("--change" "LABEL org.label-schema.schema-version=1.0" "--change" "LABEL org.label-schema.vendor=dokku" "--change" "LABEL com.dokku.app-name=$APP") local DOCKER_COMMIT_LABEL_ARGS=("--change" "LABEL org.label-schema.schema-version=1.0" "--change" "LABEL org.label-schema.vendor=dokku" "--change" "LABEL com.dokku.app-name=$APP")
local DOCKER_BUILD_LABEL_ARGS="--label=org.label-schema.schema-version=1.0 --label=org.label-schema.vendor=dokku --label=com.dokku.app-name=$APP" local DOCKER_BUILD_LABEL_ARGS="--label=org.label-schema.schema-version=1.0 --label=org.label-schema.vendor=dokku --label=com.dokku.app-name=$APP"
local DOCKER_RUN_LABEL_ARGS="--label=org.label-schema.schema-version=1.0 --label=org.label-schema.vendor=dokku --label=com.dokku.app-name=$APP" local DOCKER_RUN_LABEL_ARGS="--label=com.dokku.app-name=$APP"
eval "$(config_export app "$APP")" eval "$(config_export app "$APP")"
pushd "$TMP_WORK_DIR" &>/dev/null pushd "$TMP_WORK_DIR" &>/dev/null
@@ -536,7 +536,7 @@ dokku_build() {
case "$IMAGE_SOURCE_TYPE" in case "$IMAGE_SOURCE_TYPE" in
herokuish) herokuish)
DOKKU_IMAGE="$(config_get "$APP" DOKKU_IMAGE || echo "$DOKKU_IMAGE")" DOKKU_IMAGE="$(config_get "$APP" DOKKU_IMAGE || echo "$DOKKU_IMAGE")"
cid=$(tar -c . | "$DOCKER_BIN" run "${DOCKER_RUN_LABEL_ARGS[@]}" "${DOKKU_GLOBAL_RUN_ARGS[@]}" -i -a stdin "$DOKKU_IMAGE" /bin/bash -c "mkdir -p /app && tar -xC /app") cid=$(tar -c . | "$DOCKER_BIN" run "${DOCKER_RUN_LABEL_ARGS[@]}" $DOKKU_GLOBAL_RUN_ARGS -i -a stdin "$DOKKU_IMAGE" /bin/bash -c "mkdir -p /app && tar -xC /app")
test "$("$DOCKER_BIN" wait "$cid")" -eq 0 test "$("$DOCKER_BIN" wait "$cid")" -eq 0
"$DOCKER_BIN" commit "${DOCKER_COMMIT_LABEL_ARGS[@]}" "$cid" "$IMAGE" >/dev/null "$DOCKER_BIN" commit "${DOCKER_COMMIT_LABEL_ARGS[@]}" "$cid" "$IMAGE" >/dev/null
@@ -551,7 +551,7 @@ dokku_build() {
declare -a ARG_ARRAY declare -a ARG_ARRAY
eval "ARG_ARRAY=($DOCKER_ARGS)" eval "ARG_ARRAY=($DOCKER_ARGS)"
# shellcheck disable=SC2086 # shellcheck disable=SC2086
cid=$("$DOCKER_BIN" run "${DOCKER_RUN_LABEL_ARGS[@]}" "${DOKKU_GLOBAL_RUN_ARGS[@]}" -d -v $DOKKU_APP_HOST_CACHE_DIR:/cache -e CACHE_PATH=/cache "${ARG_ARRAY[@]}" $IMAGE /build) cid=$("$DOCKER_BIN" run "${DOCKER_RUN_LABEL_ARGS[@]}" $DOKKU_GLOBAL_RUN_ARGS -d -v $DOKKU_APP_HOST_CACHE_DIR:/cache -e CACHE_PATH=/cache "${ARG_ARRAY[@]}" $IMAGE /build)
"$DOCKER_BIN" attach "$cid" "$DOCKER_BIN" attach "$cid"
test "$("$DOCKER_BIN" wait "$cid")" -eq 0 test "$("$DOCKER_BIN" wait "$cid")" -eq 0
@@ -582,7 +582,7 @@ dokku_build() {
declare -a ARG_ARRAY declare -a ARG_ARRAY
eval "ARG_ARRAY=($DOCKER_ARGS)" eval "ARG_ARRAY=($DOCKER_ARGS)"
"$DOCKER_BIN" build "${DOCKER_BUILD_LABEL_ARGS[@]}" "${ARG_ARRAY[@]}" "${DOKKU_DOCKER_BUILD_OPTS[@]}" -t $IMAGE . "$DOCKER_BIN" build "${DOCKER_BUILD_LABEL_ARGS[@]}" $DOKKU_GLOBAL_BUILD_ARGS "${ARG_ARRAY[@]}" "${DOKKU_DOCKER_BUILD_OPTS[@]}" -t $IMAGE .
plugn trigger post-build-dockerfile "$APP" plugn trigger post-build-dockerfile "$APP"
;; ;;
@@ -601,19 +601,19 @@ dokku_release() {
local cid IMAGE=$(get_app_image_name "$APP" "$IMAGE_TAG") local cid IMAGE=$(get_app_image_name "$APP" "$IMAGE_TAG")
local DOCKER_COMMIT_LABEL_ARGS=("--change" "LABEL org.label-schema.schema-version=1.0" "--change" "LABEL org.label-schema.vendor=dokku" "--change" "LABEL com.dokku.app-name=$APP") local DOCKER_COMMIT_LABEL_ARGS=("--change" "LABEL org.label-schema.schema-version=1.0" "--change" "LABEL org.label-schema.vendor=dokku" "--change" "LABEL com.dokku.app-name=$APP")
local DOCKER_RUN_LABEL_ARGS="--label=org.label-schema.schema-version=1.0 --label=org.label-schema.vendor=dokku --label=com.dokku.app-name=$APP" local DOCKER_RUN_LABEL_ARGS="--label=com.dokku.app-name=$APP"
case "$IMAGE_SOURCE_TYPE" in case "$IMAGE_SOURCE_TYPE" in
herokuish) herokuish)
plugn trigger pre-release-buildpack "$APP" "$IMAGE_TAG" plugn trigger pre-release-buildpack "$APP" "$IMAGE_TAG"
if [[ -n $(config_export global) ]]; then if [[ -n $(config_export global) ]]; then
cid=$(config_export global | "$DOCKER_BIN" run "${DOCKER_RUN_LABEL_ARGS[@]}" "${DOKKU_GLOBAL_RUN_ARGS[@]}" -i -a stdin "$IMAGE" /bin/bash -c "mkdir -p /app/.profile.d && cat > /app/.profile.d/00-global-env.sh") cid=$(config_export global | "$DOCKER_BIN" run "${DOCKER_RUN_LABEL_ARGS[@]}" $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_BIN" wait "$cid")" -eq 0 test "$("$DOCKER_BIN" wait "$cid")" -eq 0
"$DOCKER_BIN" commit "${DOCKER_COMMIT_LABEL_ARGS[@]}" "$cid" "$IMAGE" >/dev/null "$DOCKER_BIN" commit "${DOCKER_COMMIT_LABEL_ARGS[@]}" "$cid" "$IMAGE" >/dev/null
fi fi
if [[ -n $(config_export app "$APP") ]]; then if [[ -n $(config_export app "$APP") ]]; then
cid=$(config_export app "$APP" | "$DOCKER_BIN" run "${DOCKER_RUN_LABEL_ARGS[@]}" "${DOKKU_GLOBAL_RUN_ARGS[@]}" -i -a stdin "$IMAGE" /bin/bash -c "mkdir -p /app/.profile.d && cat > /app/.profile.d/01-app-env.sh") cid=$(config_export app "$APP" | "$DOCKER_BIN" run "${DOCKER_RUN_LABEL_ARGS[@]}" $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_BIN" wait "$cid")" -eq 0 test "$("$DOCKER_BIN" wait "$cid")" -eq 0
"$DOCKER_BIN" commit "${DOCKER_COMMIT_LABEL_ARGS[@]}" "$cid" "$IMAGE" >/dev/null "$DOCKER_BIN" commit "${DOCKER_COMMIT_LABEL_ARGS[@]}" "$cid" "$IMAGE" >/dev/null

View File

@@ -21,7 +21,7 @@ func PurgeCache(appName string) error {
dokkuGlobalRunArgs := common.MustGetEnv("DOKKU_GLOBAL_RUN_ARGS") dokkuGlobalRunArgs := common.MustGetEnv("DOKKU_GLOBAL_RUN_ARGS")
image := config.GetWithDefault(appName, "DOKKU_IMAGE", os.Getenv("DOKKU_IMAGE")) image := config.GetWithDefault(appName, "DOKKU_IMAGE", os.Getenv("DOKKU_IMAGE"))
if info, _ := os.Stat(cacheDir); info != nil && info.IsDir() { if info, _ := os.Stat(cacheDir); info != nil && info.IsDir() {
dockerLabelArgs := fmt.Sprintf("--label=org.label-schema.schema-version=1.0 --label=org.label-schema.vendor=dokku --label=com.dokku.app-name=%s", appName) dockerLabelArgs := fmt.Sprintf("--label=com.dokku.app-name=%s", appName)
purgeCacheCmd := common.NewShellCmd(strings.Join([]string{ purgeCacheCmd := common.NewShellCmd(strings.Join([]string{
common.DockerBin(), common.DockerBin(),
"run --rm", dockerLabelArgs, dokkuGlobalRunArgs, "run --rm", dockerLabelArgs, dokkuGlobalRunArgs,

View File

@@ -17,7 +17,7 @@ scheduler-docker-local-pre-deploy() {
return return
fi fi
local DOCKER_RUN_LABEL_ARGS="--label=org.label-schema.schema-version=1.0 --label=org.label-schema.vendor=dokku --label=com.dokku.app-name=$APP" local DOCKER_RUN_LABEL_ARGS="--label=com.dokku.app-name=$APP"
IMAGE=$(get_app_image_name "$APP" "$IMAGE_TAG") IMAGE=$(get_app_image_name "$APP" "$IMAGE_TAG")
@@ -44,7 +44,7 @@ scheduler-docker-local-pre-deploy() {
fi fi
# shellcheck disable=SC2086 # shellcheck disable=SC2086
"$DOCKER_BIN" run "${DOCKER_RUN_LABEL_ARGS[@]}" "${DOKKU_GLOBAL_RUN_ARGS[@]}" "${ARG_ARRAY[@]}" $IMAGE /bin/bash -c "find $CONTAINER_PATHS -not -user $DOKKU_APP_USER -print0 | xargs -0 -r chown -R $DOKKU_APP_USER" || true "$DOCKER_BIN" run "${DOCKER_RUN_LABEL_ARGS[@]}" $DOKKU_GLOBAL_RUN_ARGS "${ARG_ARRAY[@]}" $IMAGE /bin/bash -c "find $CONTAINER_PATHS -not -user $DOKKU_APP_USER -print0 | xargs -0 -r chown -R $DOKKU_APP_USER" || true
} }
scheduler-docker-local-pre-deploy "$@" scheduler-docker-local-pre-deploy "$@"

View File

@@ -18,7 +18,7 @@ scheduler-docker-local-scheduler-deploy() {
rm -f "${DOKKU_LIB_ROOT}/data/scheduler-docker-local/$APP/failed-containers" rm -f "${DOKKU_LIB_ROOT}/data/scheduler-docker-local/$APP/failed-containers"
local DOCKER_RUN_LABEL_ARGS="--label=org.label-schema.schema-version=1.0 --label=org.label-schema.vendor=dokku --label=com.dokku.app-name=$APP" local DOCKER_RUN_LABEL_ARGS="--label=com.dokku.app-name=$APP"
local DOKKU_DOCKER_STOP_TIMEOUT DOKKU_HEROKUISH DOKKU_NETWORK_BIND_ALL IMAGE local DOKKU_DOCKER_STOP_TIMEOUT DOKKU_HEROKUISH DOKKU_NETWORK_BIND_ALL IMAGE
DOKKU_HEROKUISH=false DOKKU_HEROKUISH=false
IMAGE=$(get_deploying_app_image_name "$APP" "$IMAGE_TAG") IMAGE=$(get_deploying_app_image_name "$APP" "$IMAGE_TAG")
@@ -95,16 +95,16 @@ scheduler-docker-local-scheduler-deploy() {
START_CMD=$(fn-scheduler-docker-local-extract-start-cmd "$APP" "$PROC_TYPE" "$START_CMD" "$DOKKU_HEROKUISH" "$DOKKU_PORT") START_CMD=$(fn-scheduler-docker-local-extract-start-cmd "$APP" "$PROC_TYPE" "$START_CMD" "$DOKKU_HEROKUISH" "$DOKKU_PORT")
if [[ "$DOKKU_NETWORK_BIND_ALL" == "false" ]]; then if [[ "$DOKKU_NETWORK_BIND_ALL" == "false" ]]; then
# shellcheck disable=SC2086 # shellcheck disable=SC2086
cid=$("$DOCKER_BIN" run "${DOCKER_RUN_LABEL_ARGS[@]}" "${DOKKU_GLOBAL_RUN_ARGS[@]}" -d -e PORT=$DOKKU_PORT "${ARG_ARRAY[@]}" $IMAGE $START_CMD) cid=$("$DOCKER_BIN" run "${DOCKER_RUN_LABEL_ARGS[@]}" $DOKKU_GLOBAL_RUN_ARGS -d -e PORT=$DOKKU_PORT "${ARG_ARRAY[@]}" $IMAGE $START_CMD)
else else
# shellcheck disable=SC2086 # shellcheck disable=SC2086
cid=$("$DOCKER_BIN" run "${DOCKER_RUN_LABEL_ARGS[@]}" "${DOKKU_GLOBAL_RUN_ARGS[@]}" -d $DOKKU_DOCKER_PORT_ARGS -e PORT=$DOKKU_PORT "${ARG_ARRAY[@]}" $IMAGE $START_CMD) cid=$("$DOCKER_BIN" run "${DOCKER_RUN_LABEL_ARGS[@]}" $DOKKU_GLOBAL_RUN_ARGS -d $DOKKU_DOCKER_PORT_ARGS -e PORT=$DOKKU_PORT "${ARG_ARRAY[@]}" $IMAGE $START_CMD)
fi fi
else else
START_CMD=$(fn-scheduler-docker-local-extract-start-cmd "$APP" "$PROC_TYPE" "$START_CMD" "$DOKKU_HEROKUISH") START_CMD=$(fn-scheduler-docker-local-extract-start-cmd "$APP" "$PROC_TYPE" "$START_CMD" "$DOKKU_HEROKUISH")
# shellcheck disable=SC2086 # shellcheck disable=SC2086
cid=$("$DOCKER_BIN" run "${DOCKER_RUN_LABEL_ARGS[@]}" "${DOKKU_GLOBAL_RUN_ARGS[@]}" -d "${ARG_ARRAY[@]}" $IMAGE $START_CMD) cid=$("$DOCKER_BIN" run "${DOCKER_RUN_LABEL_ARGS[@]}" $DOKKU_GLOBAL_RUN_ARGS -d "${ARG_ARRAY[@]}" $IMAGE $START_CMD)
fi fi
ipaddr=$(plugn trigger network-get-ipaddr "$APP" "$PROC_TYPE" "$cid") ipaddr=$(plugn trigger network-get-ipaddr "$APP" "$PROC_TYPE" "$cid")

View File

@@ -18,7 +18,7 @@ scheduler-docker-local-scheduler-run() {
return return
fi fi
local DOCKER_RUN_LABEL_ARGS="--label=org.label-schema.schema-version=1.0 --label=org.label-schema.vendor=dokku --label=com.dokku.app-name=$APP" local DOCKER_RUN_LABEL_ARGS="--label=com.dokku.app-name=$APP"
local IMAGE_TAG=$(get_running_image_tag "$APP") local IMAGE_TAG=$(get_running_image_tag "$APP")
local IMAGE=$(get_deploying_app_image_name "$APP" "$IMAGE_TAG") local IMAGE=$(get_deploying_app_image_name "$APP" "$IMAGE_TAG")
@@ -67,7 +67,7 @@ scheduler-docker-local-scheduler-run() {
fi fi
# shellcheck disable=SC2086 # shellcheck disable=SC2086
"$DOCKER_BIN" run "${DOCKER_RUN_LABEL_ARGS[@]}" "${DOKKU_GLOBAL_RUN_ARGS[@]}" "${DOCKER_ARGS_ARRAY[@]}" $IMAGE $EXEC_CMD "$@" "$DOCKER_BIN" run "${DOCKER_RUN_LABEL_ARGS[@]}" $DOKKU_GLOBAL_RUN_ARGS "${DOCKER_ARGS_ARRAY[@]}" $IMAGE $EXEC_CMD "$@"
} }
scheduler-docker-local-scheduler-run "$@" scheduler-docker-local-scheduler-run "$@"

View File

@@ -135,4 +135,3 @@ case "$1" in
exit $? exit $?
;; ;;
esac esac

View File

@@ -30,7 +30,8 @@ teardown() {
assert_success assert_success
CID=$(docker ps -a -q -f "ancestor=dokku/${TEST_APP}" -f "label=dokku_phase_script=postdeploy") CID=$(docker ps -a -q -f "ancestor=dokku/${TEST_APP}" -f "label=dokku_phase_script=postdeploy")
IMAGE_ID=$(docker commit $CID dokku-test/${TEST_APP}) DOCKER_COMMIT_LABEL_ARGS=("--change" "LABEL org.label-schema.schema-version=1.0" "--change" "LABEL org.label-schema.vendor=dokku" "--change" "LABEL com.dokku.app-name=$TEST_APP")
IMAGE_ID=$(docker commit "${DOCKER_COMMIT_LABEL_ARGS[@]}" $CID dokku-test/${TEST_APP})
run /bin/bash -c "docker run -ti $IMAGE_ID ls /app/postdeploy.test" run /bin/bash -c "docker run -ti $IMAGE_ID ls /app/postdeploy.test"
echo "output: $output" echo "output: $output"
echo "status: $status" echo "status: $status"