chore: to create Dockerfile modules and break up the procedure into smaller, step-by-step files instead of one large Dockerfile

This commit is contained in:
Junior L. Botelho (JLB) 2023-02-11 23:08:53 -03:00
parent 779cdf0da3
commit 48b9863e3c
No known key found for this signature in database
GPG Key ID: 6A25840754F2A524
11 changed files with 105 additions and 111 deletions

View File

@ -1,4 +1,4 @@
# syntax=docker/dockerfile:1
# syntax = edrevo/dockerfile-plus
ARG VERSION="3.17"
FROM alpine:${VERSION} AS runner
WORKDIR "/home/librex"
@ -23,69 +23,18 @@ ARG DOCKER_SCRIPTS="docker"
# See more: https://en.wikipedia.org/wiki/List_of_tz_database_time_zones#List
ENV TZ="America/New_York"
# 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
ENV OPEN_SEARCH_TITLE="LibreX"
ENV OPEN_SEARCH_DESCRIPTION="Framework and javascript free privacy respecting meta search engine"
ENV OPEN_SEARCH_ENCODING="UTF-8"
ENV OPEN_SEARCH_LONG_NAME="LibreX Search"
ENV OPEN_SEARCH_HOST="http://localhost:80"
# Replace the 'config.php' script, which contains the most common search engine configurations, with these environment setups
# These environment setups can be found in 'config.php', and the default configurations can be useful for most use cases
ENV CONFIG_GOOGLE_DOMAIN=".com"
ENV CONFIG_GOOGLE_LANGUAGUE="en"
ENV CONFIG_INVIDIOUS_INSTANCE="invidious.namazso.eu"
ENV CONFIG_HIDDEN_SERVICE_SEARCH=false
ENV CONFIG_DISABLE_BITTORRENT_SEARCH=false
ENV CONFIG_BITTORRENT_TRACKERS="&tr=http://nyaa.tracker.wf:7777/announce&tr=udp://open.stealth.si:80/announce&tr=udp://tracker.opentrackr.org:1337/announce&tr=udp://exodus.desync.com:6969/announce&tr=udp://tracker.torrent.eu.org:451/announce"
# Supported apps integration configuration. These empty spaces can be set up using free hosts as pointers
# A particular example is using the "https://yewtu.be" or a self-hosted host to integrate the invidious app to librex
ENV APP_INVIDIOUS=""
ENV APP_BIBLIOGRAM=""
ENV APP_RIMGO=""
ENV APP_SCRIBE=""
ENV APP_LIBRARIAN=""
ENV APP_GOTHUB=""
ENV APP_NITTER=""
ENV APP_LIBREREDDIT=""
ENV APP_PROXITOK=""
ENV APP_WIKILESS=""
ENV APP_QUETRE=""
ENV APP_LIBREMDB=""
ENV APP_BREEZEWIKI=""
ENV APP_ANONYMOUS_OVERFLOW=""
# GNU/Curl configurations. Leave 'CURLOPT_PROXY' blank whether you don't need to use a proxy for requests
# Generally, a proxy is needed when your IP address is blocked by search engines in response to multiple requests within a short time frame. In these cases, it is recommended to use rotating proxies
ENV CURLOPT_PROXY_ENABLED=false
ENV CURLOPT_PROXY=""
ENV CURLOPT_RETURNTRANSFER=true
ENV CURLOPT_ENCODING=""
ENV CURLOPT_USERAGENT="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36"
ENV CURLOPT_CUSTOMREQUEST="GET"
ENV CURLOPT_MAXREDIRS=5
ENV CURLOPT_TIMEOUT=18
ENV CURLOPT_VERBOSE=false
# Include docker scripts, docker images, and the 'GNU License' in the Librex container
ADD "${DOCKER_SCRIPTS}/*" "scripts/"
ADD "." "."
ADD "." "/home/librex"
# Set permissions for script files as executable scripts inside 'docker/scripts' directory
RUN chmod u+x "scripts/entrypoint.sh" &&\
chmod u+x "scripts/prepare.sh"
RUN chmod u+x "${DOCKER_SCRIPTS}/php/prepare.sh" &&\
chmod u+x "${DOCKER_SCRIPTS}/server/prepare.sh" &&\
chmod u+x "${DOCKER_SCRIPTS}/entrypoint.sh" &&\
chmod u+x "${DOCKER_SCRIPTS}/attributes.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 abuild-rootbld --no-cache &&\
rm -rf .git; mkdir -p "tmp/zip"; mkdir -p "scripts/tmp" &&\
zip -r "tmp/zip/librex.zip" . -x "scripts/**\*" "Dockerfile\*" &&\
find -maxdepth 1 ! -name "scripts" ! -name "tmp" ! -name "templates" ! -name "." -exec rm -rv {} \; &&\
sh -c 'scripts/prepare.sh' && apk del -r zip abuild-rootbld
# The following lines import all Dockerfiles from other folders so that they can be built together in the final build
INCLUDE+ docker/php/php.dockerfile
INCLUDE+ docker/server/nginx.dockerfile
# Configures the container to be run as an executable.
ENTRYPOINT ["/bin/sh", "-c", "scripts/entrypoint.sh --images=nginx/php"]
ENTRYPOINT ["/bin/sh", "-c", "docker/entrypoint.sh"]

24
docker/prepare.sh → docker/attributes.sh Normal file → Executable file
View File

@ -3,22 +3,18 @@
# 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)/scripts/tmp/config.php"
export CONFIG_NGINX_TEMPLATE="$(pwd)/scripts/tmp/nginx.conf"
export CONFIG_OPEN_SEARCH_TEMPLATE="$(pwd)/scripts/tmp/opensearch.xml"
export CONFIG_PHP_TEMPLATE="$(pwd)/config.php"
export CONFIG_OPEN_SEARCH_TEMPLATE="$(pwd)/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'}"
export OPEN_SEARCH_DESCRIPTION="${OPEN_SEARCH_DESCRIPTION:-'Framework and javascript free privacy respecting meta search engine'}"
export OPEN_SEARCH_ENCODING="${OPEN_SEARCH_ENCODING:-'UTF-8'}"
export OPEN_SEARCH_LONG_NAME="${OPEN_SEARCH_LONG_NAME:-'LibreX Search'}"
export OPEN_SEARCH_HOST="${OPEN_SEARCH_HOST:-'http://localhost:80'}"
export OPEN_SEARCH_TITLE=${OPEN_SEARCH_TITLE:-"LibreX"}
export OPEN_SEARCH_DESCRIPTION=${OPEN_SEARCH_DESCRIPTION:-"Framework and javascript free privacy respecting meta search engine"}
export OPEN_SEARCH_ENCODING=${OPEN_SEARCH_ENCODING:-"UTF-8"}
export OPEN_SEARCH_LONG_NAME=${OPEN_SEARCH_LONG_NAME:-"LibreX Search"}
export OPEN_SEARCH_HOST=${OPEN_SEARCH_HOST:-"http://localhost:80"}
# Replace the 'config.php' script, which contains the most common search engine configurations, with these environment setups
# These environment setups can be found in 'config.php', and the default configurations can be useful for most use cases
@ -60,9 +56,3 @@ 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 '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};

25
docker/entrypoint.sh Normal file → Executable file
View File

@ -1,27 +1,2 @@
#!/bin/sh
# You can split the value of the --images argument using the IFS (Internal Field Separator) variable and the read command,
# and then iterate over the resulting parts using a for loop.
# See more: https://unix.stackexchange.com/questions/184863/what-is-the-meaning-of-ifs-n-in-bash-scripting
IFS='=' read -ra ARGUMENT_PARTS <<< "$1"
IFS='/' read -ra IMAGE_PARTS <<< "${ARGUMENT_PARTS[1]}"
# The block below will use iteration to either build the necessary Docker image or simply run the required containers using the provided entrypoint arguments
# First, the image will be created, and then the container will be run using the image that was generated
for IMAGE in "${IMAGE_PARTS[@]}"
do
# The following command will display the IDs of Docker images filtered by name
# See more: https://docs.docker.com/engine/reference/commandline/images/
if [ ! "$(docker images -aq --filter 'reference=${IMAGE}')" ]; then
docker buildx build -f scripts/${IMAGE}.dockerfile -t ${IMAGE}:latest scripts/
fi
# The following command will achieve the same result as the previous command, but for containers rather than images
# See more: https://docs.docker.com/engine/reference/commandline/ps/
if [ ! "$(docker ps -aq --filter name=${IMAGE})" ]; then
[ "$(docker ps -aq --filter status=exited -f name=${IMAGE})" ] && docker rm ${IMAGE}
docker run -d --name ${IMAGE} ${IMAGE}:latest
fi
done
exec sleep infinity

View File

@ -1,4 +0,0 @@
# syntax=docker/dockerfile:1
ARG VERSION="3.17"
FROM alpine:${VERSION} AS builder
WORKDIR "/home/librex"

View File

@ -1,4 +0,0 @@
# syntax=docker/dockerfile:1
ARG VERSION="3.17"
FROM alpine:${VERSION} AS builder
WORKDIR "/home/librex"

60
docker/php/php.dockerfile Normal file
View File

@ -0,0 +1,60 @@
# Set this argument during build time to indicate that the path is for php's www.conf
ARG WWW_CONFIG="/etc/php7/php-fpm.d/www.conf"
# 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
ENV OPEN_SEARCH_TITLE="LibreX"
ENV OPEN_SEARCH_DESCRIPTION="Framework and javascript free privacy respecting meta search engine"
ENV OPEN_SEARCH_ENCODING="UTF-8"
ENV OPEN_SEARCH_LONG_NAME="LibreX Search"
ENV OPEN_SEARCH_HOST="http://localhost:80"
# Replace the 'config.php' script, which contains the most common search engine configurations, with these environment setups
# These environment setups can be found in 'config.php', and the default configurations can be useful for most use cases
ENV CONFIG_GOOGLE_DOMAIN=".com"
ENV CONFIG_GOOGLE_LANGUAGUE="en"
ENV CONFIG_INVIDIOUS_INSTANCE="invidious.namazso.eu"
ENV CONFIG_HIDDEN_SERVICE_SEARCH=false
ENV CONFIG_DISABLE_BITTORRENT_SEARCH=false
ENV CONFIG_BITTORRENT_TRACKERS="&tr=http://nyaa.tracker.wf:7777/announce&tr=udp://open.stealth.si:80/announce&tr=udp://tracker.opentrackr.org:1337/announce&tr=udp://exodus.desync.com:6969/announce&tr=udp://tracker.torrent.eu.org:451/announce"
# Supported apps integration configuration. These empty spaces can be set up using free hosts as pointers
# A particular example is using the "https://yewtu.be" or a self-hosted host to integrate the invidious app to librex
ENV APP_INVIDIOUS=""
ENV APP_BIBLIOGRAM=""
ENV APP_RIMGO=""
ENV APP_SCRIBE=""
ENV APP_LIBRARIAN=""
ENV APP_GOTHUB=""
ENV APP_NITTER=""
ENV APP_LIBREREDDIT=""
ENV APP_PROXITOK=""
ENV APP_WIKILESS=""
ENV APP_QUETRE=""
ENV APP_LIBREMDB=""
ENV APP_BREEZEWIKI=""
ENV APP_ANONYMOUS_OVERFLOW=""
# GNU/Curl configurations. Leave 'CURLOPT_PROXY' blank whether you don't need to use a proxy for requests
# Generally, a proxy is needed when your IP address is blocked by search engines in response to multiple requests within a short time frame. In these cases, it is recommended to use rotating proxies
ENV CURLOPT_PROXY_ENABLED=false
ENV CURLOPT_PROXY=""
ENV CURLOPT_RETURNTRANSFER=true
ENV CURLOPT_ENCODING=""
ENV CURLOPT_USERAGENT="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36"
ENV CURLOPT_CUSTOMREQUEST="GET"
ENV CURLOPT_MAXREDIRS=5
ENV CURLOPT_TIMEOUT=18
ENV CURLOPT_VERBOSE=false
# Install PHP-FPM using Alpine's package manager, apk
# Configure PHP-FPM to listen on a Unix socket instead of a TCP port, which is more secure and efficient
RUN apk add php7 php7-fpm abuild-rootbld --no-cache --repository=http://dl-cdn.alpinelinux.org/alpine/edge/testing &&\
sed -i 's/^\s*listen = 127.0.0.1:9000/listen = \/run\/php-fpm\/php-fpm.sock/' ${WWW_CONFIG} &&\
sed -i 's/^\s*;\s*listen.owner = nobody/listen.owner = nginx/' ${WWW_CONFIG} &&\
sed -i 's/^\s*;\s*listen.group = nobody/listen.group = nginx/' ${WWW_CONFIG} &&\
sed -i 's/^\s*;\s*listen.mode = 0660/listen.mode = 0660/' ${WWW_CONFIG}
RUN echo $(pwd)
RUN docker/php/prepare.sh

View File

@ -0,0 +1,9 @@
#!/bin/sh
# Load all environment variables from 'attributes.sh' using the command 'source /path/attributes.sh'
source "docker/attributes.sh"
# 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 'docker/php/config.php' | envsubst | AwkTrim > ${CONFIG_PHP_TEMPLATE};
[[ ! -s ${CONFIG_OPEN_SEARCH_TEMPLATE} ]] && cat 'docker/php/opensearch.xml' | envsubst | AwkTrim > ${CONFIG_OPEN_SEARCH_TEMPLATE};

18
docker/server/nginx.conf Normal file
View File

@ -0,0 +1,18 @@
server {
listen 80;
server_name ${OPEN_SEARCH_HOST} localhost;
root /var/www/html;
index index.php;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
fastcgi_pass unix:/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}

View File

@ -0,0 +1 @@
RUN echo "Hello Nginx"

0
docker/nginx/prepare.sh → docker/server/prepare.sh Normal file → Executable file
View File