# @todo Test which containers can be removed crom cental_database networks
x-op-app: &app
  logging:
    driver: {{ "json-file" if IS_CONTAINER | bool else 'journald' }}
  image: {{ OPENPROJECT_CUSTOM_IMAGE }}
  {{ lookup('template', 'roles/docker-container/templates/build.yml.j2') | indent(2) }}

{% include 'roles/docker-compose/templates/base.yml.j2' %}

  cache:
{% set service_name = 'cache' %}
    image: "{{ OPENPROJECT_CACHE_IMAGE}}:{{ OPENPROJECT_CACHE_VERSION }}"
    container_name: {{ OPENPROJECT_CACHE_CONTAINER }}
{% include 'roles/docker-container/templates/base.yml.j2' %}

  proxy:
{% set service_name = 'proxy' %}
{% include 'roles/docker-container/templates/base.yml.j2' %}
    image: {{ OPENPROJECT_CUSTOM_IMAGE }}
    container_name: {{ OPENPROJECT_PROXY_CONTAINER }}
    pull_policy: never
    command: "./docker/prod/proxy"
    ports:
      - "127.0.0.1:{{ ports.localhost.http[application_id] }}:80"
    environment:
      APP_HOST: {{ OPENPROJECT_WEB_SERVICE }}
    depends_on:
      - {{ OPENPROJECT_WEB_SERVICE }}
    volumes:
      - "data:/var/openproject/assets"
      - "{{ OPENPROJECT_DUMMY_VOLUME }}:/var/openproject/pgdata" # This mount is unnecessary and just done to prevent anonymous volumes

  {{ OPENPROJECT_WEB_SERVICE }}:
    <<: *app
{% set service_name = OPENPROJECT_WEB_SERVICE %}
{% include 'roles/docker-container/templates/base.yml.j2' %}
    command: "./docker/prod/web"
    container_name: {{ OPENPROJECT_WEB_CONTAINER }}
{% include 'roles/docker-container/templates/networks.yml.j2' %}
{% include 'roles/docker-container/templates/depends_on/dmbs_incl.yml.j2' %}
      cache:
        condition: service_started
      {{ OPENPROJECT_SEEDER_SERVICE }}:
        condition: service_started
{% set container_port = 8080 %}
{% set container_healthcheck = 'health_checks/default' %}
{% include 'roles/docker-container/templates/healthcheck/curl.yml.j2' %}
    volumes:
      - "data:/var/openproject/assets"
      - "{{ OPENPROJECT_DUMMY_VOLUME }}:/var/openproject/pgdata" # This mount is unnecessary and just done to prevent anonymous volumes

{% set service_name = 'worker' %}
  worker:
    <<: *app
{% include 'roles/docker-container/templates/base.yml.j2' %}
    command: "./docker/prod/worker"
    container_name: {{ OPENPROJECT_WORKER_CONTAINER }}
{% include 'roles/docker-container/templates/networks.yml.j2' %}
{% include 'roles/docker-container/templates/depends_on/dmbs_incl.yml.j2' %}
      cache:
        condition: service_started
      {{ OPENPROJECT_SEEDER_SERVICE }}:
        condition: service_started
    volumes:
      - "data:/var/openproject/assets"
      - "{{ OPENPROJECT_DUMMY_VOLUME }}:/var/openproject/pgdata" # This mount is unnecessary and just done to prevent anonymous volumes

  cron:
    <<: *app
{% set service_name = 'cron' %}
{% include 'roles/docker-container/templates/base.yml.j2' %}
    command: "./docker/prod/cron"
    container_name: {{ OPENPROJECT_CRON_CONTAINER }}
{% include 'roles/docker-container/templates/networks.yml.j2' %}
{% include 'roles/docker-container/templates/depends_on/dmbs_incl.yml.j2' %}
      cache:
        condition: service_started
      {{ OPENPROJECT_SEEDER_SERVICE }}:
        condition: service_started
    volumes:
      - "data:/var/openproject/assets"
      - "{{ OPENPROJECT_DUMMY_VOLUME }}:/var/openproject/pgdata" # This mount is unnecessary and just done to prevent anonymous volumes

  {{ OPENPROJECT_SEEDER_SERVICE }}:
    <<: *app
{% set service_name = OPENPROJECT_SEEDER_SERVICE %}
{% set docker_restart_policy = 'on-failure' %}
{% include 'roles/docker-container/templates/base.yml.j2' %}
    command: "./docker/prod/seeder"
    container_name: {{ OPENPROJECT_SEEDER_CONTAINER }}
{% include 'roles/docker-container/templates/networks.yml.j2' %}
    volumes:
      - "data:/var/openproject/assets"
      - "{{ OPENPROJECT_DUMMY_VOLUME }}:/var/openproject/pgdata" # This mount is unnecessary and just done to prevent anonymous volumes

{% include 'roles/docker-compose/templates/volumes.yml.j2' %}
  data:
    name: {{ OPENPROJECT_VOLUME }}

{% include 'roles/docker-compose/templates/networks.yml.j2' %}