Compare commits

...

9 Commits

7 changed files with 118 additions and 91 deletions

View File

@@ -1,62 +1,69 @@
FROM php:8.4-fpm
# 1. Use the specific PHP 8.4 Alpine image
FROM webdevops/php-nginx:8.4-alpine
# Install system dependencies
RUN apt-get update && apt-get install -y \
git \
curl \
libpng-dev \
libonig-dev \
libxml2-dev \
zip \
unzip \
nginx \
supervisor \
libc-client-dev \
libkrb5-dev \
&& rm -rf /var/lib/apt/lists/*
# 2. Environment Configuration
ENV WEB_DOCUMENT_ROOT=/code/public
ENV APP_ENV=production
ENV COMPOSER_ALLOW_SUPERUSER=1
ENV COMPOSER_PROCESS_TIMEOUT=2000
# Configure and install PHP extensions
RUN docker-php-ext-configure imap --with-kerberos --with-imap-ssl \
&& docker-php-ext-install pdo_mysql mbstring exif pcntl bcmath gd intl imap \
&& pecl install redis \
&& docker-php-ext-enable redis
# 3. Install System Dependencies & Extensions
COPY --from=mlocati/php-extension-installer /usr/bin/install-php-extensions /usr/local/bin/
# Install Composer
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
RUN apk add --no-cache \
nodejs \
npm \
sqlite \
shadow \
&& install-php-extensions pdo_sqlite mongodb redis imap pdo_mysql
# Set working directory
WORKDIR /var/www
# 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
# Copy existing application directory contents
COPY . /var/www
# 5. Set Working Directory
WORKDIR /code
# Install PHP dependencies
RUN composer install --no-interaction --no-dev --optimize-autoloader
# 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
# Nginx config
COPY .docker/nginx.conf /etc/nginx/sites-available/default
RUN rm -rf /etc/nginx/sites-enabled/default && ln -s /etc/nginx/sites-available/default /etc/nginx/sites-enabled/default
# 6. Install PHP Dependencies (Layered)
COPY --chown=application:application composer.json composer.lock ./
# Supervisor config
COPY .docker/supervisord.conf /etc/supervisor/conf.d/supervisord.conf
USER application
RUN composer install --no-interaction --no-scripts --no-autoloader --prefer-dist --no-dev
# Set directory permissions
RUN chown -R www-data:www-data /var/www/storage /var/www/bootstrap/cache \
&& chmod -R 775 /var/www/storage /var/www/bootstrap/cache
# 7. Install Node Dependencies
COPY --chown=application:application package.json package-lock.json* ./
RUN npm install
# Build frontend assets
RUN curl -fsSL https://deb.nodesource.com/setup_20.x | bash - \
&& apt-get install -y nodejs \
&& npm install \
&& npm run build \
&& apt-get remove -y nodejs \
&& apt-get autoremove -y
# 8. Copy Application Code
COPY --chown=application:application . .
EXPOSE 80
# 9. Final Builds
RUN composer dump-autoload --optimize && \
composer run-script post-root-package-install && \
php artisan package:discover --ansi
# Configure entrypoint
COPY .docker/entrypoint.sh /usr/local/bin/entrypoint.sh
RUN chmod +x /usr/local/bin/entrypoint.sh
RUN npm run build
# Start Supervisor
CMD ["/usr/local/bin/entrypoint.sh"]
# 10. Runtime Initialization Script
# This runs when the container STARTS, not when it builds.
USER root
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 'touch /code/database/database.sqlite' >> /opt/docker/provision/entrypoint.d/99-init-laravel.sh && \
echo 'chown -R application:application /code/storage /code/bootstrap/cache /code/database' >> /opt/docker/provision/entrypoint.d/99-init-laravel.sh && \
echo 'chmod -R 775 /code/storage /code/bootstrap/cache /code/database' >> /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

View File

@@ -16,8 +16,8 @@ Zemailnator is a scalable disposable temporary email service (like Mailinator or
## 1.1 Deployment Architecture (Dokploy)
Zemailnator is containerized for zero-downtime deployment on Dokploy:
- **Application Container:** Uses `php:8.4-fpm` with a bundled Nginx server and Supervisor to manage background queues.
- **External Services:** MariaDB and Redis run as fully separate, standalone Dokploy instances to allow for independent backups and to prevent database restarts during application deployment.
- **Application Container:** Uses `php:8.4-fpm-alpine` configured via a single `Dockerfile` with a bundled Nginx server and Supervisor to manage background queues.
- **External Services:** MariaDB and Redis run as fully separate, standalone Dokploy application instances to allow for independent backups and to prevent database restarts during application deployment.
## 2. Technology Stack
- **Framework:** Laravel 12.x

View File

@@ -35,11 +35,14 @@ class AppServiceProvider extends ServiceProvider
$this->loadConfiguration();
$this->loadDomainUsernameData();
// Only load application data when not in testing environment
if (! $this->app->environment('testing')) {
$this->loadApplicationData();
}
if ($this->app->environment('production')) {
\Illuminate\Support\Facades\URL::forceScheme('https');
}
Cashier::calculateTaxes();
}

View File

@@ -1,39 +0,0 @@
version: '3.8'
services:
app:
build:
context: .
dockerfile: Dockerfile
restart: unless-stopped
ports:
- "${APP_PORT:-8000}:80"
environment:
- APP_ENV=${APP_ENV:-production}
- APP_DEBUG=${APP_DEBUG:-false}
- APP_URL=${APP_URL}
- DB_CONNECTION=${DB_CONNECTION:-mysql}
- DB_HOST=${DB_HOST}
- DB_PORT=${DB_PORT:-3306}
- DB_DATABASE=${DB_DATABASE:-zemail}
- DB_USERNAME=${DB_USERNAME:-zemail_user}
- DB_PASSWORD=${DB_PASSWORD}
- CACHE_STORE=${CACHE_STORE:-redis}
- QUEUE_CONNECTION=${QUEUE_CONNECTION:-redis}
- SESSION_DRIVER=${SESSION_DRIVER:-redis}
- REDIS_HOST=${REDIS_HOST}
- REDIS_PASSWORD=${REDIS_PASSWORD}
- REDIS_PORT=${REDIS_PORT:-6379}
healthcheck:
test: [ "CMD", "curl", "-f", "http://localhost/health" ]
interval: 30s
timeout: 10s
retries: 3
start_period: 30s
volumes:
- app-storage:/var/www/storage
- app-public-tmp:/var/www/public/tmp
volumes:
app-storage:
app-public-tmp:

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;
}
}