From 6c8f716c111a085f258eb0ccd22e1c4e202963dd Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Thu, 1 Aug 2019 19:33:52 -0400 Subject: [PATCH] refactor: handle case copied file is not directly readable If "docker cp" is run within docker, it seems the owner is root, resulting in other processes not being able to directly read the file without resorting to `cat` trickery. Doing this in a single place avoids the problem completely. --- plugins/common/functions | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/plugins/common/functions b/plugins/common/functions index c53c68c04..30f0af240 100755 --- a/plugins/common/functions +++ b/plugins/common/functions @@ -371,7 +371,7 @@ parse_args() { copy_from_image() { declare desc="copy file from named image to destination" - declare IMAGE="$1" SRC_FILE="$2" DST_DIR="$3" + declare IMAGE="$1" SRC_FILE="$2" DST_FILE="$3" local WORK_DIR="" verify_app_name "$APP" @@ -389,11 +389,19 @@ copy_from_image() { SRC_FILE="${WORKDIR}/${SRC_FILE}" fi fi + + TMP_FILE_COMMAND_OUTPUT=$(mktemp "/tmp/dokku-${FUNCNAME[0]}.XXXX") + trap "rm -rf '$TMP_FILE_COMMAND_OUTPUT' >/dev/null" RETURN + 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" "$TMP_FILE_COMMAND_OUTPUT"; then "$DOCKER_BIN" rm -f "$CID" &>/dev/null return 1 fi + + # workaround for CHECKS file when owner is root. seems to only happen when running inside docker + cat "$TMP_FILE_COMMAND_OUTPUT" >"$DST_FILE" + "$DOCKER_BIN" rm -f "$CID" &>/dev/null else return 1