{% include 'roles/sys-svc-compose/templates/base.yml.j2' %}
  {% set service_update_order = 'stop-first' %}
  {% set service_name = 'openresty' %}
  {{ service_name }}:
    {% include 'roles/sys-svc-container/templates/base.yml.j2' %}
    {{ lookup('template', 'roles/sys-svc-container/templates/build.yml.j2') | indent(4) }}
      args:
        OPENRESTY_IMAGE:              "{{ OPENRESTY_IMAGE }}"
        OPENRESTY_VERSION:            "{{ OPENRESTY_VERSION }}"
        PROMETHEUS_ENABLED:           "{{ OPENRESTY_PROMETHEUS_ENABLED }}"
        LUA_PROMETHEUS_URL_MAIN:      "{{ OPENRESTY_LUA_PROMETHEUS_URL_MAIN }}"
        LUA_PROMETHEUS_URL_COUNTER:   "{{ OPENRESTY_LUA_PROMETHEUS_URL_COUNTER }}"
        LUA_PROMETHEUS_URL_KEYS:      "{{ OPENRESTY_LUA_PROMETHEUS_URL_KEYS }}"
    {{ lookup('compose_only', 'container_name', OPENRESTY_CONTAINER) }}
    {{ lookup('container_image', application_id, 'openresty') }}
    {% if DEPLOYMENT_MODE == 'swarm' %}
    {{ lookup('container_ports',
              {'service': 'openresty', 'protocol': 'http', 'mode': 'host'},
              {'service': 'openresty', 'protocol': 'https', 'mode': 'host'}) | indent(4) }}
    {{ lookup('container_extra_hosts', extra_hosts=['host.docker.internal:host-gateway']) | indent(4) }}
    {{ lookup('container_networks') | indent(4) }}
    {% else %}
    network_mode: "host"
    {% endif %}
    {{ lookup('container_volumes', service_name) | indent(4) }}
    ulimits:
      nofile:
        soft: {{ WEBSERVER_PROXY_WORKER_RLIMIT_NOFILE }}
        hard: {{ WEBSERVER_PROXY_WORKER_RLIMIT_NOFILE }}
    command: ["openresty", "-g", "daemon off;"]
    {{ lookup('container_healthcheck', service_name) | indent(4) }}

{{ lookup('compose_volumes') }}
{{ lookup('compose_networks') }}
