version: '3.8'
services:
  nginx:
    image: nginx:1.19.7-alpine
    restart: always
    ports:
      - "4444:80"
    depends_on:
      - frontend
    command: nginx -g "daemon off;"
    volumes:
      - ./apps/web/ws-nginx.local.conf:/etc/nginx/conf.d/default.conf
      - ./lustre/:/lustre/aoc/cluster/pipeline/docker/workspaces
      - ./delivery_root:/tmp/delivery_root
  db:
    image: ssa-containers.aoc.nrao.edu/ops/ci/db:workspaces
    restart: always
    ports:
      - "54322:5432"
    environment:
      POSTGRES_USER: archive
      POSTGRES_PASSWORD: docker
    command: postgres -c listen_addresses=*
    healthcheck:
      test: pg_isready -U archive -d archive
      start_period: 2s
      interval: 2s
      timeout: 2s
      retries: 5
    volumes:
      - ./pgdata:/var/lib/postgresql/data

  amqp:
    image: rabbitmq:3.8-management
    restart: always
    ports:
      - "15672:15672"

  condor-cm:
    build:
      context: .
      dockerfile: ./config/htcondor/cm/Dockerfile.local
    ports:
      - 9618

  condor-execute:
    build:
      context: .
      dockerfile: ./config/htcondor/execute/Dockerfile.local
    volumes:
      - ./delivery_root:/tmp/delivery_root
      - ./lustre/aoc/cluster/pipeline/docker/workspaces:/lustre/aoc/cluster/pipeline/docker/workspaces
      - ./lustre/aoc/cluster/pipeline/vlass_docker:/lustre/aoc/cluster/pipeline/vlass_docker

  pex-watcher:
    build:
      context: .
      dockerfile: ./config/pex-watcher/Dockerfile.pex
    volumes:
      - ./config/pex-watcher:/config
      - ./apps/cli/executables/pexable/:/config/apps/cli/executables/pexable/
      - ./lustre/aoc/cluster/pipeline/docker/workspaces/sbin:/lustre/aoc/cluster/pipeline/docker/workspaces/sbin

  schema:
    build:
      context: ./shared/workspaces/alembic/
      dockerfile: Dockerfile.local
    depends_on:
      db:
        condition: service_healthy
    volumes:
      - ./shared/workspaces/alembic:/code/shared/workspaces/alembic
      - ./docker.properties:/home/ssa/capo/docker.properties

  # Used for doing a DB migration on dsoc-dev
  # Run the command `docker compose -f docker-compose.local.yml --profile schema-dev up schema-dev` and the migration will run
  schema-dev:
    build:
      context: ./shared/workspaces/alembic/
      dockerfile: Dockerfile.local
    command: ["./bin/run-migrations.sh", "dsoc-dev"]
    volumes:
      - ./shared/workspaces/alembic:/code/shared/workspaces/alembic
      - ~/.capo:/home/ssa/capo
    profiles:
      - schema-dev

  # Used for doing a DB migration on dsoc-test
  # Run the command `docker compose -f docker-compose.local.yml --profile schema-test up schema-test` and the migration will run
  schema-test:
    build:
      context: ./shared/workspaces/alembic/
      dockerfile: Dockerfile.local
    command: ["./bin/run-migrations.sh", "dsoc-test"]
    volumes:
      - ./shared/workspaces/alembic:/code/shared/workspaces/alembic
      - ~/.capo:/home/ssa/capo
    profiles:
      - schema-test

  # Used for doing a DB migration on dsoc-prod
  # Run the command `docker compose -f docker-compose.local.yml --profile schema-prod up schema-prod` and the migration will run
  schema-prod:
    build:
      context: ./shared/workspaces/alembic/
      dockerfile: Dockerfile.local
    command: ["./bin/run-migrations.sh", "dsoc-prod"]
    volumes:
      - ./shared/workspaces/alembic:/code/shared/workspaces/alembic
      - ~/.capo:/home/ssa/capo
    profiles:
      - schema-prod

  workflow:
    build:
      context: .
      dockerfile: ./services/workflow/Dockerfile.local
    ports:
      - "3456:3456"
      - 9618
    depends_on:
      - schema
      - amqp
    healthcheck:
      test: curl -f -LI localhost:3456/healthcheck
      interval: 5s
      retries: 5
      start_period: 2s
      timeout: 5s
    volumes:
      - ./services/workflow:/code
      - /code/ssa_workflow.egg-info
      - ./shared:/packages/shared
      - ./apps/cli:/packages/apps/cli
      - ./testing:/packages/testing
      - ./lustre/aoc/cluster/pipeline/docker/workspaces:/lustre/aoc/cluster/pipeline/docker/workspaces
      - ./lustre/aoc/cluster/pipeline/vlass_docker:/lustre/aoc/cluster/pipeline/vlass_docker
      - ./delivery_root:/tmp/delivery_root
      - ~/.capo:/home/ssa/capo
      - ~/.ssh:/home/vlapipe/.ssh
      - ./docker.properties:/home/ssa/capo/docker.properties
      - /packages/shared/workspaces/ssa_workspaces.egg-info
      - /packages/shared/schema/ssa_schema.egg-info
      - /packages/shared/messaging/ssa_messaging.egg-info
      - /packages/apps/cli/utilities/wf_monitor/ssa_wf_monitor.egg-info
      - /packages/apps/cli/utilities/ws_metrics/ssa_ws_metrics.egg-info
      - /packages/apps/cli/utilities/aat_wrest/ssa_aat_wrest.egg-info
      - /packages/apps/cli/utilities/contacts_wrest/ssa_contacts_wrest.egg-info
      - /packages/apps/cli/executables/pexable/mediator/ssa_system_mediator.egg-info
      - /packages/apps/cli/executables/pexable/productfetcher/ssa_productfetcher.egg-info
      - /packages/apps/cli/executables/pexable/casa_envoy/ssa_casa_envoy.egg-info
      - /packages/apps/cli/executables/pexable/vela/ssa_vela.egg-info
      - /packages/apps/cli/executables/pexable/deliver/ssa_delivery.egg-info
      - /packages/apps/cli/executables/pexable/null/ssa_null.egg-info
      - condor:/var/spool/condor

  capability:
    build:
      context: .
      dockerfile: ./services/capability/Dockerfile.local
    ports:
      - "3457:3457"
    depends_on:
      schema:
        condition: service_started
      workflow:
        condition: service_healthy
      notification:
        condition: service_healthy
      amqp:
        condition: service_started
    volumes:
      - ./docker.properties:/home/ssa/capo/docker.properties
      - ./services/capability:/code
      - ./shared:/packages/shared
      - ./apps/cli:/packages/apps/cli
      - ./testing:/packages/testing
      - /code/ssa_capability.egg-info
      - /packages/shared/workspaces/ssa_workspaces.egg-info
      - /packages/shared/schema/ssa_schema.egg-info
      - /packages/shared/messaging/ssa_messaging.egg-info
      - /packages/apps/cli/utilities/wf_monitor/ssa_wf_monitor.egg-info
      - /packages/apps/cli/utilities/ws_metrics/ssa_ws_metrics.egg-info
      - /packages/apps/cli/utilities/aat_wrest/ssa_aat_wrest.egg-info
      - /packages/apps/cli/utilities/contacts_wrest/ssa_contacts_wrest.egg-info
      - /packages/apps/cli/executables/pexable/vela/ssa_vela.egg-info
      - /packages/apps/cli/executables/pexable/mediator/ssa_system_mediator.egg-info
      - /packages/apps/cli/executables/pexable/productfetcher/ssa_productfetcher.egg-info
      - /packages/apps/cli/executables/pexable/casa_envoy/ssa_casa_envoy.egg-info
      - /packages/apps/cli/executables/pexable/deliver/ssa_delivery.egg-info
      - /packages/apps/cli/executables/pexable/null/ssa_null.egg-info

  notification:
    build:
      context: .
      dockerfile: ./services/notification/Dockerfile.local
    ports:
      - "3458:3458"
    depends_on:
      - schema
      - amqp
    healthcheck:
      test: curl -f -LI localhost:3458/healthcheck
      interval: 5s
      retries: 5
      start_period: 2s
      timeout: 5s
    volumes:
      - ./docker.properties:/home/ssa/capo/docker.properties
      - ./services/notification:/code
      - /code/ssa_notification.egg-info
      - ./shared:/packages/shared
      - ./apps/cli:/packages/apps/cli
      - ./testing:/packages/testing
      - /packages/shared/workspaces/ssa_workspaces.egg-info
      - /packages/shared/schema/ssa_schema.egg-info
      - /packages/shared/messaging/ssa_messaging.egg-info
      - /packages/apps/cli/utilities/wf_monitor/ssa_wf_monitor.egg-info
      - /packages/apps/cli/utilities/ws_metrics/ssa_ws_metrics.egg-info
      - /packages/apps/cli/utilities/aat_wrest/ssa_aat_wrest.egg-info
      - /packages/apps/cli/utilities/contacts_wrest/ssa_contacts_wrest.egg-info
      - /packages/apps/cli/executables/pexable/vela/ssa_vela.egg-info
      - /packages/apps/cli/executables/pexable/mediator/ssa_system_mediator.egg-info
      - /packages/apps/cli/executables/pexable/productfetcher/ssa_productfetcher.egg-info
      - /packages/apps/cli/executables/pexable/casa_envoy/ssa_casa_envoy.egg-info
      - /packages/apps/cli/executables/pexable/deliver/ssa_delivery.egg-info
      - /packages/apps/cli/executables/pexable/null/ssa_null.egg-info

  frontend:
    build:
      context: .
      dockerfile: ./apps/web/Dockerfile.local
    init: true
    ports:
      - "4200:4200"
    depends_on:
      - capability
      - workflow
    volumes:
      - ./apps/web:/code
      - /code/node_modules

volumes:
  condor:
