- entrypoint.sh: Redis wait tenía loop infinito sin timeout → el contenedor se quedaba colgado para siempre si Redis tardaba, causando 504 Gateway Timeout Ahora tiene MAX_RETRIES=15 (30s) y continúa aunque Redis no esté disponible - entrypoint.sh: removido set -e para que errores no-críticos (permisos, SSL, etc.) no maten el arranque del contenedor - docker-compose.yml: removido depends_on redis con condition:service_healthy Docker bloqueaba el inicio de app hasta que Redis estuviera healthy, lo que podía exceder el timeout de Traefik
177 lines
4.6 KiB
YAML
177 lines
4.6 KiB
YAML
services:
|
|
# Aplicación PHP con Nginx y Workers
|
|
app:
|
|
build:
|
|
context: .
|
|
dockerfile: Dockerfile
|
|
container_name: whatsapp-bot-app
|
|
restart: unless-stopped
|
|
working_dir: /var/www/html
|
|
# Coolify/Traefik gestiona el enrutamiento - no exponer puertos al host
|
|
expose:
|
|
- "80"
|
|
volumes:
|
|
- ./:/var/www/html
|
|
- ./logs:/var/www/html/logs
|
|
- ./uploads:/var/www/html/uploads
|
|
- php-socket:/run/php
|
|
environment:
|
|
- APP_ENV=${APP_ENV:-production}
|
|
- DB_HOST=${DB_HOST}
|
|
- DB_PORT=${DB_PORT:-3306}
|
|
- DB_NAME=${DB_NAME}
|
|
- DB_USER=${DB_USER}
|
|
- DB_PASS=${DB_PASS}
|
|
- REDIS_HOST=redis
|
|
- REDIS_PORT=6379
|
|
- REDIS_PASSWORD=${REDIS_PASSWORD:-}
|
|
- WHATSAPP_TOKEN=${WHATSAPP_TOKEN}
|
|
- WHATSAPP_PHONE_NUMBER_ID=${WHATSAPP_PHONE_NUMBER_ID}
|
|
- WEBHOOK_VERIFY_TOKEN=${WEBHOOK_VERIFY_TOKEN}
|
|
- LOG_LEVEL=${LOG_LEVEL:-INFO}
|
|
- ENABLE_RATE_LIMIT=${ENABLE_RATE_LIMIT:-true}
|
|
networks:
|
|
- whatsapp-network
|
|
healthcheck:
|
|
test: ["CMD", "curl", "-f", "http://localhost/health.php"]
|
|
interval: 30s
|
|
timeout: 5s
|
|
retries: 3
|
|
start_period: 40s
|
|
logging:
|
|
driver: "json-file"
|
|
options:
|
|
max-size: "10m"
|
|
max-file: "3"
|
|
|
|
# MySQL Database (DESHABILITADO - usando BD externa)
|
|
# Descomenta si quieres usar MySQL en Docker
|
|
# db:
|
|
# image: mysql:8.0
|
|
# container_name: whatsapp-bot-db
|
|
# restart: unless-stopped
|
|
# ports:
|
|
# - "${DB_PORT:-3306}:3306"
|
|
# environment:
|
|
# MYSQL_ROOT_PASSWORD: ${DB_ROOT_PASSWORD}
|
|
# MYSQL_DATABASE: ${DB_NAME:-whatsapp_bot}
|
|
# MYSQL_USER: ${DB_USER:-whatsapp_user}
|
|
# MYSQL_PASSWORD: ${DB_PASS}
|
|
# MYSQL_CHARACTER_SET_SERVER: utf8mb4
|
|
# MYSQL_COLLATION_SERVER: utf8mb4_unicode_ci
|
|
# volumes:
|
|
# - db-data:/var/lib/mysql
|
|
# - ./database/init.sql:/docker-entrypoint-initdb.d/init.sql:ro
|
|
# networks:
|
|
# - whatsapp-network
|
|
# healthcheck:
|
|
# test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-u", "root", "-p${DB_ROOT_PASSWORD}"]
|
|
# interval: 10s
|
|
# timeout: 5s
|
|
# retries: 5
|
|
# start_period: 30s
|
|
# command: --default-authentication-plugin=mysql_native_password --max_connections=500
|
|
|
|
# Redis para colas y caché
|
|
redis:
|
|
image: redis:7-alpine
|
|
container_name: whatsapp-bot-redis
|
|
restart: unless-stopped
|
|
ports:
|
|
- "${REDIS_PORT:-6379}:6379"
|
|
command: >
|
|
redis-server
|
|
--appendonly yes
|
|
--maxmemory 512mb
|
|
--maxmemory-policy allkeys-lru
|
|
${REDIS_PASSWORD:+--requirepass $REDIS_PASSWORD}
|
|
volumes:
|
|
- redis-data:/data
|
|
networks:
|
|
- whatsapp-network
|
|
healthcheck:
|
|
test: ["CMD", "redis-cli", "ping"]
|
|
interval: 10s
|
|
timeout: 3s
|
|
retries: 5
|
|
start_period: 10s
|
|
|
|
# Workers dedicados (adicionales a los del contenedor app)
|
|
worker:
|
|
build:
|
|
context: .
|
|
dockerfile: Dockerfile.worker
|
|
restart: unless-stopped
|
|
working_dir: /var/www/html
|
|
deploy:
|
|
replicas: ${WORKER_REPLICAS:-2}
|
|
volumes:
|
|
- ./logs:/var/www/html/logs
|
|
- ./.env:/var/www/html/.env:ro
|
|
environment:
|
|
- APP_ENV=${APP_ENV:-production}
|
|
- DB_HOST=${DB_HOST}
|
|
- DB_PORT=${DB_PORT:-3306}
|
|
- DB_NAME=${DB_NAME}
|
|
- DB_USER=${DB_USER}
|
|
- DB_PASS=${DB_PASS}
|
|
- REDIS_HOST=redis
|
|
- REDIS_PORT=6379
|
|
- REDIS_PASSWORD=${REDIS_PASSWORD:-}
|
|
- LOG_LEVEL=${LOG_LEVEL:-DEBUG}
|
|
depends_on:
|
|
redis:
|
|
condition: service_healthy
|
|
networks:
|
|
- whatsapp-network
|
|
command: php worker.php --daemon
|
|
|
|
# PHPMyAdmin (DESHABILITADO - solo si usas MySQL local)
|
|
# phpmyadmin:
|
|
# image: phpmyadmin:latest
|
|
# container_name: whatsapp-bot-phpmyadmin
|
|
# restart: unless-stopped
|
|
# ports:
|
|
# - "${PHPMYADMIN_PORT:-8081}:80"
|
|
# environment:
|
|
# PMA_HOST: db
|
|
# PMA_PORT: 3306
|
|
# PMA_USER: ${DB_USER:-whatsapp_user}
|
|
# PMA_PASSWORD: ${DB_PASS}
|
|
# UPLOAD_LIMIT: 50M
|
|
# depends_on:
|
|
# - db
|
|
# networks:
|
|
# - whatsapp-network
|
|
# profiles:
|
|
# - dev
|
|
|
|
# Redis Commander (opcional, solo desarrollo)
|
|
redis-commander:
|
|
image: rediscommander/redis-commander:latest
|
|
container_name: whatsapp-bot-redis-commander
|
|
restart: unless-stopped
|
|
ports:
|
|
- "${REDIS_COMMANDER_PORT:-8082}:8081"
|
|
environment:
|
|
- REDIS_HOSTS=local:redis:6379
|
|
- REDIS_PASSWORD=${REDIS_PASSWORD:-}
|
|
depends_on:
|
|
- redis
|
|
networks:
|
|
- whatsapp-network
|
|
profiles:
|
|
- dev
|
|
|
|
volumes:
|
|
db-data:
|
|
driver: local
|
|
redis-data:
|
|
driver: local
|
|
php-socket:
|
|
driver: local
|
|
|
|
networks:
|
|
whatsapp-network:
|
|
driver: bridge
|