version: "2.1"

services:
  postgres:
    image: postgres
    restart: unless-stopped
    volumes:
      - postgres:/var/lib/postgresql/data
      - ./init-database.sh:/docker-entrypoint-initdb.d/init-database.sh
    environment:
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=postgres
    ports:
      - 5432:5432
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U postgres"]
      interval: 5s
      timeout: 5s
      retries: 5
  hwsd_component-2:
    depends_on:
      postgres:
        condition: service_healthy
    ports:
    - "5001:80"
    build:
      context: ./hwsd_component
      args:
        - PACKAGE_NAME=hwsd_component-2
    command: migrate-and-run
    environment:
      HWSD_COMPONENT__POSTGRES__HOST: postgres
      HWSD_COMPONENT__POSTGRES__USERNAME: hwsd_component
      HWSD_COMPONENT__POSTGRES__PASSWORD: secret
      HWSD_COMPONENT__POSTGRES__DATABASE_NAME: hwsd_component
    restart: on-failure
    healthcheck:
      test: ["CMD-SHELL", "curl 0.0.0.0:80/health/status"]
      interval: 5s
      timeout: 5s
      retries: 5
  hwsd_run-2:
    depends_on:
      postgres:
        condition: service_healthy
    ports:
    - "5000:80"
    build:
      context: ./hwsd_run
      args:
        - PACKAGE_NAME=hwsd_run-2
    command: migrate-and-run
    environment:
      HWSD_RUN__POSTGRES__HOST: postgres
      HWSD_RUN__POSTGRES__USERNAME: hwsd_run
      HWSD_RUN__POSTGRES__PASSWORD: secret
      HWSD_RUN__POSTGRES__DATABASE_NAME: hwsd_run
    restart: on-failure
    healthcheck:
      test: ["CMD-SHELL", "curl 0.0.0.0:80/health/status"]
      interval: 5s
      timeout: 5s
      retries: 5
  hwsd_station-2:
    depends_on:
      postgres:
        condition: service_healthy
    ports:
    - "5003:80"
    build:
      context: ./hwsd_station
      args:
        - PACKAGE_NAME=hwsd_station-2
    command: migrate-and-run
    environment:
      HWSD_STATION__POSTGRES__HOST: postgres
      HWSD_STATION__POSTGRES__USERNAME: hwsd_station
      HWSD_STATION__POSTGRES__PASSWORD: secret
      HWSD_STATION__POSTGRES__DATABASE_NAME: hwsd_station
    restart: on-failure
    healthcheck:
      test: ["CMD-SHELL", "curl 0.0.0.0:80/health/status"]
      interval: 5s
      timeout: 5s
      retries: 5
  hwsd_test-2:
    depends_on:
      postgres:
        condition: service_healthy
    ports:
    - "5002:80"
    build:
      context: ./hwsd_test
      args:
        - PACKAGE_NAME=hwsd_test-2
    command: migrate-and-run
    environment:
      HWSD_TEST__POSTGRES__HOST: postgres
      HWSD_TEST__POSTGRES__USERNAME: hwsd_test
      HWSD_TEST__POSTGRES__PASSWORD: secret
      HWSD_TEST__POSTGRES__DATABASE_NAME: hwsd_test
    restart: on-failure
    healthcheck:
      test: ["CMD-SHELL", "curl 0.0.0.0:80/health/status"]
      interval: 5s
      timeout: 5s
      retries: 5
  hwsd_gateway-2:
    depends_on:
      - hwsd_component-2
      - hwsd_run-2
      - hwsd_station-2
      - hwsd_test-2
    ports:
    - "5060:80"
    build:
      context: ./hwsd_gateway
      args:
        - PACKAGE_NAME=hwsd_gateway-2
    restart: on-failure
    environment:
      HWSD_GATEWAY__HWSD_COMPONENT_URL: http://hwsd_component-2:80/
      HWSD_GATEWAY__HWSD_RUN_URL: http://hwsd_run-2:80/
      HWSD_GATEWAY__HWSD_STATION_URL: http://hwsd_station-2:80/
      HWSD_GATEWAY__HWSD_TEST_URL: http://hwsd_test-2:80/
    healthcheck:
      test: ["CMD-SHELL", "curl 0.0.0.0:80/health/status"]
      interval: 5s
      timeout: 5s
      retries: 5
volumes:
  postgres:
