Updated and simplified the docker building setup

This commit is contained in:
nohoster 2023-08-29 19:49:11 -06:00
parent 1c4e9eafde
commit f9430475bf
11 changed files with 43 additions and 133 deletions

10
.dockerignore Normal file
View File

@ -0,0 +1,10 @@
.github/
.git/
.gitignore
.dockerignore
config.php.example
docker-compose.yml
Dockerfile
opensearch.xml.example
README.md
docker-old/

View File

@ -1,10 +1,10 @@
# syntax = edrevo/dockerfile-plus
ARG VERSION="3.18"
FROM alpine:${VERSION} AS librey
FROM alpine:3.18
WORKDIR "/var/www/html"
ADD "." "."
# Docker metadata contains information about the maintainer, such as the name, repository, and support email
# Please add any necessary information or correct any incorrect information
# See more: https://docs.docker.com/config/labels-custom-metadata/
LABEL name="LibreY" \
description="Framework and javascript free privacy respecting meta search engine" \
@ -18,28 +18,25 @@ LABEL name="LibreY" \
# Change or add new arguments to customize the image generated by 'docker build' command
ARG DOCKER_SCRIPTS="docker"
ARG NGINX_PORT=8080
# Set this argument during build time to indicate that the path is for php's www.conf
ARG WWW_CONFIG="/etc/php82/php-fpm.d/www.conf"
# Customize the environment during both execution and build time by modifying the environment variables added to the container's shell
# When building your image, make sure to set the 'TZ' environment variable to your desired time zone location, for example 'America/Sao_Paulo'
# See more: https://en.wikipedia.org/wiki/List_of_tz_database_time_zones#List
ENV TZ="America/New_York"
RUN apk add gettext --no-cache
# Install required packages
RUN apk add gettext php82 php82-fpm php82-dom php82-curl php82-json php82-apcu nginx --no-cache
# 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
# Include docker scripts, docker images, and the 'GNU License' in the LibreY container
ADD "." "/var/www/html"
# Set permissions for script files as executable scripts inside 'docker/scripts' directory
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"
# Configure PHP-FPM to listen on a Unix socket instead of a TCP port, which is more secure and efficient
RUN touch /run/php-fpm82.sock && chown nginx:nginx "/run/php-fpm82.sock"
RUN sed -i 's/^\s*listen = 127.0.0.1:9000/listen = \/run\/php-fpm82.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}
EXPOSE ${NGINX_PORT}
# Configures the container to be run as an executable.
ENTRYPOINT ["/bin/sh", "-c", "docker/entrypoint.sh"]
ENTRYPOINT ["/bin/sh", "-c", "docker/entrypoint.sh"]

View File

@ -1,10 +1,7 @@
#!/bin/sh
# Due to an issue with Docker's 'CMD' directive, the following scripts are not executing as expected.
# This workaround has been implemented to resolve the issue for now
sh "docker/php/prepare.sh"
sh "docker/server/prepare.sh"
/bin/sh -c docker/env-substitution.sh
/bin/sh -c /usr/sbin/php-fpm8
/bin/sh -c /usr/sbin/php-fpm82
exec nginx -g "daemon off;"

View File

@ -1,23 +1,24 @@
#!/bin/sh
echo "[PREPARE] docker/server/prepare.sh'"
# Load all environment variables from 'attributes.sh' using the command 'source /path/attributes.sh'
source "docker/attributes.sh"
# This condition creates the Unix socket if 'php-fpm8.sock' does not already exist.
# This fixes an issue where Nginx starts but does not serve content
if [ ! -d "/run/php8" ] || [ ! -S "/run/php8/php-fpm8.sock" ]; then
mkdir "/run/php8"
touch "/run/php8/php-fpm8.sock"
chmod 660 "/run/php8/php-fpm8.sock"
chown nginx:nginx "/run/php8/php-fpm8.sock"
fi
# 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
# The lines below will replace the environment variables in the templates with the corresponding variables listed above if the config file is not yet provided. 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 > ${CONFIG_PHP_TEMPLATE};
[[ ! -s ${CONFIG_OPEN_SEARCH_TEMPLATE} ]] && cat 'docker/php/opensearch.xml' | envsubst > ${CONFIG_OPEN_SEARCH_TEMPLATE};
[[ ! -s ${CONFIG_PHP_TEMPLATE} ]] && cat 'docker/config.php' | envsubst > ${CONFIG_PHP_TEMPLATE};
[[ ! -s ${CONFIG_OPEN_SEARCH_TEMPLATE} ]] && cat 'docker/opensearch.xml' | envsubst > ${CONFIG_OPEN_SEARCH_TEMPLATE};
export OPEN_SEARCH_HOST_FOR_NGINX="$(echo "${OPEN_SEARCH_HOST}" | cut -d "/" -f 3 | cut -d ":" -f 1)"
if [[ ! -s ${CONFIG_NGINX_TEMPLATE} ]]; then
cat 'docker/nginx.conf' | envsubst '${OPEN_SEARCH_HOST_FOR_NGINX}' > ${CONFIG_NGINX_TEMPLATE};
mv "docker/fastcgi.conf" /etc/nginx/fastcgi.conf
chown nginx:nginx "/etc/nginx/fastcgi.conf"
chown nginx:nginx "/etc/nginx/http.d/librey.conf"
fi
# If it is empty or proxy is not enabled, we are using sed to delete
# any line that contains the string 'CURLOPT_PROXY' or 'CURLOPT_PROXYTYPE'

