diff --git a/.docker/server/nginx.dockerfile b/.docker/nginx/nginx.dockerfile similarity index 100% rename from .docker/server/nginx.dockerfile rename to .docker/nginx/nginx.dockerfile diff --git a/.docker/server/nginx.entrypoint.sh b/.docker/nginx/nginx.entrypoint.sh similarity index 100% rename from .docker/server/nginx.entrypoint.sh rename to .docker/nginx/nginx.entrypoint.sh diff --git a/.docker/build.sh b/.docker/prepare.sh similarity index 87% rename from .docker/build.sh rename to .docker/prepare.sh index 3506025..eaa4dc0 100644 --- a/.docker/build.sh +++ b/.docker/prepare.sh @@ -8,9 +8,9 @@ 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" +export CONFIG_PHP_TEMPLATE="$(pwd)/scripts/tmp/config.php" +export CONFIG_NGINX_TEMPLATE="$(pwd)/scripts/tmp/nginx.conf" +export CONFIG_OPEN_SEARCH_TEMPLATE="$(pwd)/scripts/tmp/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 @@ -58,11 +58,11 @@ export CURLOPT_MAXREDIRS=${CURLOPT_MAXREDIRS:-5} export CURLOPT_TIMEOUT=${CURLOPT_TIMEOUT:-18} export CURLOPT_VERBOSE=${CURLOPT_VERBOSE:-false} +# These shell functions will be available for use by any function calls +function AwkTrim() { awk '{$1=$1};1'; } + # 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' } +[[ ! -s ${CONFIG_PHP_TEMPLATE} ]] && cat 'scripts/config.php' | envsubst | AwkTrim > ${CONFIG_PHP_TEMPLATE}; +[[ ! -s ${CONFIG_NGINX_TEMPLATE} ]] && cat 'scripts/nginx.conf' | envsubst | AwkTrim > ${CONFIG_NGINX_TEMPLATE}; +[[ ! -s ${CONFIG_OPEN_SEARCH_TEMPLATE} ]] && cat 'scripts/opensearch.xml' | envsubst | AwkTrim > ${CONFIG_OPEN_SEARCH_TEMPLATE}; diff --git a/Dockerfile b/Dockerfile index cd9aeea..2c9a093 100644 --- a/Dockerfile +++ b/Dockerfile @@ -73,17 +73,20 @@ ADD "." "." # Set permissions for script files as executable scripts inside 'docker/scripts' directory RUN chmod u+x "scripts/entrypoint.sh" &&\ - chmod u+x "scripts/build.sh" + chmod u+x "scripts/prepare.sh" # Add 'zip' package to generate a temporary compressed 'librex.zip' for best recursive copy between Docker images # Remove unnecessary folders and create a temporary folder that will contain the zip file created earlier # 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,templates}/zip" &&\ +RUN apk update; apk add zip abuild-rootbld --no-cache &&\ + rm -rf .git; mkdir -p "tmp/zip" &&\ zip -r "tmp/zip/librex.zip" . -x "scripts/**\*" "Dockerfile\*" &&\ find -maxdepth 1 ! -name "scripts" ! -name "tmp" ! -name "templates" ! -name "." -exec rm -rv {} \; &&\ - apk del -r zip; + sh -c 'scripts/prepare.sh' && apk del -r zip abuild-rootbld + +RUN docker build --no-cache -t 'nginx:latest' scripts/nginx/nginx.dockerfile &&\ + docker build --no-cache -t 'php:latest' scripts/php/php.dockerfile # Configures the container to be run as an executable. ENTRYPOINT ["/bin/sh", "-c", "scripts/entrypoint.sh"]