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/
# Install system dependencies
RUN apk add --no-cache \
git \
curl \
zip \
unzip \
nginx \
supervisor \
nodejs \
npm \
bash
sqlite \
shadow \
&& install-php-extensions pdo_sqlite mongodb redis imap pdo_mysql
# Install PHP extensions
RUN install-php-extensions pdo_mysql mbstring exif pcntl bcmath gd intl imap redis zip
# 4. Copy Custom Configs
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
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
# 5. Set Working Directory
WORKDIR /code
# Set working directory
WORKDIR /var/www
# CRITICAL FIX: Transfer ownership of /code to the 'application' user
# WORKDIR creates folders as 'root' by default, which blocks Composer later.
RUN chown application:application /code
# Copy existing application directory contents
COPY . /var/www
# 6. Install PHP Dependencies (Layered)
COPY --chown=application:application composer.json composer.lock ./
# Install PHP/Node dependencies and build frontend
RUN composer install --no-interaction --no-dev --optimize-autoloader \
&& npm install \
&& npm run build \
&& npm cache clean --force
USER application
RUN composer install --no-interaction --no-scripts --no-autoloader --prefer-dist --no-dev
# Nginx config
# Alpine uses http.d instead of sites-available
COPY .docker/nginx.conf /etc/nginx/http.d/default.conf
# 7. Install Node Dependencies
COPY --chown=application:application package.json package-lock.json* ./
RUN npm install
# Supervisor config
RUN mkdir -p /etc/supervisor/conf.d /var/log/supervisor
COPY .docker/supervisord.conf /etc/supervisor/conf.d/supervisord.conf
# 8. Copy Application Code
COPY --chown=application:application . .
# Set directory permissions
RUN mkdir -p /run/nginx /var/lib/nginx \
&& chown -R www-data:www-data /var/www \
&& chown -R www-data:www-data /var/lib/nginx \
&& chown -R www-data:www-data /run/nginx \
&& chmod -R 775 /var/www/storage /var/www/bootstrap/cache
# 9. Final Builds
RUN composer dump-autoload --optimize && \
composer run-script post-root-package-install && \
php artisan package:discover --ansi
EXPOSE 80
RUN npm run build
# Configure entrypoint
COPY .docker/entrypoint.sh /usr/local/bin/entrypoint.sh
RUN chmod +x /usr/local/bin/entrypoint.sh
# 10. Runtime Initialization Script
# This runs when the container STARTS, not when it builds.
USER root
# Start Supervisor
CMD ["/usr/local/bin/entrypoint.sh"]
RUN echo '#!/bin/bash' > /opt/docker/provision/entrypoint.d/99-init-laravel.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