version: "3.9"

configs:
  app_env:
    name: app_env_${CONFIG_VERSION:-latest}
    file: .env
  nginx_conf:
    name: nginx_conf_${CONFIG_VERSION:-latest}
    file: ../nginx/default.conf
services:
  nginx:
    configs:
      - source: nginx_conf
        target: /etc/nginx/conf.d/default.conf
    image: nginx:alpine
    ports:
      - target: 80
        published: 8081
        protocol: tcp
        mode: ingress
    networks:
      - cba-network
    deploy:
      replicas: 2
      restart_policy:
        condition: any



  api:
    build:
      context: .
      dockerfile: Dockerfile
    image: ghcr.io/viscount-holdings/viscountcbaapi:dev
    configs:
      - source: app_env
        target: /app/.env
    environment:
      APP_ENV: production
    volumes:
      - storage-data:/app/storage
    networks:
      - cba-network
    deploy:
      replicas: 3
      restart_policy:
        condition: any
      update_config:
        order: start-first

  worker:
    build:
      context: .
      dockerfile: Dockerfile
    image: ghcr.io/viscount-holdings/viscountcbaapi:dev
    configs:
      - source: app_env
        target: /app/.env
    command: php artisan queue:work --sleep=3 --tries=3 --timeout=90
    networks:
      - cba-network
    deploy:
      replicas: 2
      restart_policy:
        condition: any

  scheduler:
    build:
      context: .
      dockerfile: Dockerfile
    image: ghcr.io/viscount-holdings/viscountcbaapi:dev
    configs:
      - source: app_env
        target: /app/.env
    command: php artisan schedule:work
    networks:
      - cba-network
    deploy:
      replicas: 1
      restart_policy:
        condition: any

networks:
  cba-network:
    driver: overlay

volumes:
  storage-data:
    driver: local
