version: '3.8'
services:

  workflow:
    image: ${BASE_REGISTRY_URL}/workspaces/workflow:${TAG}
    build:
      context: .
      dockerfile: ./services/workflow/Dockerfile
      target: prod
      args:
        - BASE_REGISTRY_URL=${BASE_REGISTRY_URL}
        - WS_VERSION=${WS_VERSION}
        - LOCAL_OR_SERVER_PEX="server-pex"
        - DEPLOY_ENV=${ENV}
    ports:
      - target: 3456
        published: 3456
        protocol: tcp
        mode: host
    environment:
      CAPO_PATH: /home/casa/capo
      CAPO_PROFILE: dsoc-${ENV}
      DL_HOST: ${DL_HOST}
      ENV_HOST: ${ENV_HOST}
    deploy:
      placement:
        constraints:
          - "node.labels.node_env==${ENV}"
      restart_policy:
        condition: on-failure
        max_attempts: 3
        window: 5s
      update_config:
        parallelism: 2
        delay: 5s
        order: stop-first
        failure_action: rollback
      rollback_config:
        parallelism: 0
        order: stop-first
    volumes:
      - /lustre/aoc/cluster/pipeline/dsoc-${ENV}/downloads/nrao:/lustre/aoc/cluster/pipeline/dsoc-${ENV}/downloads/nrao
      - /lustre/aoc/cluster/pipeline/dsoc-${ENV}/workspaces:/lustre/aoc/cluster/pipeline/dsoc-${ENV}/workspaces
      - /lustre/aoc/cluster/pipeline/vlass_${ENV}:/lustre/aoc/cluster/pipeline/vlass_${ENV}
      - /home/ssa/bin/python3.10:/home/ssa/bin/python3.10
      - /home/casa/capo:/home/casa/capo
      - /users/vlapipe/.ssh:/home/vlapipe/.ssh
      - /root/ws-condor/tokens.d:/etc/condor/tokens.d
      - condor:/var/spool/condor

  capability:
    image: ${BASE_REGISTRY_URL}/workspaces/capability:${TAG}
    build:
      context: .
      dockerfile: ./services/capability/Dockerfile
      target: prod
      args:
        - BASE_REGISTRY_URL=${BASE_REGISTRY_URL}
        - WS_VERSION=${WS_VERSION}
        - DEPLOY_ENV=${ENV}
        - ENV_HOST=${ENV_HOST}
    ports:
      - target: 3457
        published: 3457
        protocol: tcp
        mode: host
#    healthcheck:
#      test: ( curl -f -LI "${ENV_HOST}":3456/healthcheck ) || exit 1
#      interval: 5s
#      retries: 5
#      timeout: 60s
#      start_period: 30s
    environment:
      CAPO_PATH: /home/casa/capo
      CAPO_PROFILE: dsoc-${ENV}
      ENV_HOST: ${ENV_HOST}
      DL_HOST: ${DL_HOST}
    volumes:
      - /home/casa/capo:/home/casa/capo
    deploy:
      placement:
        constraints:
          - "node.labels.node_env==${ENV}"
      restart_policy:
        condition: on-failure
        delay: 5s
        window: 5s
      update_config:
        parallelism: 2
        delay: 5s
        order: stop-first
        failure_action: rollback
      rollback_config:
        parallelism: 0
        order: stop-first

  notification:
    image: ${BASE_REGISTRY_URL}/workspaces/notification:${TAG}
    build:
      context: .
      dockerfile: ./services/notification/Dockerfile
      target: prod
      args:
        - BASE_REGISTRY_URL=${BASE_REGISTRY_URL}
        - WS_VERSION=${WS_VERSION}
        - DEPLOY_ENV=${ENV}
    ports:
      - target: 3458
        published: 3458
        protocol: tcp
        mode: host
    environment:
      CAPO_PATH: /home/casa/capo
      CAPO_PROFILE: dsoc-${ENV}
      DL_HOST: ${DL_HOST}
      ENV_HOST: ${ENV_HOST}
    volumes:
      - /home/casa/capo:/home/casa/capo
    deploy:
      placement:
        constraints:
          - "node.labels.node_env==${ENV}"
      restart_policy:
        condition: on-failure
        max_attempts: 3
        window: 5s
      update_config:
        parallelism: 2
        delay: 5s
        order: stop-first
        failure_action: rollback
      rollback_config:
        parallelism: 0
        order: stop-first

  web:
    image: ${BASE_REGISTRY_URL}/workspaces/web:${TAG}
    build:
      context: .
      dockerfile: ./apps/web/Dockerfile
      target: prod
      args:
        - BASE_REGISTRY_URL=${BASE_REGISTRY_URL}
        - WS_VERSION=${WS_VERSION}
        - ENV_HOST=${ENV_HOST}
    ports:
      - target: 80
        published: 4444
        protocol: tcp
        mode: host
    environment:
      DL_HOST: ${DL_HOST}
      ENV_HOST: ${ENV_HOST}
      NG_APP_WS_VERSION: ${TAG}
    deploy:
      placement:
        constraints:
          - "node.labels.node_env==${ENV}"
      restart_policy:
        condition: on-failure
        max_attempts: 3
        window: 5s
      update_config:
        parallelism: 2
        delay: 5s
        order: stop-first
        failure_action: rollback
      rollback_config:
        parallelism: 0
        order: stop-first

volumes:
  condor:
