networks:
  tango-net:
    name: tango-net
    driver: bridge

services:
  tango-db:
    image: artefact.skao.int/ska-tango-images-tango-db:11.2.6
    platform: linux/x86_64
    networks:
      - tango-net
    environment:
      - MARIADB_ROOT_PASSWORD=root
      - MARIADB_DATABASE=tango
      - MARIADB_USER=tango
      - MARIADB_PASSWORD=tango
    healthcheck:
      test: ["CMD", "healthcheck.sh", "--connect"]
      start_period: 10s
      interval: 500ms
      timeout: 1s
      retries: 3

  tango-dbds:
    image: artefact.skao.int/ska-tango-images-tango-databaseds:5.23.0
    platform: linux/x86_64
    networks:
      - tango-net
    ports:
      - "10000:10000"
    environment:
      - TANGO_HOST=localhost:10000
      - MYSQL_HOST=tango-db:3306
      - MYSQL_USER=tango
      - MYSQL_PASSWORD=tango
      - MYSQL_DATABASE=tango
    depends_on:
      tango-db:
        condition: service_healthy
    entrypoint: Databaseds
    command:
      - "2"
      - -ORBendPoint
      - giop:tcp::10000
    healthcheck:
      test: ["CMD", "sh", "-c", "/usr/local/bin/tango_admin --ping-database || exit 1"]
      start_period: 10s
      start_interval: 500ms
      timeout: 3s
      retries: 3

  load-tango-config:
    image: artefact.skao.int/ska-tango-images-tango-dsconfig:1.8.0
    platform: linux/x86_64
    networks:
      - tango-net
    environment:
      - TANGO_HOST=tango-dbds:10000
    volumes:
      - ./:/mnt:z
    depends_on:
      tango-dbds:
        condition: service_healthy
    entrypoint: "bash"
    command:
      - "-c"
      - "json2tango --write /mnt/tango.json || [ $$? -eq 2 ]"

  archive-db:
    image: artefact.skao.int/ska-tango-images-hdbpp-timescaledb:2.4.0
    platform: linux/x86_64
    networks:
      - tango-net
    ports:
      - "5432:5432"
    environment:
      - POSTGRES_PASSWORD=tango
    healthcheck:
      test: ["CMD", "pg_isready"]
      start_period: 10s
      start_interval: 500ms
      timeout: 1s
      retries: 3

  archive-cm:
    image: artefact.skao.int/ska-tango-images-hdbpp-cm:2.2.1
    platform: linux/x86_64
    networks:
      - tango-net
    environment:
      - TANGO_HOST=tango-dbds:10000
    depends_on:
      tango-dbds:
        condition: service_healthy
      load-tango-config:
        condition: service_completed_successfully
    healthcheck:
      test: ["CMD", "sh", "-c", "/usr/local/bin/tango_admin --ping-device hdb/cm/1 || exit 1"]
      start_period: 10s
      start_interval: 500ms
      timeout: 1s
      retries: 3
    command:
      - "1"

  archive-es:
    image: artefact.skao.int/ska-tango-images-hdbpp-es-timescaledb:2.4.0
    platform: linux/x86_64
    networks:
      - tango-net
    environment:
      - TANGO_HOST=tango-dbds:10000
    depends_on:
      tango-dbds:
        condition: service_healthy
      load-tango-config:
        condition: service_completed_successfully
    healthcheck:
      test: ["CMD", "sh", "-c", "/usr/local/bin/tango_admin --ping-device hdb/es/1 || exit 1"]
      start_period: 10s
      start_interval: 500ms
      timeout: 1s
      retries: 3
    command:
      - "1"

  load-archive-config:
    image: artefact.skao.int/ska-tango-images-hdbpp-yaml2archiving:0.11.0
    platform: linux/x86_64
    networks:
      - tango-net
    environment:
      - TANGO_HOST=tango-dbds:10000
    volumes:
      - ./:/mnt:z
    depends_on:
      archive-cm:
        condition: service_healthy
      archive-es:
        condition: service_healthy
    command:
      - "--write"
      - "/mnt/archive.yaml"

  tango-test:
    image: artefact.skao.int/ska-tango-images-tango-test:3.10.0
    platform: linux/x86_64
    networks:
      - tango-net
    environment:
      - TANGO_HOST=tango-dbds:10000
    depends_on:
      tango-dbds:
        condition: service_healthy
    healthcheck:
      test: ["CMD", "sh", "-c", "/usr/local/bin/tango_admin --ping-device sys/tg_test/1 || exit 1"]
      start_period: 10s
      start_interval: 500ms
      timeout: 1s
      retries: 3
    command:
      - "test"
