services:
  postgres:
    image: pgvector/pgvector:pg16
    restart: unless-stopped
    environment:
      POSTGRES_DB: chatwoot_production
      POSTGRES_USER: chatwoot
      POSTGRES_PASSWORD: chatwoot123
    volumes:
      - postgres-data:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U chatwoot"]
      interval: 10s
      timeout: 5s
      retries: 5

  redis:
    image: redis:alpine
    restart: unless-stopped
    command: redis-server --requirepass redis123
    volumes:
      - redis-data:/data
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
      interval: 10s
      timeout: 5s
      retries: 5

  chatwoot:
    image: chatwoot/chatwoot:latest
    restart: unless-stopped
    ports:
      - "3000:3000"
    environment:
      SECRET_KEY_BASE: ${SECRET_KEY_BASE}
      FRONTEND_URL: https://omnichannel.softlinkoptions.me.ke
      POSTGRES_HOST: postgres
      POSTGRES_PORT: 5432
      POSTGRES_DB: chatwoot_production
      POSTGRES_USER: chatwoot
      POSTGRES_PASSWORD: chatwoot123
      REDIS_HOST: redis
      REDIS_PORT: 6379
      REDIS_PASSWORD: redis123
      RAILS_ENV: production
      RAILS_LOG_TO_STDOUT: true
      INSTALLATION_ENV: docker
    depends_on:
      postgres:
        condition: service_healthy
      redis:
        condition: service_healthy
    command: >
      sh -c "
        sleep 20 &&
        bundle exec rails db:create db:migrate db:seed &&
        bundle exec rails server -b 0.0.0.0 -p 3000 -e production
      "

volumes:
  postgres-data:
  redis-data:
