Deployment: Upgrade Dockerfile with multi-stage asset building, add Redis service and queue workers
This commit is contained in:
12
Dockerfile
12
Dockerfile
@@ -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
|
FROM php:8.3-fpm-alpine AS base
|
||||||
|
|
||||||
RUN apk add --no-cache \
|
RUN apk add --no-cache \
|
||||||
@@ -36,6 +45,9 @@ RUN composer install --no-dev --no-interaction --no-autoloader --no-scripts --pr
|
|||||||
|
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
|
# Copy Vite compiled assets
|
||||||
|
COPY --from=assets-builder /app/public/build ./public/build
|
||||||
|
|
||||||
RUN composer dump-autoload --optimize --no-dev \
|
RUN composer dump-autoload --optimize --no-dev \
|
||||||
&& mkdir -p storage/app/private/feedback-attachments \
|
&& mkdir -p storage/app/private/feedback-attachments \
|
||||||
&& mkdir -p storage/framework/{cache,sessions,views} \
|
&& mkdir -p storage/framework/{cache,sessions,views} \
|
||||||
|
|||||||
@@ -1,18 +1,35 @@
|
|||||||
|
version: '3.8'
|
||||||
|
|
||||||
services:
|
services:
|
||||||
app:
|
app:
|
||||||
build:
|
build:
|
||||||
context: .
|
context: .
|
||||||
dockerfile: Dockerfile
|
dockerfile: Dockerfile
|
||||||
|
image: minicrm:latest
|
||||||
|
container_name: minicrm_app
|
||||||
ports:
|
ports:
|
||||||
- "${APP_PORT:-8080}:80"
|
- "${APP_PORT:-8080}:80"
|
||||||
env_file:
|
env_file:
|
||||||
- .env
|
- .env
|
||||||
volumes:
|
volumes:
|
||||||
- ./database/database.sqlite:/var/www/html/database/database.sqlite
|
- ./database:/var/www/html/database
|
||||||
- ./storage/app:/var/www/html/storage/app
|
- ./storage/app:/var/www/html/storage/app
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
|
depends_on:
|
||||||
|
- redis
|
||||||
healthcheck:
|
healthcheck:
|
||||||
test: ["CMD", "curl", "-f", "http://localhost/admin/login"]
|
test: ["CMD", "curl", "-f", "http://localhost/admin/login"]
|
||||||
interval: 30s
|
interval: 30s
|
||||||
timeout: 5s
|
timeout: 5s
|
||||||
retries: 3
|
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:
|
||||||
|
|||||||
@@ -3,8 +3,9 @@ set -e
|
|||||||
|
|
||||||
if [ ! -f /var/www/html/database/database.sqlite ]; then
|
if [ ! -f /var/www/html/database/database.sqlite ]; then
|
||||||
touch /var/www/html/database/database.sqlite
|
touch /var/www/html/database/database.sqlite
|
||||||
chown www-data:www-data /var/www/html/database/database.sqlite
|
|
||||||
fi
|
fi
|
||||||
|
chown -R www-data:www-data /var/www/html/database
|
||||||
|
chmod -R 775 /var/www/html/database
|
||||||
|
|
||||||
if [ -z "$APP_KEY" ]; then
|
if [ -z "$APP_KEY" ]; then
|
||||||
php artisan key:generate --force --no-interaction
|
php artisan key:generate --force --no-interaction
|
||||||
|
|||||||
@@ -13,3 +13,16 @@ stdout_logfile_maxbytes=0
|
|||||||
command=nginx -g 'daemon off;'
|
command=nginx -g 'daemon off;'
|
||||||
stdout_logfile=/dev/stdout
|
stdout_logfile=/dev/stdout
|
||||||
stdout_logfile_maxbytes=0
|
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
|
||||||
|
|||||||
Reference in New Issue
Block a user