version: '3.8'

services:
  rails:
    image: ghcr.io/${GITHUB_REPOSITORY_OWNER:-rodribm10}/chatwoot-jasmine:latest
    environment:
      - RAILS_ENV=production
      - NODE_ENV=production
      - REDIS_URL=redis://redis:6379
      - POSTGRES_HOST=postgres
      - POSTGRES_PORT=5432
    env_file:
      - .env
    ports:
      - '3000:3000'
    deploy:
      replicas: 1
      restart_policy:
        condition: on-failure
    depends_on:
      - postgres
      - redis

  sidekiq:
    image: ghcr.io/${GITHUB_REPOSITORY_OWNER:-rodribm10}/chatwoot-jasmine:latest
    command: bundle exec sidekiq -C config/sidekiq.yml
    environment:
      - RAILS_ENV=production
      - NODE_ENV=production
      - REDIS_URL=redis://redis:6379
      - POSTGRES_HOST=postgres
      - POSTGRES_PORT=5432
    env_file:
      - .env
    deploy:
      replicas: 1
      restart_policy:
        condition: on-failure
    depends_on:
      - postgres
      - redis

  postgres:
    image: postgres:12
    restart: always
    environment:
      - POSTGRES_DB=chatwoot_production
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=postgres
    volumes:
      - postgres_data:/var/lib/postgresql/data
    deploy:
      placement:
        constraints:
          - node.role == manager

  redis:
    image: redis:6.2-alpine
    restart: always
    volumes:
      - redis_data:/data
    deploy:
      placement:
        constraints:
          - node.role == manager

volumes:
  postgres_data:
  redis_data:
  storage:
