forked from mirror/pixelfed
more tweaks
This commit is contained in:
parent
890827d60e
commit
895b51fd9f
|
@ -108,6 +108,12 @@ When a Pixelfed container starts up, the [`ENTRYPOINT`](https://docs.docker.com/
|
||||||
1. If the file has the extension `.sh` the file will be run like a normal script.
|
1. If the file has the extension `.sh` the file will be run like a normal script.
|
||||||
1. Any other file extension will log a warning and will be ignored.
|
1. Any other file extension will log a warning and will be ignored.
|
||||||
|
|
||||||
|
#### Debugging
|
||||||
|
|
||||||
|
You can set environment variable `ENTRYPOINT_DEBUG=1` to show verbose output of what each `entrypoint.d` script is doing.
|
||||||
|
|
||||||
|
You can also `docker exec` or `docker run` into a container and run `/`
|
||||||
|
|
||||||
#### Included scripts
|
#### Included scripts
|
||||||
|
|
||||||
* `/docker/entrypoint.d/04-defaults.envsh` calculates Docker container environment variables needed for [templating](#templating) configuration files.
|
* `/docker/entrypoint.d/04-defaults.envsh` calculates Docker container environment variables needed for [templating](#templating) configuration files.
|
||||||
|
@ -145,7 +151,7 @@ Variables available for templating are sourced (in order, so *last* source takes
|
||||||
|
|
||||||
#### Template guide 101
|
#### Template guide 101
|
||||||
|
|
||||||
Please see the [gomplate documentation](https://docs.gomplate.ca/) for a more comprehensive overview.
|
Please see the [`gomplate` documentation](https://docs.gomplate.ca/) for a more comprehensive overview.
|
||||||
|
|
||||||
The most frequent use-case you have is likely to print a environment variable (or a default value if it's missing), so this is how to do that:
|
The most frequent use-case you have is likely to print a environment variable (or a default value if it's missing), so this is how to do that:
|
||||||
|
|
||||||
|
@ -156,8 +162,8 @@ The script will *fail* if you reference a variable that does not exist (and don'
|
||||||
|
|
||||||
Please see the
|
Please see the
|
||||||
|
|
||||||
* [gomplate syntax documentation](https://docs.gomplate.ca/syntax/)
|
* [`gomplate` syntax documentation](https://docs.gomplate.ca/syntax/)
|
||||||
* [gomplate functions documentation](https://docs.gomplate.ca/functions/)
|
* [`gomplate` functions documentation](https://docs.gomplate.ca/functions/)
|
||||||
|
|
||||||
### Fixing ownership on startup
|
### Fixing ownership on startup
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ source /docker/helpers.sh
|
||||||
entrypoint-set-name "$0"
|
entrypoint-set-name "$0"
|
||||||
|
|
||||||
# Copy the [storage/] skeleton files over the "real" [storage/] directory so assets are updated between versions
|
# Copy the [storage/] skeleton files over the "real" [storage/] directory so assets are updated between versions
|
||||||
run-as-runtime-user cp --recursive storage.skel/* storage/
|
run-as-runtime-user cp --recursive storage.skel/ storage/
|
||||||
|
|
||||||
# Ensure storage linkk are correctly configured
|
# Ensure storage linkk are correctly configured
|
||||||
run-as-runtime-user php artisan storage:link
|
run-as-runtime-user php artisan storage:link
|
||||||
|
|
|
@ -7,15 +7,15 @@ entrypoint-set-name "$0"
|
||||||
: ${ENTRYPOINT_ENSURE_OWNERSHIP_PATHS:=""}
|
: ${ENTRYPOINT_ENSURE_OWNERSHIP_PATHS:=""}
|
||||||
|
|
||||||
declare -a ensure_ownership_paths=()
|
declare -a ensure_ownership_paths=()
|
||||||
IFS=' ' read -a ensure_ownership_paths <<<"$ENTRYPOINT_ENSURE_OWNERSHIP_PATHS"
|
IFS=' ' read -a ensure_ownership_paths <<<"${ENTRYPOINT_ENSURE_OWNERSHIP_PATHS}"
|
||||||
|
|
||||||
if [[ ${#ensure_ownership_paths} == 0 ]]; then
|
if [[ ${#ensure_ownership_paths[@]} == 0 ]]; then
|
||||||
log-info "No paths has been configured for ownership fixes via [\$ENTRYPOINT_ENSURE_OWNERSHIP_PATHS]."
|
log-info "No paths has been configured for ownership fixes via [\$ENTRYPOINT_ENSURE_OWNERSHIP_PATHS]."
|
||||||
|
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
for path in "${ensure_ownership_paths[@]}"; do
|
for path in "${ensure_ownership_paths[@]}"; do
|
||||||
log-info "Ensure ownership of [${path}] correct"
|
log-info "Ensure ownership of [${path}] is correct"
|
||||||
chown --recursive ${RUNTIME_UID}:${RUNTIME_GID} "${path}"
|
run-as-current-user chown --recursive ${RUNTIME_UID}:${RUNTIME_GID} "${path}"
|
||||||
done
|
done
|
||||||
|
|
|
@ -50,7 +50,9 @@ find "${ENTRYPOINT_ROOT}" -follow -type f -print | sort -V | while read -r file;
|
||||||
log-error-and-exit "File [${file}] is not executable (please 'chmod +x' it)"
|
log-error-and-exit "File [${file}] is not executable (please 'chmod +x' it)"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
log-info
|
||||||
log-info "Sourcing [${file}]"
|
log-info "Sourcing [${file}]"
|
||||||
|
log-info
|
||||||
|
|
||||||
source "${file}"
|
source "${file}"
|
||||||
|
|
||||||
|
@ -65,7 +67,10 @@ find "${ENTRYPOINT_ROOT}" -follow -type f -print | sort -V | while read -r file;
|
||||||
log-error-and-exit "File [${file}] is not executable (please 'chmod +x' it)"
|
log-error-and-exit "File [${file}] is not executable (please 'chmod +x' it)"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
log-info
|
||||||
log-info "Running [${file}]"
|
log-info "Running [${file}]"
|
||||||
|
log-info
|
||||||
|
|
||||||
"${file}"
|
"${file}"
|
||||||
;;
|
;;
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,7 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
set -e -o errexit -o nounset -o pipefail
|
set -e -o errexit -o nounset -o pipefail
|
||||||
|
|
||||||
: ${ENTRYPOINT_DEBUG:=0}
|
[[ ${ENTRYPOINT_DEBUG:=0} == 1 ]] && set -x
|
||||||
|
|
||||||
[[ ${ENTRYPOINT_DEBUG} == 1 ]] && set -x
|
|
||||||
|
|
||||||
# Some splash of color for important messages
|
# Some splash of color for important messages
|
||||||
declare -g error_message_color="\033[1;31m"
|
declare -g error_message_color="\033[1;31m"
|
||||||
|
@ -40,14 +38,37 @@ function entrypoint-restore-name() {
|
||||||
# @exitcode 0 if the command succeeeds
|
# @exitcode 0 if the command succeeeds
|
||||||
# @exitcode 1 if the command fails
|
# @exitcode 1 if the command fails
|
||||||
function run-as-runtime-user() {
|
function run-as-runtime-user() {
|
||||||
|
run-command-as "$(id -un ${RUNTIME_UID})" "${@}"
|
||||||
|
}
|
||||||
|
|
||||||
|
# @description Run a command as the [runtime user]
|
||||||
|
# @arg $@ string The command to run
|
||||||
|
# @exitcode 0 if the command succeeeds
|
||||||
|
# @exitcode 1 if the command fails
|
||||||
|
function run-as-current-user() {
|
||||||
|
run-command-as "$(id -un)" "${@}"
|
||||||
|
}
|
||||||
|
|
||||||
|
# @description Run a command as the a named user
|
||||||
|
# @arg $1 string The user to run the command as
|
||||||
|
# @arg $@ string The command to run
|
||||||
|
# @exitcode 0 If the command succeeeds
|
||||||
|
# @exitcode 1 If the command fails
|
||||||
|
function run-command-as() {
|
||||||
local -i exit_code
|
local -i exit_code
|
||||||
local target_user
|
local target_user
|
||||||
|
|
||||||
target_user=$(id -un ${RUNTIME_UID})
|
target_user=${1}
|
||||||
|
shift
|
||||||
|
|
||||||
log-info "👷 Running [${*}] as [${target_user}]"
|
log-info-stderr "👷 Running [${*}] as [${target_user}]"
|
||||||
|
|
||||||
|
if [[ ${target_user} != "root" ]]; then
|
||||||
su --preserve-environment "${target_user}" --shell /bin/bash --command "${*}"
|
su --preserve-environment "${target_user}" --shell /bin/bash --command "${*}"
|
||||||
|
else
|
||||||
|
"${@}"
|
||||||
|
fi
|
||||||
|
|
||||||
exit_code=$?
|
exit_code=$?
|
||||||
|
|
||||||
if [[ $exit_code != 0 ]]; then
|
if [[ $exit_code != 0 ]]; then
|
||||||
|
@ -55,7 +76,7 @@ function run-as-runtime-user() {
|
||||||
return $exit_code
|
return $exit_code
|
||||||
fi
|
fi
|
||||||
|
|
||||||
log-info "✅ OK!"
|
log-info-stderr "✅ OK!"
|
||||||
return $exit_code
|
return $exit_code
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -92,6 +113,15 @@ function log-info() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# @description Print the given message to stderr unless [ENTRYPOINT_QUIET_LOGS] is set
|
||||||
|
# @arg $@ string A info message.
|
||||||
|
# @stderr The info message provided with log prefix unless $ENTRYPOINT_QUIET_LOGS
|
||||||
|
function log-info-stderr() {
|
||||||
|
if [ -z "${ENTRYPOINT_QUIET_LOGS:-}" ]; then
|
||||||
|
echo "${log_prefix}$*"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
# @description Loads the dot-env files used by Docker and track the keys present in the configuration.
|
# @description Loads the dot-env files used by Docker and track the keys present in the configuration.
|
||||||
# @sets seen_dot_env_variables array List of config keys discovered during loading
|
# @sets seen_dot_env_variables array List of config keys discovered during loading
|
||||||
function load-config-files() {
|
function load-config-files() {
|
||||||
|
|
Loading…
Reference in New Issue