View File

@ -10,7 +10,7 @@ server {
}
location ~ \.php$ {
fastcgi_pass unix:/run/php8/php-fpm8.sock;
fastcgi_pass unix:/run/php-fpm82.sock;
fastcgi_index index.php;
include fastcgi.conf;
}

View File

@ -1,65 +0,0 @@
# Set this argument during build time to indicate that the path is for php's www.conf
ARG WWW_CONFIG="/etc/php8/php-fpm.d/www.conf"
# Configure 'opensearch.xml' with librey 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="LibreY"
ENV OPEN_SEARCH_DESCRIPTION="Framework and javascript free privacy respecting meta search engine"
ENV OPEN_SEARCH_ENCODING="UTF-8"
ENV OPEN_SEARCH_LONG_NAME="LibreY search"
ENV OPEN_SEARCH_HOST="http://127.0.0.1:${NGINX_PORT}"
# 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_LANGUAGE_SITE="en"
ENV CONFIG_GOOGLE_LANGUAGE_RESULTS="en"
ENV CONFIG_GOOGLE_NUMBER_OF_RESULTS="10"
ENV CONFIG_INSTANCE_FALLBACK=true
ENV CONFIG_INVIDIOUS_INSTANCE="https://invidious.snopyta.org"
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 librey
ENV APP_INVIDIOUS=""
ENV APP_RIMGO=""
ENV APP_SCRIBE=""
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=""
ENV APP_SUDS=""
ENV APP_BIBLIOREADS=""
# Preferred search engines.
ENV CONFIG_TEXT_SEARCH_ENGINE="google"
# 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_PROXYTYPE="CURLPROXY_HTTP"
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=true
# 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 php8 php8-fpm php8-dom php8-curl php8-json php8-apcu --no-cache --repository=http://dl-cdn.alpinelinux.org/alpine/edge/testing &&\
sed -i 's/^\s*listen = 127.0.0.1:9000/listen = \/run\/php8\/php-fpm8.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}
CMD [ "/bin/sh", "-c", "docker/php/prepare.sh" ]

View File

@ -1,9 +0,0 @@
# Install Nginx with FastCGI enabled, optimizing its performance for serving content
RUN apk add nginx
# Forward request and error logs to docker log collector
# RUN ln -sf /dev/stdout /var/log/nginx/access.log &&\
# ln -sf /dev/stderr /var/log/nginx/error.log
# After executing the 'docker run' command, run the 'prepare.sh' script
CMD [ "/bin/sh", "-c", "docker/server/prepare.sh" ]

View File

@ -1,21 +0,0 @@
#!/bin/sh
echo "[PREPARE] docker/server/prepare.sh'"
# Load all environment variables from 'attributes.sh' using the command 'source /path/attributes.sh'
source "docker/attributes.sh"
export OPEN_SEARCH_HOST_FOR_NGINX="$(echo "${OPEN_SEARCH_HOST}" | cut -d "/" -f 3 | cut -d ":" -f 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
if [[ ! -s ${CONFIG_NGINX_TEMPLATE} ]]; then
cp "docker/server/fastcgi.conf" /etc/nginx/fastcgi.conf
cp "docker/server/nginx.conf" /etc/nginx/http.d/librey.conf
# To address issues with 'nginx.conf', the following lines will ensure that these configurations remain executable
chmod u+x "/etc/nginx/fastcgi.conf"
chmod u+x "/etc/nginx/http.d/librey.conf"
cat 'docker/server/nginx.conf' | envsubst '${OPEN_SEARCH_HOST_FOR_NGINX}' > ${CONFIG_NGINX_TEMPLATE};
fi