now !
Some checks failed
Publish Docker Image / docker (push) Failing after 51s

This commit is contained in:
Lee 2024-09-28 18:13:30 +01:00
parent dea7a6647c
commit 2cbea618bd
2 changed files with 15 additions and 32 deletions

@ -5,10 +5,6 @@ FROM alpine:3.20.3 AS builder
ARG NGINX_VERSION="1.27.1" ARG NGINX_VERSION="1.27.1"
ARG PHP_VERSION="8.3" ARG PHP_VERSION="8.3"
# Print versions
RUN echo "NGINX_VERSION=${NGINX_VERSION}"
RUN echo "PHP_VERSION=${PHP_VERSION}"
# Install build dependencies and required tools # Install build dependencies and required tools
RUN apk update && apk upgrade && \ RUN apk update && apk upgrade && \
apk add --no-cache build-base pcre-dev openssl-dev zlib-dev linux-headers apk add --no-cache build-base pcre-dev openssl-dev zlib-dev linux-headers
@ -39,7 +35,7 @@ COPY ./docker/index.html /tmp/index.html
COPY ./public /tmp/public COPY ./public /tmp/public
# Stage 2: Create a smaller production image # Stage 2: Create a smaller production image
FROM alpine:3.20.3 FROM alpine:3.20.1
# Copy Nginx and PHP-FPM binaries and configurations from the builder stage # Copy Nginx and PHP-FPM binaries and configurations from the builder stage
COPY --from=builder /usr/local/nginx /usr/local/nginx COPY --from=builder /usr/local/nginx /usr/local/nginx
@ -52,13 +48,10 @@ COPY --from=builder /tmp/public /tmp/public
# Install runtime dependencies # Install runtime dependencies
RUN apk update && apk upgrade && \ RUN apk update && apk upgrade && \
apk add --no-cache php${PHP_VERSION} php${PHP_VERSION}-fpm php${PHP_VERSION}-gd pcre apk add --no-cache php81 php81-fpm php81-gd pcre
# Cleanup unnecessary files # Cleanup unnecessary files
RUN rm -rf /var/cache/apk/* RUN rm -rf /var/cache/apk/*
# Ensure signals are passed through
STOPSIGNAL SIGTERM
# Start server # Start server
CMD ["sh", "/start.sh"] CMD ["sh", "/start.sh"]

@ -23,15 +23,15 @@ else
fi fi
# Letting php know that we are running in docker # Letting php know that we are running in docker
echo "env[DOCKER] = true" >> /etc/php83/php-fpm.d/www.conf echo "env[DOCKER] = true" >> /etc/php81/php-fpm.d/www.conf
echo "clear_env = no" >> /etc/php83/php-fpm.d/www.conf echo "clear_env = no" >> /etc/php81/php-fpm.d/www.conf
# Create the directory for PHP socket # Create the directory for PHP socket
mkdir -p /run/php mkdir -p /run/php
# Set php-fpm to listen on socket # Set php-fpm to listen on socket
touch /run/php/php.sock touch /run/php/php.sock
sed -i 's/^listen = .*/listen = \/run\/php\/php.sock/' /etc/php83/php-fpm.d/www.conf sed -i 's/^listen = .*/listen = \/run\/php\/php.sock/' /etc/php81/php-fpm.d/www.conf
echo "Setting permissions for upload script" echo "Setting permissions for upload script"
chmod 777 /var/www/html/upload.php chmod 777 /var/www/html/upload.php
@ -39,31 +39,21 @@ chmod 777 /var/www/html/upload.php
echo "Setting max upload size to ${MAX_UPLOAD_SIZE}" echo "Setting max upload size to ${MAX_UPLOAD_SIZE}"
# Set max upload size for php # Set max upload size for php
sed -i "s/^upload_max_filesize = .*/upload_max_filesize = ${MAX_UPLOAD_SIZE}/" /etc/php83/php.ini sed -i "s/^upload_max_filesize = .*/upload_max_filesize = ${MAX_UPLOAD_SIZE}/" /etc/php81/php.ini
sed -i "s/^post_max_size = .*/post_max_size = ${MAX_UPLOAD_SIZE}/" /etc/php83/php.ini sed -i "s/^post_max_size = .*/post_max_size = ${MAX_UPLOAD_SIZE}/" /etc/php81/php.ini
# Set max upload size for nginx # Set max upload size for nginx
sed -i "s/client_max_body_size 500M;/client_max_body_size ${MAX_UPLOAD_SIZE};/" /etc/nginx/nginx.conf sed -i "s/client_max_body_size 500M;/client_max_body_size ${MAX_UPLOAD_SIZE};/" /etc/nginx/nginx.conf
# Function to handle signal forwarding and service startup function start() {
function start_services() { echo "Starting PHP & Nginx"
echo "Starting PHP-FPM..." php-fpm81 &&
php-fpm83 --nodaemonize && chmod 777 /run/php/php.sock & chmod 777 /run/php/php.sock &&
PHP_FPM_PID=$! /usr/local/sbin/nginx -g 'daemon off;'
echo "Starting Nginx..."
nginx -g 'daemon off;' &
NGINX_PID=$!
# Wait for both processes to finish
wait $PHP_FPM_PID $NGINX_PID
} }
# Trap SIGTERM and SIGINT and forward to PHP-FPM and Nginx # Start Nginx and retry if it fails
trap "echo 'Stopping services...'; kill -TERM $PHP_FPM_PID $NGINX_PID" SIGTERM SIGINT until start; do
echo "Nginx failed to start, retrying in 5 seconds..."
# Start the services and retry if Nginx fails
until start_services; do
echo "Nginx or PHP-FPM failed to start, retrying in 5 seconds..."
sleep 5 sleep 5
done done