feat: setup custom webdevops Dockerfile with explicit PHP 8.4 Zemailnator extensions and configs

This commit is contained in:
idevakk
2026-03-01 08:36:49 +05:30
parent 0aed57bc2c
commit b30da6614a
4 changed files with 107 additions and 41 deletions

View File

@@ -1,58 +1,68 @@
FROM php:8.4-fpm-alpine # 1. Use the specific PHP 8.4 Alpine image
FROM webdevops/php-nginx:8.4-alpine
# Install extension installer # 2. Environment Configuration
ENV WEB_DOCUMENT_ROOT=/code/public
ENV APP_ENV=production
ENV COMPOSER_ALLOW_SUPERUSER=1
ENV COMPOSER_PROCESS_TIMEOUT=2000
# 3. Install System Dependencies & Extensions
COPY --from=mlocati/php-extension-installer /usr/bin/install-php-extensions /usr/local/bin/ COPY --from=mlocati/php-extension-installer /usr/bin/install-php-extensions /usr/local/bin/
# Install system dependencies
RUN apk add --no-cache \ RUN apk add --no-cache \
git \
curl \
zip \
unzip \
nginx \
supervisor \
nodejs \ nodejs \
npm \ npm \
bash sqlite \
shadow \
&& install-php-extensions pdo_sqlite mongodb redis imap pdo_mysql
# Install PHP extensions # 4. Copy Custom Configs
RUN install-php-extensions pdo_mysql mbstring exif pcntl bcmath gd intl imap redis zip COPY ./dockerizer/php.ini /opt/docker/etc/php/php.ini
COPY ./dockerizer/vhost.conf /opt/docker/etc/nginx/vhost.conf
COPY ./dockerizer/supervisor.laravel.conf /opt/docker/etc/supervisor.d/laravel.conf
# Install Composer # 5. Set Working Directory
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer WORKDIR /code
# Set working directory # CRITICAL FIX: Transfer ownership of /code to the 'application' user
WORKDIR /var/www # WORKDIR creates folders as 'root' by default, which blocks Composer later.
RUN chown application:application /code
# Copy existing application directory contents # 6. Install PHP Dependencies (Layered)
COPY . /var/www COPY --chown=application:application composer.json composer.lock ./
# Install PHP/Node dependencies and build frontend USER application
RUN composer install --no-interaction --no-dev --optimize-autoloader \ RUN composer install --no-interaction --no-scripts --no-autoloader --prefer-dist --no-dev
&& npm install \
&& npm run build \
&& npm cache clean --force
# Nginx config # 7. Install Node Dependencies
# Alpine uses http.d instead of sites-available COPY --chown=application:application package.json package-lock.json* ./
COPY .docker/nginx.conf /etc/nginx/http.d/default.conf RUN npm install
# Supervisor config # 8. Copy Application Code
RUN mkdir -p /etc/supervisor/conf.d /var/log/supervisor COPY --chown=application:application . .
COPY .docker/supervisord.conf /etc/supervisor/conf.d/supervisord.conf
# Set directory permissions # 9. Final Builds
RUN mkdir -p /run/nginx /var/lib/nginx \ RUN composer dump-autoload --optimize && \
&& chown -R www-data:www-data /var/www \ composer run-script post-root-package-install && \
&& chown -R www-data:www-data /var/lib/nginx \ php artisan package:discover --ansi
&& chown -R www-data:www-data /run/nginx \
&& chmod -R 775 /var/www/storage /var/www/bootstrap/cache
EXPOSE 80 RUN npm run build
# Configure entrypoint # 10. Runtime Initialization Script
COPY .docker/entrypoint.sh /usr/local/bin/entrypoint.sh # This runs when the container STARTS, not when it builds.
RUN chmod +x /usr/local/bin/entrypoint.sh USER root
# Start Supervisor RUN echo '#!/bin/bash' > /opt/docker/provision/entrypoint.d/99-init-laravel.sh && \
CMD ["/usr/local/bin/entrypoint.sh"] echo 'set -e' >> /opt/docker/provision/entrypoint.d/99-init-laravel.sh && \
# 1. Fix Permissions \
echo 'echo "Fixing storage permissions..."' >> /opt/docker/provision/entrypoint.d/99-init-laravel.sh && \
echo 'mkdir -p /code/storage/framework/{views,cache,sessions} /code/bootstrap/cache' >> /opt/docker/provision/entrypoint.d/99-init-laravel.sh && \
echo 'chown -R application:application /code/storage /code/bootstrap/cache' >> /opt/docker/provision/entrypoint.d/99-init-laravel.sh && \
echo 'chmod -R 775 /code/storage /code/bootstrap/cache' >> /opt/docker/provision/entrypoint.d/99-init-laravel.sh && \
# 2. Run Optimization (As the application user) \
echo 'echo "Running Laravel Optimizations..."' >> /opt/docker/provision/entrypoint.d/99-init-laravel.sh && \
echo 'su -s /bin/sh application -c "php artisan optimize"' >> /opt/docker/provision/entrypoint.d/99-init-laravel.sh && \
# 3. Cache Views (Optional but recommended for production) \
echo 'su -s /bin/sh application -c "php artisan view:cache"' >> /opt/docker/provision/entrypoint.d/99-init-laravel.sh && \
chmod +x /opt/docker/provision/entrypoint.d/99-init-laravel.sh

6
dockerizer/php.ini Normal file
View File

@@ -0,0 +1,6 @@
date.time = UTC
display_errors = Off
memory_limit = 128M
max_execution_time = 60
post_max_size = 32M
upload_max_filesize = 16M

View File

@@ -0,0 +1,25 @@
[program:laravel-worker]
process_name=%(program_name)s_%(process_num)02d
command=php /code/artisan queue:work --sleep=3 --tries=3 --max-time=3600
autostart=true
autorestart=true
stopasgroup=true
killasgroup=true
user=application
numprocs=1
redirect_stderr=true
stdout_logfile=/docker.stdout
stdout_logfile_maxbytes=0
[program:laravel-scheduler]
process_name=%(program_name)s_%(process_num)02d
command=php /code/artisan schedule:work
autostart=true
autorestart=true
stopasgroup=true
killasgroup=true
user=application
numprocs=1
redirect_stderr=true
stdout_logfile=/docker.stdout
stdout_logfile_maxbytes=0

25
dockerizer/vhost.conf Normal file
View File

@@ -0,0 +1,25 @@
server {
listen 80 default_server;
server_name _;
root "/code/public";
index index.php;
client_max_body_size 50m;
access_log /docker.stdout;
error_log /docker.stderr warn;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_read_timeout 600;
}
}