refactor: separate MariaDB and Redis into independent Coolify resources

This commit is contained in:
hamed
2026-06-28 11:28:29 +03:30
parent 471f43248b
commit 42bb723333
6 changed files with 323 additions and 72 deletions
+17 -42
View File
@@ -1,6 +1,11 @@
# Coolify deployment — Build Pack: Docker Compose
# This is the production deploy stack (MariaDB + Redis). The ddev local env uses
# its own compose.yaml; do not confuse the two.
# This is the production APP stack (app + workers ONLY). MariaDB and Redis are
# run as SEPARATE Coolify Database Resources, not part of this compose.
# - Create a standalone MariaDB resource and a standalone Redis resource in Coolify.
# - Enable "Connect to Predefined Network" on THIS app stack.
# - Set DATABASE_URL / REDIS_URL / MESSENGER_TRANSPORT_DSN in Coolify's env tab,
# pointing at the resources via their internal hostnames (mariadb-<uuid> / redis-<uuid>).
# The ddev local env uses its own compose.yaml; do not confuse the two.
# Select this file (docker-compose.yml) as the Compose file in the Coolify resource.
# Do NOT define custom `networks:` — Coolify manages the network; custom ones
# break Traefik routing (per Coolify docs).
@@ -10,9 +15,13 @@ x-app-env: &app-env
APP_ENV: prod
APP_DEBUG: "0"
APP_SECRET: ${APP_SECRET}
DATABASE_URL: "mysql://clinic:${DB_PASSWORD}@mariadb:3306/clinic_pro?serverVersion=mariadb-11.8.0&charset=utf8mb4"
MESSENGER_TRANSPORT_DSN: redis://redis:6379/messages
REDIS_URL: redis://redis:6379
# Connection strings point at the SEPARATE Coolify DB/Redis resources.
# Real values are injected from Coolify's Environment Variables tab — the
# hostname is mariadb-<uuid> / redis-<uuid> from each resource's page, so they
# cannot be hardcoded here (the UUID differs per installation).
DATABASE_URL: ${DATABASE_URL}
MESSENGER_TRANSPORT_DSN: ${MESSENGER_TRANSPORT_DSN}
REDIS_URL: ${REDIS_URL}
JWT_SECRET_KEY: "%kernel.project_dir%/config/jwt/private.pem"
JWT_PUBLIC_KEY: "%kernel.project_dir%/config/jwt/public.pem"
JWT_PASSPHRASE: ${JWT_PASSPHRASE}
@@ -34,13 +43,6 @@ x-app-volumes: &app-volumes
- uploads_public:/app/public/uploads
- uploads_var:/app/var/uploads
# Shared dependency gate on DB + Redis being up.
x-app-depends: &app-depends
mariadb:
condition: service_healthy
redis:
condition: service_started
services:
# Web app (PHP-FPM + Nginx).
# In Coolify, assign ALL serving domains to THIS service (port 80) — the backend
@@ -51,7 +53,7 @@ services:
app:
# Shared image tag — app builds it once; the two workers reuse the SAME image
# (image: below, no build:). Without this Coolify builds the Dockerfile 3×,
# tripling apk/pecl network fetches and intermittently failing on the host.
# tripling apk network fetches and intermittently failing on the host.
image: clinicpro-app:latest
build:
context: .
@@ -61,7 +63,6 @@ services:
<<: *app-env
RUN_INIT: "1" # runs JWT keygen + migrations on start (only this service)
volumes: *app-volumes
depends_on: *app-depends
healthcheck:
test: ["CMD", "php", "-r", "exit(@fsockopen('127.0.0.1', 80) ? 0 : 1);"]
interval: 15s
@@ -78,7 +79,7 @@ services:
<<: *app-env
RUN_INIT: "0"
volumes: *app-volumes
depends_on: *app-depends
depends_on: [app]
# Scheduler consumer — expires unpaid appointments every minute. Reuses app's image.
worker-scheduler:
@@ -89,35 +90,9 @@ services:
<<: *app-env
RUN_INIT: "0"
volumes: *app-volumes
depends_on: *app-depends
mariadb:
image: mariadb:11.8
restart: unless-stopped
environment:
MARIADB_DATABASE: clinic_pro
MARIADB_USER: clinic
MARIADB_PASSWORD: ${DB_PASSWORD}
MARIADB_ROOT_PASSWORD: ${DB_ROOT_PASSWORD}
volumes:
- mariadb_data:/var/lib/mysql
healthcheck:
test: ["CMD", "healthcheck.sh", "--connect", "--innodb_initialized"]
interval: 10s
timeout: 5s
retries: 10
start_period: 30s
redis:
image: redis:7-alpine
restart: unless-stopped
command: redis-server --appendonly yes
volumes:
- redis_data:/data
depends_on: [app]
volumes:
jwt_keys:
uploads_public:
uploads_var:
mariadb_data:
redis_data: