---
services:
  db:
    image: 'postgres:17.0-alpine'
    hostname: &db_host db
    init: true
    environment:
      POSTGRES_USER: &db_user postgres
      POSTGRES_PASSWORD: &db_pass postgres
      POSTGRES_DB: postgres
    volumes:
      - './priv/docker/postgres/init.sql:/docker-entrypoint-initdb.d/init.sql'
      - 'db_data:/var/lib/postgresql/data'
    restart: unless-stopped
  app:
    image: 'joaodubas/ex_trainer:${EX_TRAINER_TAG:-dev}'
    build:
      target: builder
      context: .
      args:
        BUILD_MIX_ENV: dev
    hostname: &app_host ex_trainer
    depends_on:
      - db
    init: true
    develop:
      watch:
        - path: ./
          ignore:
            - ./build/
            - ./deps/
          target: /opt/app
          action: sync
        - path: ./config/
          target: /opt/app
          action: sync+restart
        - path: ./lib/wabanex/application.ex
          target: /opt/app
          action: sync+restart
        - path: ./mix.exs
          target: /opt/app
          action: sync+restart
        - path: ./mix.lock
          action: rebuild
    environment:
      DNS_CLUSTER_QUERY: *app_host
      POSTGRES_HOST: *db_host
      POSTGRES_USER: *db_user
      POSTGRES_PASS: *db_pass
      POSTGRES_NAME: wabanex_dev
    working_dir: /opt/app
    restart: unless-stopped
    scale: 3
    entrypoint: ./priv/docker/service/docker-entrypoint.sh
    command: local-cookie

volumes:
  db_data: {}
