version: "3"

services:
  migrations:
    image: mediacms/mediacms:latest
    volumes:
      - mediacms_data:/home/mediacms.io/mediacms/media
      - mediacms_static:/home/mediacms.io/mediacms/staticfiles
    environment:
      ENABLE_UWSGI: 'no'
      ENABLE_NGINX: 'no'
      ENABLE_CELERY_SHORT: 'no'
      ENABLE_CELERY_LONG: 'no'
      ENABLE_CELERY_BEAT: 'no'
      ENABLE_MIGRATIONS: 'yes'
      ADMIN_USER: 'admin'
      ADMIN_EMAIL: 'admin@localhost'
      ADMIN_PASSWORD: ${ADMIN_PASSWORD}
      DATABASE_HOST: db
      DATABASE_PORT: 5432
      DATABASE_USER: mediacms
      DATABASE_PASSWORD: ${POSTGRES_PASSWORD}
      DATABASE_NAME: mediacms
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
      REDIS_HOST: redis
      REDIS_PORT: 6379
    command: "./deploy/docker/prestart.sh"
    restart: on-failure
    depends_on:
      redis:
        condition: service_healthy
      db:
        condition: service_healthy

  web:
    image: mediacms/mediacms:latest
    deploy:
      replicas: 1
    ports:
      - 80
    volumes:
      - mediacms_data:/home/mediacms.io/mediacms/media
      - mediacms_static:/home/mediacms.io/mediacms/staticfiles
    environment:
      ENABLE_CELERY_BEAT: 'no'
      ENABLE_CELERY_SHORT: 'no'
      ENABLE_CELERY_LONG: 'no'
      ENABLE_MIGRATIONS: 'no'
      DATABASE_HOST: db
      DATABASE_PORT: 5432
      DATABASE_USER: mediacms
      DATABASE_PASSWORD: ${POSTGRES_PASSWORD}
      DATABASE_NAME: mediacms
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
      REDIS_HOST: redis
      REDIS_PORT: 6379
    depends_on:
      - migrations

  celery_beat:
    image: mediacms/mediacms:latest
    volumes:
      - mediacms_data:/home/mediacms.io/mediacms/media
      - mediacms_static:/home/mediacms.io/mediacms/staticfiles
    environment:
      ENABLE_UWSGI: 'no'
      ENABLE_NGINX: 'no'
      ENABLE_CELERY_SHORT: 'no'
      ENABLE_CELERY_LONG: 'no'
      ENABLE_MIGRATIONS: 'no'
      DATABASE_HOST: db
      DATABASE_PORT: 5432
      DATABASE_USER: mediacms
      DATABASE_PASSWORD: ${POSTGRES_PASSWORD}
      DATABASE_NAME: mediacms
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
      REDIS_HOST: redis
      REDIS_PORT: 6379
    depends_on:
      - redis

  celery_worker:
    image: mediacms/mediacms:latest
    deploy:
      replicas: 1
    volumes:
      - mediacms_data:/home/mediacms.io/mediacms/media
      - mediacms_static:/home/mediacms.io/mediacms/staticfiles
    environment:
      ENABLE_UWSGI: 'no'
      ENABLE_NGINX: 'no'
      ENABLE_CELERY_BEAT: 'no'
      ENABLE_MIGRATIONS: 'no'
      DATABASE_HOST: db
      DATABASE_PORT: 5432
      DATABASE_USER: mediacms
      DATABASE_PASSWORD: ${POSTGRES_PASSWORD}
      DATABASE_NAME: mediacms
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
      REDIS_HOST: redis
      REDIS_PORT: 6379
    depends_on:
      - migrations

  db:
    image: postgres:17.2-alpine
    volumes:
      - postgres_data:/var/lib/postgresql/data/
    restart: always
    environment:
      POSTGRES_USER: mediacms
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
      POSTGRES_DB: mediacms
      TZ: Europe/London
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -d $${POSTGRES_DB} -U $${POSTGRES_USER}"]
      interval: 10s
      timeout: 5s
      retries: 5

  redis:
    image: "redis:alpine"
    restart: always
    healthcheck:
      test: ["CMD", "redis-cli","ping"]
      interval: 10s
      timeout: 5s
      retries: 3

volumes:
  postgres_data:
  mediacms_data:
  mediacms_static:

