chore: create template substitution variables with shell

This commit is contained in:
Junior L. Botelho (JLB) 2023-02-11 15:55:17 -03:00
parent a6883f62d7
commit 9abb2cdbc8
No known key found for this signature in database
GPG Key ID: 6A25840754F2A524
3 changed files with 20 additions and 6 deletions

View File

@ -1,12 +1,17 @@
#!/bin/sh
# YOU DON'T NEED TO EDIT THIS FILE. IF YOU WANT TO SET
# CUSTOM ENVIRONMENT VARIABLES, USE THE 'DOCKERFILE IMAGE'
# FROM ROOT DIRECTORY AND PASS THE ENVIRONMENT PARAMETERS
# YOU DON'T NEED TO EDIT THIS FILE. IF YOU WANT TO SET CUSTOM ENVIRONMENT VARIABLES,
# USE THE 'DOCKERFILE IMAGE' FROM ROOT DIRECTORY AND PASS THE ENVIRONMENT PARAMETERS
# This variable changes the behavior of the image builder to remove the base image
export DOCKER_BUILDKIT=1
# These templates will be used to create configuration files that incorporate values from environment variables
# If these locations do not already exist within the Docker container, they will be created
export CONFIG_PHP_TEMPLATE="$(pwd)/templates/config.php"
export CONFIG_NGINX_TEMPLATE="$(pwd)/templates/nginx.conf"
export CONFIG_OPEN_SEARCH_TEMPLATE="$(pwd)/templates/opensearch.xml"
# Configure 'opensearch.xml' with Librex configuration metadata, such as the encoding and the host that stores the site
# These configurations will replace the 'opensearch.xml' inside '.dockers/templates' for the best setup for your instance
export OPEN_SEARCH_TITLE="${OPEN_SEARCH_TITLE:-'LibreX'}"
@ -52,3 +57,12 @@ export CURLOPT_CUSTOMREQUEST="${CURLOPT_CUSTOMREQUEST:-'GET'}"
export CURLOPT_MAXREDIRS=${CURLOPT_MAXREDIRS:-5}
export CURLOPT_TIMEOUT=${CURLOPT_TIMEOUT:-18}
export CURLOPT_VERBOSE=${CURLOPT_VERBOSE:-false}
# The lines below will replace the environment variables in the templates with the corresponding variables listed above. To accomplish this, the GNU 'envsubst' package will be used
# Although not recommended (if you do not know what you are doing), you still have the option to add new substitution file templates using any required environment variables
[[ ! -s ${CONFIG_PHP_TEMPLATE} ]] && cat '$(pwd)/config.php' | envsubst | AwkTrim > ${CONFIG_PHP_TEMPLATE}
[[ ! -s ${CONFIG_NGINX_TEMPLATE} ]] && cat '$(pwd)/nginx.conf' | envsubst | AwkTrim > ${CONFIG_NGINX_TEMPLATE}
[[ ! -s ${CONFIG_OPEN_SEARCH_TEMPLATE} ]] && cat '$(pwd)/opensearch.xml' | envsubst | AwkTrim > ${CONFIG_OPEN_SEARCH_TEMPLATE}
# These shell functions will be available for use by any function calls
function AwkTrim() { awk '{$1=$1};1' }

View File

@ -1,2 +1,2 @@
#!/bin/sh
exec sleep infinity
exec sleep infinity

View File

@ -80,9 +80,9 @@ RUN chmod u+x "scripts/entrypoint.sh" &&\
# Compress Librex files, excluding the '.docker' folder containing scripts and the Dockerfile, using the previously downloaded zip package
# Delete all files in the root directory, except for the '.docker' and 'tmp' folders, which are created exclusively to be handled by Docker
RUN apk update; apk add zip --no-cache &&\
rm -rf .git; mkdir -p "tmp/zip" &&\
rm -rf .git; mkdir -p "{tmp,templates}/zip" &&\
zip -r "tmp/zip/librex.zip" . -x "scripts/**\*" "Dockerfile\*" &&\
find -maxdepth 1 ! -name "scripts" ! -name "tmp" ! -name "." -exec rm -rv {} \; &&\
find -maxdepth 1 ! -name "scripts" ! -name "tmp" ! -name "templates" ! -name "." -exec rm -rv {} \; &&\
apk del -r zip;
# Configures the container to be run as an executable.