---
name: {{ config.docker_compose_project_name }}
services:

{% if env.settings.run_qontract_reconcile %}
  qontract-reconcile:
    container_name: qontract-reconcile-{{ profile.settings.integration_name }}
    stop_grace_period: 1s
    stop_signal: SIGKILL
    tty: true
    restart: unless-stopped
    {% if profile.settings.qontract_reconcile_build_image %}
    build:
      context: {{ profile.settings.qontract_reconcile_path.expanduser().absolute() }}
      dockerfile: ./dockerfiles/Dockerfile
      target: dev-image
      args:
        CONTAINER_UID: {{ profile.settings.container_uid }}
    {% else %}
    image: {{ profile.settings.qontract_reconcile_image }}
    {% endif %}
    environment:
    - INTEGRATION_NAME={{ profile.settings.integration_name }}
    - INTEGRATION_EXTRA_ARGS={{ profile.settings.integration_extra_args }}
    - DRY_RUN={% if profile.settings.dry_run %}--dry-run{% else %}--no-dry-run{%endif%}
    - SLEEP_DURATION_SECS={{ profile.settings.sleep_duration_secs }}
    - DEBUGGER={{ profile.settings.debugger }}
    - CONFIG=/config/{{ env.settings.config.name }}
    - APP_INTERFACE_STATE_BUCKET={{ env.settings.app_interface_state_bucket }}
    - APP_INTERFACE_STATE_BUCKET_ACCOUNT={{ env.settings.app_interface_state_bucket_account }}
{% if  profile.settings.run_once %}
    - RUN_ONCE=1
{% endif %}
    - gitlab_pr_submitter_queue_url={{ env.settings.gitlab_pr_submitter_queue_url }}
    - LOG_LEVEL={{ profile.settings.log_level.upper() }}
    {% for key, value in profile.settings.additional_environment.items() %}
    - {{ key }}={{ value }}
    {% endfor %}
    volumes:
    - {{ profile.settings.qontract_reconcile_path.expanduser().absolute() }}:/work
    - {{ env.settings.config.expanduser().absolute().parent }}:/config
    - tmp-volume:/tmp
{% if env.settings.run_qontract_server or env.settings.run_vault %}
    links:
{% endif %}
{% if env.settings.run_qontract_server %}
    - qontract-server
{% endif %}
{% if env.settings.run_vault %}
    - vault
{% endif %}
    ports:
    - 9090:9090 # Metrics Exporter
    - 5678:5678 # Debugger Port
    networks:
    - qontract-development
{% endif %}

{% if env.settings.run_qontract_server %}
  qontract-server:
    {% if profile.settings.qontract_server_build_image %}
    build:
      context: {{ profile.settings.qontract_server_path.expanduser().absolute() }}
    {% else %}
    image: {{ profile.settings.qontract_server_image }}
    {% endif %}
    container_name: qontract-server
    volumes:
    - {{ profile.settings.qontract_server_path.expanduser().absolute() }}/bundle:/bundle:ro
    environment:
    - LOAD_METHOD=fs
    - DATAFILES_FILE=/bundle/bundle.json
    ports:
    - 4000:4000
    - 6789:6789 # Debugger Port
    networks:
    - qontract-development
{% endif %}

{% if env.settings.run_vault %}
  vault:
    container_name: vault
    image: "vault:1.5.4"
    environment:
    - VAULT_ADDR=http://127.0.0.1:8200
    - VAULT_TOKEN=root
    - VAULT_DEV_ROOT_TOKEN_ID=root
    - VAULT_DEV_LISTEN_ADDRESS=0.0.0.0:8200
    ports:
    - 8200:8200
    networks:
    - qontract-development
{% endif %}

volumes:
  tmp-volume:

networks:
  qontract-development:
    name: qontract-development
