This commit is contained in:
parent
dea7a6647c
commit
2cbea618bd
11
Dockerfile
11
Dockerfile
@ -5,10 +5,6 @@ FROM alpine:3.20.3 AS builder
|
||||
ARG NGINX_VERSION="1.27.1"
|
||||
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
|
||||
RUN apk update && apk upgrade && \
|
||||
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
|
||||
|
||||
# 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 --from=builder /usr/local/nginx /usr/local/nginx
|
||||
@ -52,13 +48,10 @@ COPY --from=builder /tmp/public /tmp/public
|
||||
|
||||
# Install runtime dependencies
|
||||
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
|
||||
RUN rm -rf /var/cache/apk/*
|
||||
|
||||
# Ensure signals are passed through
|
||||
STOPSIGNAL SIGTERM
|
||||
|
||||
# Start server
|
||||
CMD ["sh", "/start.sh"]
|
||||
|
@ -23,15 +23,15 @@ else
|
||||
fi
|
||||
|
||||
# Letting php know that we are running in docker
|
||||
echo "env[DOCKER] = true" >> /etc/php83/php-fpm.d/www.conf
|
||||
echo "clear_env = no" >> /etc/php83/php-fpm.d/www.conf
|
||||
echo "env[DOCKER] = true" >> /etc/php81/php-fpm.d/www.conf
|
||||
echo "clear_env = no" >> /etc/php81/php-fpm.d/www.conf
|
||||
|
||||
# Create the directory for PHP socket
|
||||
mkdir -p /run/php
|
||||
|
||||
# Set php-fpm to listen on socket
|
||||
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"
|
||||
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}"
|
||||
|
||||
# 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/^post_max_size = .*/post_max_size = ${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/php81/php.ini
|
||||
|
||||
# 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
|
||||
|
||||
# Function to handle signal forwarding and service startup
|
||||
function start_services() {
|
||||
echo "Starting PHP-FPM..."
|
||||
php-fpm83 --nodaemonize && chmod 777 /run/php/php.sock &
|
||||
PHP_FPM_PID=$!
|
||||
|
||||
echo "Starting Nginx..."
|
||||
nginx -g 'daemon off;' &
|
||||
NGINX_PID=$!
|
||||
|
||||
# Wait for both processes to finish
|
||||
wait $PHP_FPM_PID $NGINX_PID
|
||||
function start() {
|
||||
echo "Starting PHP & Nginx"
|
||||
php-fpm81 &&
|
||||
chmod 777 /run/php/php.sock &&
|
||||
/usr/local/sbin/nginx -g 'daemon off;'
|
||||
}
|
||||
|
||||
# Trap SIGTERM and SIGINT and forward to PHP-FPM and Nginx
|
||||
trap "echo 'Stopping services...'; kill -TERM $PHP_FPM_PID $NGINX_PID" SIGTERM SIGINT
|
||||
|
||||
# Start the services and retry if Nginx fails
|
||||
until start_services; do
|
||||
echo "Nginx or PHP-FPM failed to start, retrying in 5 seconds..."
|
||||
# Start Nginx and retry if it fails
|
||||
until start; do
|
||||
echo "Nginx failed to start, retrying in 5 seconds..."
|
||||
sleep 5
|
||||
done
|
Loading…
x
Reference in New Issue
Block a user