more clanup

This commit is contained in:
Christian Winther 2024-01-04 21:55:24 +00:00
parent ce34e4d046
commit f2c8497136
5 changed files with 100 additions and 75 deletions

View file

@ -126,9 +126,9 @@ RUN --mount=type=cache,id=pixelfed-apt-${PHP_VERSION}-${PHP_DEBIAN_RELEASE}-${TA
FROM base AS php-extensions FROM base AS php-extensions
ARG PHP_EXTENSIONS_DATABASE
ARG PHP_DEBIAN_RELEASE ARG PHP_DEBIAN_RELEASE
ARG PHP_EXTENSIONS ARG PHP_EXTENSIONS
ARG PHP_EXTENSIONS_DATABASE
ARG PHP_EXTENSIONS_EXTRA ARG PHP_EXTENSIONS_EXTRA
ARG PHP_PECL_EXTENSIONS ARG PHP_PECL_EXTENSIONS
ARG PHP_PECL_EXTENSIONS_EXTRA ARG PHP_PECL_EXTENSIONS_EXTRA
@ -136,13 +136,10 @@ ARG PHP_VERSION
ARG TARGETPLATFORM ARG TARGETPLATFORM
ENV PHP_EXTENSIONS_DATABASE=${PHP_EXTENSIONS_DATABASE} ENV PHP_EXTENSIONS_DATABASE=${PHP_EXTENSIONS_DATABASE}
ENV PHP_DEBIAN_RELEASE=${PHP_DEBIAN_RELEASE}
ENV PHP_EXTENSIONS_EXTRA=${PHP_EXTENSIONS_EXTRA} ENV PHP_EXTENSIONS_EXTRA=${PHP_EXTENSIONS_EXTRA}
ENV PHP_EXTENSIONS=${PHP_EXTENSIONS} ENV PHP_EXTENSIONS=${PHP_EXTENSIONS}
ENV PHP_PECL_EXTENSIONS_EXTRA=${PHP_PECL_EXTENSIONS_EXTRA} ENV PHP_PECL_EXTENSIONS_EXTRA=${PHP_PECL_EXTENSIONS_EXTRA}
ENV PHP_PECL_EXTENSIONS=${PHP_PECL_EXTENSIONS} ENV PHP_PECL_EXTENSIONS=${PHP_PECL_EXTENSIONS}
ENV PHP_VERSION=${PHP_VERSION}
ENV TARGETPLATFORM=${TARGETPLATFORM}
COPY contrib/docker/shared/root/docker/install/php-extensions.sh /docker/install/php-extensions.sh COPY contrib/docker/shared/root/docker/install/php-extensions.sh /docker/install/php-extensions.sh
RUN --mount=type=cache,id=pixelfed-php-${PHP_VERSION}-${PHP_DEBIAN_RELEASE}-${TARGETPLATFORM},sharing=locked,target=/usr/src/php/ \ RUN --mount=type=cache,id=pixelfed-php-${PHP_VERSION}-${PHP_DEBIAN_RELEASE}-${TARGETPLATFORM},sharing=locked,target=/usr/src/php/ \

View file

@ -2,20 +2,23 @@
# NOTE: # NOTE:
# #
# this file is *sourced* not run by the entrypoint runner # This file is *sourced* not run by the entrypoint runner
# so any environment values set here will be accessible to all sub-processes # so any environment values set here will be accessible to all sub-processes
# and future entrypoint.d scripts # and future entrypoint.d scripts
# #
# We also don't need to source `helpers.sh` since it's already available
entrypoint-set-name "${BASH_SOURCE[0]}" entrypoint-set-name "${BASH_SOURCE[0]}"
load-config-files load-config-files
# We assign a 1MB buffer to the just-in-time calculated max post size to allow for fields and overhead
: ${POST_MAX_SIZE_BUFFER:=1M} : ${POST_MAX_SIZE_BUFFER:=1M}
log-info "POST_MAX_SIZE_BUFFER is set to [${POST_MAX_SIZE_BUFFER}]" log-info "POST_MAX_SIZE_BUFFER is set to [${POST_MAX_SIZE_BUFFER}]"
buffer=$(numfmt --invalid=fail --from=auto --to=none --to-unit=K "${POST_MAX_SIZE_BUFFER}") buffer=$(numfmt --invalid=fail --from=auto --to=none --to-unit=K "${POST_MAX_SIZE_BUFFER}")
log-info "POST_MAX_SIZE_BUFFER converted to KB is [${buffer}]" log-info "POST_MAX_SIZE_BUFFER converted to KB is [${buffer}]"
# Automatically calculate the [post_max_size] value for [php.ini] and [nginx]
log-info "POST_MAX_SIZE will be calculated by [({MAX_PHOTO_SIZE} * {MAX_ALBUM_LENGTH}) + {POST_MAX_SIZE_BUFFER}]" log-info "POST_MAX_SIZE will be calculated by [({MAX_PHOTO_SIZE} * {MAX_ALBUM_LENGTH}) + {POST_MAX_SIZE_BUFFER}]"
log-info " MAX_PHOTO_SIZE=${MAX_PHOTO_SIZE}" log-info " MAX_PHOTO_SIZE=${MAX_PHOTO_SIZE}"
log-info " MAX_ALBUM_LENGTH=${MAX_ALBUM_LENGTH}" log-info " MAX_ALBUM_LENGTH=${MAX_ALBUM_LENGTH}"
@ -23,4 +26,5 @@ log-info " POST_MAX_SIZE_BUFFER=${buffer}"
: ${POST_MAX_SIZE:=$(numfmt --invalid=fail --from=auto --from-unit=K --to=si $(((${MAX_PHOTO_SIZE} * ${MAX_ALBUM_LENGTH}) + ${buffer})))} : ${POST_MAX_SIZE:=$(numfmt --invalid=fail --from=auto --from-unit=K --to=si $(((${MAX_PHOTO_SIZE} * ${MAX_ALBUM_LENGTH}) + ${buffer})))}
log-info "POST_MAX_SIZE was calculated to [${POST_MAX_SIZE}]" log-info "POST_MAX_SIZE was calculated to [${POST_MAX_SIZE}]"
# NOTE: must export the value so it's available in other scripts!
export POST_MAX_SIZE export POST_MAX_SIZE

View file

@ -3,37 +3,53 @@ source /docker/helpers.sh
entrypoint-set-name "$0" entrypoint-set-name "$0"
declare template_dir="${ENVSUBST_TEMPLATE_DIR:-/docker/templates}" # Show [git diff] of templates being rendered (will help verify output)
declare output_dir="${ENVSUBST_OUTPUT_DIR:-}"
declare filter="${ENVSUBST_FILTER:-}"
declare template defined_envs relative_path output_path output_dir subdir
# load all dot-env files
load-config-files
: ${ENTRYPOINT_SHOW_TEMPLATE_DIFF:=1} : ${ENTRYPOINT_SHOW_TEMPLATE_DIFF:=1}
# Directory where templates can be found
: ${ENTRYPOINT_TEMPLATE_DIR:=/docker/templates/}
# Root path to write template template_files to (default is '', meaning it will be written to /<path>)
: ${ENTRYPOINT_TEMPLATE_OUTPUT_PREFIX:=}
declare template_file relative_template_file_path output_file_dir
# load all dot-env config files
load-config-files
# export all dot-env variables so they are available in templating # export all dot-env variables so they are available in templating
export ${seen_dot_env_variables[@]} export ${seen_dot_env_variables[@]}
find "$template_dir" -follow -type f -print | while read -r template; do find "${ENTRYPOINT_TEMPLATE_DIR}" -follow -type f -print | while read -r template_file; do
relative_path="${template#"$template_dir/"}" # Example: template_file=/docker/templates/usr/local/etc/php/php.ini
subdir=$(dirname "$relative_path")
output_path="$output_dir/${relative_path}"
output_dir=$(dirname "$output_path")
if [ ! -w "$output_dir" ]; then # The file path without the template dir prefix ($ENTRYPOINT_TEMPLATE_DIR)
log-error-and-exit "ERROR: $template_dir exists, but $output_dir is not writable" #
# Example: /usr/local/etc/php/php.ini
relative_template_file_path="${template_file#"${ENTRYPOINT_TEMPLATE_DIR}"}"
# Adds optional prefix to the output file path
#
# Example: /usr/local/etc/php/php.ini
output_file_path="${ENTRYPOINT_TEMPLATE_OUTPUT_PREFIX}/${relative_template_file_path}"
# Remove the file from the path
#
# Example: /usr/local/etc/php
output_file_dir=$(dirname "${output_file_path}")
# Ensure the output directory is writable
if ! is-writable "${output_file_dir}"; then
log-error-and-exit "${output_file_dir} is not writable"
fi fi
# create a subdirectory where the template file exists # Create the output directory if it doesn't exists
mkdir -p "$output_dir/$subdir" ensure-directory "${output_file_dir}"
log-info "Running [gomplate] on [$template] --> [$output_path]" # Render the template
cat "$template" | gomplate >"$output_path" log-info "Running [gomplate] on [${template_file}] --> [${output_file_path}]"
cat "${template_file}" | gomplate >"${output_file_path}"
# Show the diff from the envsubst command # Show the diff from the envsubst command
if [[ ${ENTRYPOINT_SHOW_TEMPLATE_DIFF} = 1 ]]; then if [[ ${ENTRYPOINT_SHOW_TEMPLATE_DIFF} = 1 ]]; then
git --no-pager diff "$template" "${output_path}" || : git --no-pager diff "${template_file}" "${output_file_path}" || :
fi fi
done done

View file

@ -1,29 +1,26 @@
#!/bin/bash #!/bin/bash
set -e -o errexit -o nounset -o pipefail if [[ ${ENTRYPOINT_SKIP:=0} != 0 ]]; then
exec "$@"
fi
: ${ENTRYPOINT_SKIP:=0}
: ${ENTRYPOINT_SKIP_SCRIPTS:=""}
: ${ENTRYPOINT_DEBUG:=0}
: ${ENTRYPOINT_ROOT:="/docker/entrypoint.d/"} : ${ENTRYPOINT_ROOT:="/docker/entrypoint.d/"}
: ${ENTRYPOINT_SKIP_SCRIPTS:=""}
export ENTRYPOINT_ROOT export ENTRYPOINT_ROOT
if [[ ${ENTRYPOINT_SKIP} == 0 ]]; then source /docker/helpers.sh
[[ ${ENTRYPOINT_DEBUG} == 1 ]] && set -x
source /docker/helpers.sh entrypoint-set-name "entrypoint.sh"
entrypoint-set-name "entrypoint.sh" declare -a skip_scripts
IFS=' ' read -a skip_scripts <<<"$ENTRYPOINT_SKIP_SCRIPTS"
declare -a skip_scripts declare script_name
IFS=' ' read -a skip_scripts <<<"$ENTRYPOINT_SKIP_SCRIPTS"
declare script_name # ensure the entrypoint folder exists
mkdir -p "${ENTRYPOINT_ROOT}"
# ensure the entrypoint folder exists if /usr/bin/find "${ENTRYPOINT_ROOT}" -mindepth 1 -maxdepth 1 -type f -print -quit 2>/dev/null | read v; then
mkdir -p "${ENTRYPOINT_ROOT}"
if /usr/bin/find "${ENTRYPOINT_ROOT}" -mindepth 1 -maxdepth 1 -type f -print -quit 2>/dev/null | read v; then
log-info "looking for shell scripts in /docker/entrypoint.d/" log-info "looking for shell scripts in /docker/entrypoint.d/"
find "${ENTRYPOINT_ROOT}" -follow -type f -print | sort -V | while read -r file; do find "${ENTRYPOINT_ROOT}" -follow -type f -print | sort -V | while read -r file; do
@ -68,9 +65,8 @@ if [[ ${ENTRYPOINT_SKIP} == 0 ]]; then
done done
log-info "Configuration complete; ready for start up" log-info "Configuration complete; ready for start up"
else else
log-warning "No files found in ${ENTRYPOINT_ROOT}, skipping configuration" log-warning "No files found in ${ENTRYPOINT_ROOT}, skipping configuration"
fi
fi fi
exec "$@" exec "$@"

View file

@ -1,6 +1,10 @@
#!/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} == 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"
declare -g warn_message_color="\033[1;34m" declare -g warn_message_color="\033[1;34m"
@ -110,6 +114,14 @@ function is-executable() {
[[ -x "$1" ]] [[ -x "$1" ]]
} }
function is-writable() {
[[ -w "$1" ]]
}
function ensure-directory() {
mkdir -pv "$@"
}
function get-entrypoint-script-name() { function get-entrypoint-script-name() {
echo "${1#"$ENTRYPOINT_ROOT"}" echo "${1#"$ENTRYPOINT_ROOT"}"
} }