Deployment: Upgrade Dockerfile with multi-stage asset building, add Redis service and queue workers

This commit is contained in:
2026-05-21 04:00:30 +00:00
parent fc9158b928
commit ffbfde943c
4 changed files with 45 additions and 2 deletions

View File

@@ -1,3 +1,12 @@
# Stage 1: Build front-end assets
FROM node:22-alpine AS assets-builder
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
RUN npm run build
# Stage 2: Production PHP FPM + Nginx image
FROM php:8.3-fpm-alpine AS base
RUN apk add --no-cache \
@@ -36,6 +45,9 @@ RUN composer install --no-dev --no-interaction --no-autoloader --no-scripts --pr
COPY . .
# Copy Vite compiled assets
COPY --from=assets-builder /app/public/build ./public/build
RUN composer dump-autoload --optimize --no-dev \
&& mkdir -p storage/app/private/feedback-attachments \
&& mkdir -p storage/framework/{cache,sessions,views} \

View File

@@ -1,18 +1,35 @@
version: '3.8'
services:
app:
build:
context: .
dockerfile: Dockerfile
image: minicrm:latest
container_name: minicrm_app
ports:
- "${APP_PORT:-8080}:80"
env_file:
- .env
volumes:
- ./database/database.sqlite:/var/www/html/database/database.sqlite
- ./database:/var/www/html/database
- ./storage/app:/var/www/html/storage/app
restart: unless-stopped
depends_on:
- redis
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost/admin/login"]
interval: 30s
timeout: 5s
retries: 3
redis:
image: redis:7-alpine
container_name: minicrm_redis
command: redis-server --appendonly yes
volumes:
- redis_data:/data
restart: unless-stopped
volumes:
redis_data:

View File

@@ -3,8 +3,9 @@ set -e
if [ ! -f /var/www/html/database/database.sqlite ]; then
touch /var/www/html/database/database.sqlite
chown www-data:www-data /var/www/html/database/database.sqlite
fi
chown -R www-data:www-data /var/www/html/database
chmod -R 775 /var/www/html/database
if [ -z "$APP_KEY" ]; then
php artisan key:generate --force --no-interaction

View File

@@ -13,3 +13,16 @@ stdout_logfile_maxbytes=0
command=nginx -g 'daemon off;'
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
[program:laravel-worker]
process_name=%(program_name)s_%(process_num)02d
command=php /var/www/html/artisan queue:work --sleep=3 --tries=3 --max-time=3600
autostart=true
autorestart=true
stopasgroup=true
killasgroup=true
numprocs=1
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0