LibreY

- privacy respecting meta search engine
git clone git://git.acid.vegas/LibreY.git
Log | Files | Refs | Archive | README | LICENSE

commit f9430475bfb6e99f1267a3ff65a5a7fe47590ed8
parent 1c4e9eafde7ca863b88b6794c243d7f84377aea0
Author: nohoster <admin@nohost.network>
Date: Tue, 29 Aug 2023 19:49:11 -0600

Updated and simplified the docker building setup

Diffstat:
A.dockerignore | 11+++++++++++
MDockerfile | 34++++++++++++++++------------------
Rdocker/php/config.php -> docker/config.php | 0
Mdocker/entrypoint.sh | 7++-----
Adocker/env-substitution.sh | 29+++++++++++++++++++++++++++++
Rdocker/server/fastcgi.conf -> docker/fastcgi.conf | 0
Adocker/nginx.conf | 17+++++++++++++++++
Rdocker/php/opensearch.xml -> docker/opensearch.xml | 0
Ddocker/php/php.dockerfile | 65-----------------------------------------------------------------
Ddocker/php/prepare.sh | 28----------------------------
Ddocker/server/nginx.conf | 17-----------------
Ddocker/server/nginx.dockerfile | 9---------
Ddocker/server/prepare.sh | 21---------------------

13 files changed, 75 insertions(+), 163 deletions(-)

diff --git a/.dockerignore b/.dockerignore
@@ -0,0 +1,10 @@
+.github/
+.git/
+.gitignore
+.dockerignore
+config.php.example
+docker-compose.yml
+Dockerfile
+opensearch.xml.example
+README.md
+docker-old/
+\ No newline at end of file
diff --git a/Dockerfile b/Dockerfile
@@ -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
-
-# 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"
+# Install required packages
+RUN apk add gettext php82 php82-fpm php82-dom php82-curl php82-json php82-apcu nginx --no-cache
 
-# 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"]
+\ No newline at end of file
diff --git a/docker/php/config.php b/docker/config.php
diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh
@@ -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;"
diff --git a/docker/env-substitution.sh b/docker/env-substitution.sh
@@ -0,0 +1,29 @@
+#!/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 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/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'
+# from the file 'config.php' defined on top of 'attributes.sh'
+if [[ -z "${CURLOPT_PROXY}" || "${CURLOPT_PROXY_ENABLED}" = false ]]; then
+    sed -i "/CURLOPT_PROXY/d" ${CONFIG_PHP_TEMPLATE};
+    sed -i "/CURLOPT_PROXYTYPE/d" ${CONFIG_PHP_TEMPLATE};
+fi
diff --git a/docker/server/fastcgi.conf b/docker/fastcgi.conf
diff --git a/docker/nginx.conf b/docker/nginx.conf
@@ -0,0 +1,17 @@
+server {
+    listen       8080;
+    server_name  ${OPEN_SEARCH_HOST_FOR_NGINX} localhost;
+
+    root   /var/www/html;
+    index  index.php;
+
+    location / {
+        try_files $uri $uri/ /index.php?$args;
+    }
+
+    location ~ \.php$ {
+        fastcgi_pass   unix:/run/php-fpm82.sock;
+        fastcgi_index  index.php;
+        include        fastcgi.conf;
+    }
+}
diff --git a/docker/php/opensearch.xml b/docker/opensearch.xml
diff --git a/docker/php/php.dockerfile b/docker/php/php.dockerfile
@@ -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" ]
diff --git a/docker/php/prepare.sh b/docker/php/prepare.sh
@@ -1,28 +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"
-
-# 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
-# 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};
-
-# 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'
-# from the file 'config.php' defined on top of 'attributes.sh'
-if [[ -z "${CURLOPT_PROXY}" || "${CURLOPT_PROXY_ENABLED}" = false ]]; then
-    sed -i "/CURLOPT_PROXY/d" ${CONFIG_PHP_TEMPLATE};
-    sed -i "/CURLOPT_PROXYTYPE/d" ${CONFIG_PHP_TEMPLATE};
-fi
diff --git a/docker/server/nginx.conf b/docker/server/nginx.conf
@@ -1,17 +0,0 @@
-server {
-    listen       8080;
-    server_name  ${OPEN_SEARCH_HOST_FOR_NGINX} localhost;
-
-    root   /var/www/html;
-    index  index.php;
-
-    location / {
-        try_files $uri $uri/ /index.php?$args;
-    }
-
-    location ~ \.php$ {
-        fastcgi_pass   unix:/run/php8/php-fpm8.sock;
-        fastcgi_index  index.php;
-        include        fastcgi.conf;
-    }
-}
diff --git a/docker/server/nginx.dockerfile b/docker/server/nginx.dockerfile
@@ -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" ]
diff --git a/docker/server/prepare.sh b/docker/server/prepare.sh
@@ -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