diff --git a/plugins/common/functions b/plugins/common/functions index 358f8af2345..73beec9c1ed 100755 --- a/plugins/common/functions +++ b/plugins/common/functions @@ -490,46 +490,7 @@ copy_from_image() { declare IMAGE="$1" SRC_FILE="$2" DST_FILE="$3" local WORK_DIR="" - local DOCKER_CREATE_LABEL_ARGS="--label=com.dokku.app-name=$APP" - - if verify_image "$IMAGE"; then - if ! is_abs_path "$SRC_FILE"; then - if is_image_cnb_based "$IMAGE"; then - WORKDIR="/workspace" - elif is_image_herokuish_based "$IMAGE" "$APP"; then - WORKDIR="/app" - else - WORKDIR="$("$DOCKER_BIN" image inspect --format '{{.Config.WorkingDir}}' "$IMAGE")" - fi - - if [[ -n "$WORKDIR" ]]; then - SRC_FILE="${WORKDIR}/${SRC_FILE}" - fi - fi - - TMP_FILE_COMMAND_OUTPUT=$(mktemp "/tmp/dokku-${DOKKU_PID}-${FUNCNAME[0]}.XXXXXX") - trap "rm -rf '$TMP_FILE_COMMAND_OUTPUT' &>/dev/null || true" RETURN - - local CID=$("$DOCKER_BIN" container create "${DOCKER_CREATE_LABEL_ARGS[@]}" $DOKKU_GLOBAL_RUN_ARGS "$IMAGE") - "$DOCKER_BIN" container cp "$CID:$SRC_FILE" "$TMP_FILE_COMMAND_OUTPUT" 2>/dev/null || true - "$DOCKER_BIN" container rm --force "$CID" &>/dev/null - plugn trigger scheduler-register-retired "$APP" "$CID" - - # docker cp exits with status 1 when run as non-root user when it tries to chown the file - # after successfully copying the file. Thus, we suppress stderr. - # ref: https://github.com/dotcloud/docker/issues/3986 - if [[ ! -s "$TMP_FILE_COMMAND_OUTPUT" ]]; then - return 1 - fi - - # workaround for CHECKS file when owner is root. seems to only happen when running inside docker - dos2unix -l <"$TMP_FILE_COMMAND_OUTPUT" >"$DST_FILE" - - # add trailing newline for certain places where file parsing depends on it - if [[ "$(tail -c1 "$DST_FILE")" != "" ]]; then - echo "" >>"$DST_FILE" - fi - else + if ! "$PLUGIN_CORE_AVAILABLE_PATH/common/common" copy-from-image "$APP" "$IMAGE" "$SRC_FILE" "$DST_FILE"; then return 1 fi } diff --git a/plugins/common/src/common/common.go b/plugins/common/src/common/common.go index 1cd87b13dae..2862536e93e 100644 --- a/plugins/common/src/common/common.go +++ b/plugins/common/src/common/common.go @@ -20,6 +20,12 @@ func main() { var err error switch cmd { + case "copy-from-image": + appName := flag.Arg(1) + image := flag.Arg(2) + source := flag.Arg(3) + destination := flag.Arg(4) + err = common.CopyFromImage(appName, image, source, destination) case "docker-cleanup": appName := flag.Arg(1) force := common.ToBool(flag.Arg(2))