Compare commits
9 Commits
66b5d2f89e
...
dokploy-se
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
42e2f1bf0a | ||
|
|
2989613b75 | ||
|
|
285b995afb | ||
|
|
0d9a524267 | ||
|
|
b30da6614a | ||
|
|
0aed57bc2c | ||
|
|
6d24d1f6fc | ||
|
|
189c2d7c58 | ||
|
|
7f58ca9f45 |
105
Dockerfile
105
Dockerfile
@@ -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
|
# 2. Environment Configuration
|
||||||
RUN apt-get update && apt-get install -y \
|
ENV WEB_DOCUMENT_ROOT=/code/public
|
||||||
git \
|
ENV APP_ENV=production
|
||||||
curl \
|
ENV COMPOSER_ALLOW_SUPERUSER=1
|
||||||
libpng-dev \
|
ENV COMPOSER_PROCESS_TIMEOUT=2000
|
||||||
libonig-dev \
|
|
||||||
libxml2-dev \
|
|
||||||
zip \
|
|
||||||
unzip \
|
|
||||||
nginx \
|
|
||||||
supervisor \
|
|
||||||
libc-client-dev \
|
|
||||||
libkrb5-dev \
|
|
||||||
&& rm -rf /var/lib/apt/lists/*
|
|
||||||
|
|
||||||
# Configure and install PHP extensions
|
# 3. Install System Dependencies & Extensions
|
||||||
RUN docker-php-ext-configure imap --with-kerberos --with-imap-ssl \
|
COPY --from=mlocati/php-extension-installer /usr/bin/install-php-extensions /usr/local/bin/
|
||||||
&& docker-php-ext-install pdo_mysql mbstring exif pcntl bcmath gd intl imap \
|
|
||||||
&& pecl install redis \
|
|
||||||
&& docker-php-ext-enable redis
|
|
||||||
|
|
||||||
# Install Composer
|
RUN apk add --no-cache \
|
||||||
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
|
nodejs \
|
||||||
|
npm \
|
||||||
|
sqlite \
|
||||||
|
shadow \
|
||||||
|
&& install-php-extensions pdo_sqlite mongodb redis imap pdo_mysql
|
||||||
|
|
||||||
# Set working directory
|
# 4. Copy Custom Configs
|
||||||
WORKDIR /var/www
|
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
|
# 5. Set Working Directory
|
||||||
COPY . /var/www
|
WORKDIR /code
|
||||||
|
|
||||||
# Install PHP dependencies
|
# CRITICAL FIX: Transfer ownership of /code to the 'application' user
|
||||||
RUN composer install --no-interaction --no-dev --optimize-autoloader
|
# WORKDIR creates folders as 'root' by default, which blocks Composer later.
|
||||||
|
RUN chown application:application /code
|
||||||
|
|
||||||
# Nginx config
|
# 6. Install PHP Dependencies (Layered)
|
||||||
COPY .docker/nginx.conf /etc/nginx/sites-available/default
|
COPY --chown=application:application composer.json composer.lock ./
|
||||||
RUN rm -rf /etc/nginx/sites-enabled/default && ln -s /etc/nginx/sites-available/default /etc/nginx/sites-enabled/default
|
|
||||||
|
|
||||||
# Supervisor config
|
USER application
|
||||||
COPY .docker/supervisord.conf /etc/supervisor/conf.d/supervisord.conf
|
RUN composer install --no-interaction --no-scripts --no-autoloader --prefer-dist --no-dev
|
||||||
|
|
||||||
# Set directory permissions
|
# 7. Install Node Dependencies
|
||||||
RUN chown -R www-data:www-data /var/www/storage /var/www/bootstrap/cache \
|
COPY --chown=application:application package.json package-lock.json* ./
|
||||||
&& chmod -R 775 /var/www/storage /var/www/bootstrap/cache
|
RUN npm install
|
||||||
|
|
||||||
# Build frontend assets
|
# 8. Copy Application Code
|
||||||
RUN curl -fsSL https://deb.nodesource.com/setup_20.x | bash - \
|
COPY --chown=application:application . .
|
||||||
&& apt-get install -y nodejs \
|
|
||||||
&& npm install \
|
|
||||||
&& npm run build \
|
|
||||||
&& apt-get remove -y nodejs \
|
|
||||||
&& apt-get autoremove -y
|
|
||||||
|
|
||||||
EXPOSE 80
|
# 9. Final Builds
|
||||||
|
RUN composer dump-autoload --optimize && \
|
||||||
|
composer run-script post-root-package-install && \
|
||||||
|
php artisan package:discover --ansi
|
||||||
|
|
||||||
# Configure entrypoint
|
RUN npm run build
|
||||||
COPY .docker/entrypoint.sh /usr/local/bin/entrypoint.sh
|
|
||||||
RUN chmod +x /usr/local/bin/entrypoint.sh
|
|
||||||
|
|
||||||
# Start Supervisor
|
# 10. Runtime Initialization Script
|
||||||
CMD ["/usr/local/bin/entrypoint.sh"]
|
# 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
|
||||||
|
|||||||
@@ -16,8 +16,8 @@ Zemailnator is a scalable disposable temporary email service (like Mailinator or
|
|||||||
|
|
||||||
## 1.1 Deployment Architecture (Dokploy)
|
## 1.1 Deployment Architecture (Dokploy)
|
||||||
Zemailnator is containerized for zero-downtime deployment on 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.
|
- **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 instances to allow for independent backups and to prevent database restarts during application deployment.
|
- **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
|
## 2. Technology Stack
|
||||||
- **Framework:** Laravel 12.x
|
- **Framework:** Laravel 12.x
|
||||||
|
|||||||
@@ -35,11 +35,14 @@ class AppServiceProvider extends ServiceProvider
|
|||||||
$this->loadConfiguration();
|
$this->loadConfiguration();
|
||||||
$this->loadDomainUsernameData();
|
$this->loadDomainUsernameData();
|
||||||
|
|
||||||
// Only load application data when not in testing environment
|
|
||||||
if (! $this->app->environment('testing')) {
|
if (! $this->app->environment('testing')) {
|
||||||
$this->loadApplicationData();
|
$this->loadApplicationData();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($this->app->environment('production')) {
|
||||||
|
\Illuminate\Support\Facades\URL::forceScheme('https');
|
||||||
|
}
|
||||||
|
|
||||||
Cashier::calculateTaxes();
|
Cashier::calculateTaxes();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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
6
dockerizer/php.ini
Normal 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
|
||||||
25
dockerizer/supervisor.laravel.conf
Normal file
25
dockerizer/supervisor.laravel.conf
Normal 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
25
dockerizer/vhost.conf
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user