feat: handle case where docker cp is run as non root and tries to chown the file

This _may_ be cargo-cult, but its an easy way to handle any potential issues, so we'll include it regardless.
This commit is contained in:
Jose Diaz-Gonzalez
2019-08-01 19:40:30 -04:00
parent dc9d597cd8
commit 8dbf855d56

View File

@@ -394,8 +394,13 @@ copy_from_image() {
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" "$TMP_FILE_COMMAND_OUTPUT"; then
"$DOCKER_BIN" rm -f "$CID" &>/dev/null
"$DOCKER_BIN" cp "$CID:$SRC_FILE" "$TMP_FILE_COMMAND_OUTPUT" 2>/dev/null || true
"$DOCKER_BIN" rm -f "$CID" &>/dev/null
# 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