x-ruby: &ruby
  build:
    context: .
    args:
      RUBY_VERSION: 2.6.6
      GEM_VERSION: 3.3.22
      BUNDLER_VERSION: 2.4.22
  image: ruby:2.6.6-idiario
  pull_policy: never
  platform: linux/amd64
  volumes:
    - .:/app
    - box:/box
  depends_on:
    postgres:
      condition: service_started
    redis:
      condition: service_started
    ruby:
      condition: service_completed_successfully
  environment:
    DATABASE_HOST: postgres

services:
  ruby:
    <<: *ruby
    container_name: idiario-ruby
    command: ./script/start
    depends_on: []

  puma:
    <<: *ruby
    container_name: idiario-puma
    command: bundle exec rails server -b 0.0.0.0
    ports:
      - ${DOCKER_APP_PORT:-80}:3000
      - ${DOCKER_APP_SSL_PORT:-443}:3000

  sidekiq:
    <<: *ruby
    container_name: idiario-sidekiq
    command: bundle exec sidekiq -c 10 --logfile log/sidekiq.log
    restart: always

  sidekiq-enqueue:
    <<: *ruby
    container_name: idiario-sidekiq-enqueue
    command: bundle exec sidekiq -q synchronizer_enqueue_next_job -q synchronizer_enqueue_next_job_full -c 1 --logfile log/sidekiq.log
    restart: always

  sidekiq-synchronizer-full:
    <<: *ruby
    container_name: sidekiq-synchronizer-full
    command: bundle exec sidekiq -q synchronizer_full -c 1 --logfile log/sidekiq-synchronizer-full.log
    restart: always

  sidekiq-synchronizer:
    <<: *ruby
    container_name: sidekiq-synchronizer
    command: bundle exec sidekiq -q synchronizer -c 1 --logfile log/sidekiq-synchronizer.log
    restart: always

  sidekiq-critical:
    <<: *ruby
    container_name: idiario-sidekiq-critical
    command: bundle exec sidekiq -q critical -c 1 --logfile log/sidekiq.log
    restart: always

  postgres:
    container_name: idiario-postgres
    image: postgres:18-alpine
    volumes:
      - postgres:/var/lib/postgresql/data
    environment:
      POSTGRES_DB: idiario_development
      POSTGRES_USER: idiario
      POSTGRES_PASSWORD: idiario
    ports:
      - ${DOCKER_POSTGRES_PORT:-5432}:5432

  redis:
    container_name: idiario-redis
    image: redis:8-alpine
    ports:
      - ${DOCKER_REDIS_PORT:-6379}:6379

volumes:
  box:
  postgres:
