Merge pull request #3781 from dokku/mh/fix/custom-dokku-app-user
fix: respect DOKKU_APP_USER in is_image_herokuish_based
This commit is contained in:
@@ -86,7 +86,7 @@ execute_script() {
|
||||
local DOCKER_ARGS=$(sed -e "s/--restart=[[:graph:]]\+[[:blank:]]\?//g" <<<"$DOCKER_ARGS")
|
||||
|
||||
local IMAGE_SOURCE_TYPE="dockerfile"
|
||||
is_image_herokuish_based "$IMAGE" && IMAGE_SOURCE_TYPE="herokuish"
|
||||
is_image_herokuish_based "$IMAGE" "$APP" && IMAGE_SOURCE_TYPE="herokuish"
|
||||
DOCKER_ARGS+=$(: | plugn trigger docker-args-process-deploy "$APP" "$IMAGE_TAG" "$IMAGE_SOURCE_TYPE")
|
||||
|
||||
# eval args as array to respect escapes
|
||||
@@ -109,7 +109,7 @@ execute_script() {
|
||||
return
|
||||
fi
|
||||
|
||||
if ! is_image_herokuish_based "$IMAGE"; then
|
||||
if ! is_image_herokuish_based "$IMAGE" "$APP"; then
|
||||
local DOKKU_DOCKERFILE_ENTRYPOINT=$(config_get "$APP" DOKKU_DOCKERFILE_ENTRYPOINT)
|
||||
local DOKKU_DOCKERFILE_CMD=$(config_get "$APP" DOKKU_DOCKERFILE_CMD)
|
||||
[[ -z "$DOKKU_DOCKERFILE_ENTRYPOINT" ]] && DOKKU_DOCKERFILE_ENTRYPOINT="$(get_entrypoint_from_image "$IMAGE")"
|
||||
|
||||
@@ -58,7 +58,7 @@ check_process() {
|
||||
|
||||
IS_HEROKUISH_CONTAINER=false
|
||||
IMAGE=$(get_app_image_name "$APP")
|
||||
is_image_herokuish_based "$IMAGE" && IS_HEROKUISH_CONTAINER=true
|
||||
is_image_herokuish_based "$IMAGE" "$APP" && IS_HEROKUISH_CONTAINER=true
|
||||
|
||||
dokku_log_info1 "Running checks for app ($APP.$PROC_TYPE.$CONTAINER_INDEX)"
|
||||
CONTAINER_ID=$(<"$DOKKU_CONTAINER_ID_FILE")
|
||||
|
||||
@@ -245,7 +245,7 @@ func IsDeployed(appName string) bool {
|
||||
}
|
||||
|
||||
// IsImageHerokuishBased returns true if app image is based on herokuish
|
||||
func IsImageHerokuishBased(image string) bool {
|
||||
func IsImageHerokuishBased(image string, appName string) bool {
|
||||
output, err := DockerInspect(image, "{{range .Config.Env}}{{if eq . \"USER=herokuishuser\" }}{{println .}}{{end}}{{end}}")
|
||||
if err != nil {
|
||||
return false
|
||||
|
||||
@@ -293,14 +293,20 @@ get_running_image_tag() {
|
||||
is_image_herokuish_based() {
|
||||
declare desc="returns true if app image is based on herokuish"
|
||||
declare IMAGE="$1"
|
||||
declare APP="$2"
|
||||
local DOKKU_APP_USER
|
||||
if [[ -n "$APP" ]]; then
|
||||
DOKKU_APP_USER=$(config_get "$APP" DOKKU_APP_USER || true)
|
||||
fi
|
||||
DOKKU_APP_USER=${DOKKU_APP_USER:="herokuishuser"}
|
||||
local USER_VALUE
|
||||
|
||||
if [[ -z "$IMAGE" ]]; then
|
||||
return 1
|
||||
fi
|
||||
|
||||
# due to how the build process works, all herokuish images have the Environment variable USER=herokuishuser
|
||||
USER_VALUE="$("$DOCKER_BIN" image inspect --format '{{range .Config.Env}}{{if eq . "USER=herokuishuser" }}{{println .}}{{end}}{{end}}' "$IMAGE")"
|
||||
# due to how the build process works, all herokuish images have the Environment variable USER=$DOKKU_APP_USER
|
||||
USER_VALUE="$("$DOCKER_BIN" image inspect --format '{{range .Config.Env}}{{if eq . "USER='"$DOKKU_APP_USER"'"}}{{println .}}{{end}}{{end}}' "$IMAGE")"
|
||||
[[ "$USER_VALUE" == "" ]] && return 1
|
||||
return 0
|
||||
}
|
||||
@@ -395,7 +401,7 @@ copy_from_image() {
|
||||
|
||||
if verify_image "$IMAGE"; then
|
||||
if ! is_abs_path "$SRC_FILE"; then
|
||||
if is_image_herokuish_based "$IMAGE"; then
|
||||
if is_image_herokuish_based "$IMAGE" "$APP"; then
|
||||
WORKDIR="/app"
|
||||
else
|
||||
WORKDIR="$("$DOCKER_BIN" image inspect --format '{{.Config.WorkingDir}}' "$IMAGE")"
|
||||
@@ -583,7 +589,7 @@ release_and_deploy() {
|
||||
verify_app_name "$APP"
|
||||
|
||||
if verify_image "$IMAGE"; then
|
||||
if is_image_herokuish_based "$IMAGE"; then
|
||||
if is_image_herokuish_based "$IMAGE" "$APP"; then
|
||||
local IMAGE_SOURCE_TYPE="herokuish"
|
||||
else
|
||||
local IMAGE_SOURCE_TYPE="dockerfile"
|
||||
|
||||
@@ -14,7 +14,7 @@ config_docker_args() {
|
||||
trigger="$0 config_docker_args"
|
||||
verify_app_name "$APP"
|
||||
|
||||
if ! is_image_herokuish_based "$IMAGE"; then
|
||||
if ! is_image_herokuish_based "$IMAGE" "$APP"; then
|
||||
ENV_ARGS="$(config_export app "$APP" --format docker-args --merged)"
|
||||
echo -n "$STDIN $ENV_ARGS"
|
||||
else
|
||||
|
||||
@@ -58,7 +58,7 @@ enter_default_cmd() {
|
||||
|
||||
local EXEC_CMD=""
|
||||
has_tty && local DOKKU_RUN_OPTS+=" -i -t"
|
||||
is_image_herokuish_based "$IMAGE" && local EXEC_CMD="/exec"
|
||||
is_image_herokuish_based "$IMAGE" "$APP" && local EXEC_CMD="/exec"
|
||||
# shellcheck disable=SC2086
|
||||
"$DOCKER_BIN" container exec $DOKKU_RUN_OPTS $ID $EXEC_CMD "${@:-$DOKKU_APP_SHELL}"
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ func BuildConfig(appName string) {
|
||||
}
|
||||
|
||||
image := common.GetAppImageName(appName, "", "")
|
||||
isHerokuishContainer := common.IsImageHerokuishBased(image)
|
||||
isHerokuishContainer := common.IsImageHerokuishBased(image, appName)
|
||||
common.LogInfo1(fmt.Sprintf("Ensuring network configuration is in sync for %s", appName))
|
||||
lines, err := common.FileToSlice(scaleFile)
|
||||
if err != nil {
|
||||
|
||||
@@ -25,7 +25,7 @@ scheduler-docker-local-scheduler-deploy() {
|
||||
verify_app_name "$APP"
|
||||
plugn trigger pre-deploy "$APP" "$IMAGE_TAG"
|
||||
|
||||
is_image_herokuish_based "$IMAGE" && DOKKU_HEROKUISH=true
|
||||
is_image_herokuish_based "$IMAGE" "$APP" && DOKKU_HEROKUISH=true
|
||||
local IMAGE_SOURCE_TYPE="dockerfile"
|
||||
[[ "$DOKKU_HEROKUISH" == "true" ]] && IMAGE_SOURCE_TYPE="herokuish"
|
||||
local DOKKU_SCALE_FILE="$DOKKU_ROOT/$APP/DOKKU_SCALE"
|
||||
|
||||
@@ -34,7 +34,7 @@ scheduler-docker-local-scheduler-run() {
|
||||
|
||||
local DYNO_NUMBER="$RANDOM"
|
||||
local IMAGE_SOURCE_TYPE="dockerfile"
|
||||
is_image_herokuish_based "$IMAGE" && IMAGE_SOURCE_TYPE="herokuish"
|
||||
is_image_herokuish_based "$IMAGE" "$APP" && IMAGE_SOURCE_TYPE="herokuish"
|
||||
DOCKER_ARGS+=$(: | plugn trigger docker-args-process-run "$APP" "$IMAGE_TAG" "$IMAGE_SOURCE_TYPE")
|
||||
DOCKER_ARGS+=" -e DYNO=run.$DYNO_NUMBER --name $APP.run.$DYNO_NUMBER"
|
||||
|
||||
|
||||
@@ -186,3 +186,42 @@ EOF
|
||||
echo "status: $status"
|
||||
assert_output "3001/udp 3000/tcp 3003"
|
||||
}
|
||||
|
||||
@test "(core) image type detection (herokuish default user)" {
|
||||
export DOKKU_ROOT
|
||||
deploy_app
|
||||
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
|
||||
source "$PLUGIN_CORE_AVAILABLE_PATH/config/functions"
|
||||
|
||||
run is_image_herokuish_based "dokku/$TEST_APP" "$TEST_APP"
|
||||
echo "output: $output"
|
||||
echo "status: $status"
|
||||
assert_success
|
||||
}
|
||||
|
||||
@test "(core) image type detection (herokuish custom user)" {
|
||||
export DOKKU_ROOT
|
||||
deploy_app
|
||||
CID=$(< "$DOKKU_ROOT/$TEST_APP/CONTAINER.web.1")
|
||||
docker commit --change "ENV USER postgres" "$CID" "dokku/${TEST_APP}:latest"
|
||||
dokku config:set --no-restart "$TEST_APP" DOKKU_APP_USER=postgres
|
||||
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
|
||||
source "$PLUGIN_CORE_AVAILABLE_PATH/config/functions"
|
||||
|
||||
run is_image_herokuish_based "dokku/$TEST_APP" "$TEST_APP"
|
||||
echo "output: $output"
|
||||
echo "status: $status"
|
||||
assert_success
|
||||
}
|
||||
|
||||
@test "(core) image type detection (dockerfile)" {
|
||||
export DOKKU_ROOT
|
||||
deploy_app dockerfile
|
||||
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
|
||||
source "$PLUGIN_CORE_AVAILABLE_PATH/config/functions"
|
||||
|
||||
run is_image_herokuish_based "dokku/$TEST_APP" "$TEST_APP"
|
||||
echo "output: $output"
|
||||
echo "status: $status"
|
||||
assert_failure
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
# constants
|
||||
DOKKU_ROOT=${DOKKU_ROOT:=~dokku}
|
||||
DOCKER_BIN=${DOCKER_BIN:="docker"}
|
||||
DOKKU_LIB_ROOT=${DOKKU_LIB_PATH:="/var/lib/dokku"}
|
||||
PLUGIN_PATH=${PLUGIN_PATH:="$DOKKU_LIB_ROOT/plugins"}
|
||||
PLUGIN_AVAILABLE_PATH=${PLUGIN_AVAILABLE_PATH:="$PLUGIN_PATH/available"}
|
||||
|
||||
Reference in New Issue
Block a user