-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcompose.prod.yaml
More file actions
149 lines (141 loc) · 5.48 KB
/
compose.prod.yaml
File metadata and controls
149 lines (141 loc) · 5.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
services:
web:
build:
context: .
dockerfile: ./docker/production/nginx/Dockerfile
restart: unless-stopped # Automatically restart unless the service is explicitly stopped
volumes:
# Mount the 'laravel-storage-production' volume to '/var/www/storage' inside the container.
# -----------------------------------------------------------
# This volume stores persistent data like uploaded files and cache.
# The ':ro' option mounts it as read-only in the 'web' service because Nginx only needs to read these files.
# The 'php-fpm' service mounts the same volume without ':ro' to allow write operations.
# -----------------------------------------------------------
- laravel-storage-production:/var/www/storage:ro
- laravel-public-assets:/var/www/public/build:ro
- ./:/var/www/html
networks:
- laravel-production
ports:
# Map port 80 inside the container to the port specified by 'NGINX_PORT' on the host machine.
# -----------------------------------------------------------
# This allows external access to the Nginx web server running inside the container.
# For example, if 'NGINX_PORT' is set to '8080', accessing 'http://localhost:8080' will reach the application.
# -----------------------------------------------------------
- "${NGINX_PORT:-80}:80"
depends_on:
php-fpm:
condition: service_healthy # Wait for php-fpm health check
php-fpm:
# For the php-fpm service, we will create a custom image to install the necessary PHP extensions and setup proper permissions.
build:
context: .
dockerfile: ./docker/common/php-fpm/Dockerfile
target: production
restart: unless-stopped
volumes:
- laravel-public-assets:/var/www/public/build # Mount built public assets to ensure the manifest.json and hashed files match between Nginx and PHP-FPM
- laravel-storage-production:/var/www/storage # Mount the storage volume
env_file:
- .env.docker
networks:
- laravel-production
healthcheck:
test: ["CMD-SHELL", "php-fpm-healthcheck || exit 1"]
interval: 10s
timeout: 5s
retries: 3
# The 'depends_on' attribute with 'condition: service_healthy' ensures that
# this service will not start until the 'postgres' service passes its health check.
# This prevents the application from trying to connect to the database before it's ready.
depends_on:
mysql:
condition: service_healthy
mysql:
image: mysql:8.0
restart: unless-stopped
ports:
- "${MYSQL_PORT:-3306}:3306"
environment:
MYSQL_ROOT_PASSWORD: ${DB_PASSWORD:-secret}
MYSQL_DATABASE: ${DB_DATABASE:-platformio}
MYSQL_USER: ${DB_USERNAME:-laravel}
MYSQL_PASSWORD: ${DB_PASSWORD:-secret}
volumes:
- mysql-data-production:/var/lib/mysql
networks:
- laravel-production
# Health check for MySQL
# -----------------------------------------------------------
# Health checks allow Docker to determine if a service is operational.
# The 'mysqladmin ping' command checks if MySQL is ready to accept connections.
# This prevents dependent services from starting before the database is ready.
# -----------------------------------------------------------
healthcheck:
test: ["CMD", "mysqladmin", "ping", "-h", "localhost"]
interval: 10s
timeout: 5s
retries: 5
redis:
image: redis:alpine
restart: unless-stopped # Automatically restart unless the service is explicitly stopped
volumes:
- redis-data-production:/data # Added persistence so queues/sessions survive restarts
networks:
- laravel-production
# Health check for Redis
# -----------------------------------------------------------
# Checks if Redis is responding to the 'PING' command.
# This ensures that the service is not only running but also operational.
# -----------------------------------------------------------
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 10s
timeout: 5s
retries: 3
# ---------------------------------------------------------
# CUSTOM PRODUCTION SERVICES FOR MONOLITH
# ---------------------------------------------------------
reverb:
build:
context: .
dockerfile: ./docker/common/php-fpm/Dockerfile
target: production
restart: unless-stopped
command: php artisan reverb:start --host="0.0.0.0" --port=8080
ports:
- "8080:8080"
env_file:
- .env.docker
networks:
- laravel-production
depends_on:
redis:
condition: service_healthy
mysql:
condition: service_healthy
python_ai:
build:
context: ./python_services
dockerfile: dockerfile
restart: unless-stopped
command: python ai_worker.py
env_file:
- .env.docker
networks:
- laravel-production
depends_on:
redis:
condition: service_healthy
networks:
# Attach the service to the 'laravel' network.
# -----------------------------------------------------------
# This custom network allows all services within it to communicate using their service names as hostnames.
# For example, 'php-fpm' can connect to 'mysql' by using 'mysql' as the hostname.
# -----------------------------------------------------------
laravel-production:
volumes:
mysql-data-production:
laravel-storage-production:
laravel-public-assets:
redis-data-production: # Added Redis persistence volume