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

@@ -22,7 +22,7 @@ apps_clone_cmd() {
OLD_APP="$1" NEW_APP="$2"
[[ -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 "$NEW_APP"
@@ -46,7 +46,7 @@ apps_clone_cmd() {
plugn trigger post-app-clone-setup "$OLD_APP" "$NEW_APP"
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
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_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
"$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
rm -rf "$OLD_CACHE_DIR"
apps_create "$NEW_APP"