fix: Only override the WORKDIR in copy_from_image if the image is gliderlabs/herokuish based
Rather than always assuming a missing `WORKDIR` means herokuish, we instead inspect the image to verify that it is. If it is, then and _only_ then do we set WORKDIR. Otherwise, we respect the decision of `docker cp` to execute from within the last known `WORKDIR` context, which is inherited at the image level, not image metadata level. Additionally, speed up `is_image_herokuish_based` by inspecting the environment variables on the image. When there is a "USER=herokuishuser", we can more or less safely assume it is an image that Dokku built, and is therefore a herokuish image. While possible, it would be very strange if a non-herokuish image had this environment variable set, so it is a relatively safe change.
This commit is contained in:
@@ -275,9 +275,13 @@ get_running_image_tag() {
|
|||||||
|
|
||||||
is_image_herokuish_based() {
|
is_image_herokuish_based() {
|
||||||
declare desc="returns true if app image is based on herokuish"
|
declare desc="returns true if app image is based on herokuish"
|
||||||
# circleci can't support --rm as they run lxc in lxc
|
declare IMAGE="$1"
|
||||||
[[ ! -f "/home/ubuntu/.circlerc" ]] && local DOCKER_ARGS="--rm"
|
local USER_VALUE
|
||||||
docker run "$DOKKU_GLOBAL_RUN_ARGS" --entrypoint="/bin/sh" $DOCKER_ARGS "$@" -c "test -f /exec" &>/dev/null
|
|
||||||
|
# due to how the build process works, all herokuish images have the Environment variable USER=herokuishuser
|
||||||
|
USER_VALUE="$(docker inspect -f '{{range .Config.Env}}{{if eq . "USER=herokuishuser" }}{{println .}}{{end}}{{end}}' "$IMAGE")"
|
||||||
|
[[ "$USER_VALUE" == "" ]] && return 1
|
||||||
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
get_docker_version() {
|
get_docker_version() {
|
||||||
@@ -346,16 +350,21 @@ parse_args() {
|
|||||||
|
|
||||||
copy_from_image() {
|
copy_from_image() {
|
||||||
declare desc="copy file from named image to destination"
|
declare desc="copy file from named image to destination"
|
||||||
local IMAGE="$1"
|
declare IMAGE="$1" SRC_FILE="$2" DST_DIR="$3"
|
||||||
local SRC_FILE="$2"
|
local WORK_DIR=""
|
||||||
local DST_DIR="$3"
|
|
||||||
verify_app_name "$APP"
|
verify_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
|
||||||
local WORKDIR=$(docker inspect -f '{{.Config.WorkingDir}}' "$IMAGE")
|
if is_image_herokuish_based "$IMAGE"; then
|
||||||
[[ -z "$WORKDIR" ]] && local WORKDIR=/app
|
WORKDIR="/app"
|
||||||
local SRC_FILE="$WORKDIR/$SRC_FILE"
|
else
|
||||||
|
WORKDIR="$(docker inspect -f '{{.Config.WorkingDir}}' "$IMAGE")"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ -n "$WORKDIR" ]]; then
|
||||||
|
SRC_FILE="${WORKDIR}/${SRC_FILE}"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
local CID=$(docker create "$DOKKU_GLOBAL_RUN_ARGS" "$IMAGE")
|
local CID=$(docker create "$DOKKU_GLOBAL_RUN_ARGS" "$IMAGE")
|
||||||
docker cp "$CID:$SRC_FILE" "$DST_DIR"
|
docker cp "$CID:$SRC_FILE" "$DST_DIR"
|
||||||
|
|||||||
Reference in New Issue
Block a user