From 8b2b8af183d81d95f814d98a587f81e099984e31 Mon Sep 17 00:00:00 2001 From: "Junior L. Botelho (JLB)" Date: Sun, 12 Feb 2023 13:35:16 -0300 Subject: [PATCH] chore: fixed an issue that occurred when nginx did not have permissions on the 'php-fpm8.sock' file --- Dockerfile | 4 +--- docker/entrypoint.sh | 7 ++++++- docker/php/prepare.sh | 2 ++ docker/server/nginx.dockerfile | 2 ++ docker/server/prepare.sh | 8 ++++++-- 5 files changed, 17 insertions(+), 6 deletions(-) diff --git a/Dockerfile b/Dockerfile index 4e3738d..ffe38eb 100644 --- a/Dockerfile +++ b/Dockerfile @@ -36,10 +36,8 @@ RUN chmod u+x "${DOCKER_SCRIPTS}/php/prepare.sh" &&\ RUN apk add openrc abuild-rootbld --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 - -RUN apk del -r abuild-rootbld +INCLUDE+ docker/php/php.dockerfile EXPOSE ${NGINX_PORT} diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh index 175eddb..c8e20d6 100755 --- a/docker/entrypoint.sh +++ b/docker/entrypoint.sh @@ -1,6 +1,11 @@ #!/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" + service php-fpm8 start service nginx start -exec nginx -g daemon off; +exec nginx -g "daemon off;" diff --git a/docker/php/prepare.sh b/docker/php/prepare.sh index 0a84a12..34660ec 100755 --- a/docker/php/prepare.sh +++ b/docker/php/prepare.sh @@ -1,5 +1,7 @@ #!/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" diff --git a/docker/server/nginx.dockerfile b/docker/server/nginx.dockerfile index f3066f2..59c7a9f 100644 --- a/docker/server/nginx.dockerfile +++ b/docker/server/nginx.dockerfile @@ -1,3 +1,5 @@ +# Install Nginx with FastCGI enabled, optimizing its performance for serving content RUN apk add nginx +# 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 index 2120faf..93664e1 100755 --- a/docker/server/prepare.sh +++ b/docker/server/prepare.sh @@ -1,13 +1,17 @@ #!/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 + mkdir "/run/php8" + touch "/run/php8/php-fpm8.sock" + chmod 0660 "/run/php8/php-fpm8.sock" + chown nginx:nginx "/run/php8/php-fpm8.sock" fi export OPEN_SEARCH_HOST_FOR_NGINX="$(echo "${OPEN_SEARCH_HOST}" | cut -d "/" -f 3 | cut -d ":" -f 1)"