#jinja2: lstrip_blocks: True
version: '2'
services:

  web:
    image: {{ awx_web_docker_actual_image }}
    depends_on:
      - rabbitmq
      - memcached
      {% if pg_hostname is not defined %}
      - postgres
      {% endif %}
    ports:
      - "{{ host_port }}:8052"
    hostname: {{ awx_web_hostname }}
    user: root
    restart: unless-stopped
    {% if (project_data_dir is defined) or (ca_trust_dir is defined) %}
    volumes:
    {% endif %}
    {% if project_data_dir is defined %}
      - "{{ project_data_dir +':/var/lib/awx/projects:rw' }}"
    {% endif %}
    {% if ca_trust_dir is defined %}
      - "{{ ca_trust_dir +':/etc/pki/ca-trust/source/anchors:ro' }}"
    {% endif %}
    {% if (awx_container_search_domains is defined) and (',' in awx_container_search_domains) %}
    {% set awx_container_search_domains_list = awx_container_search_domains.split(',') %}
    dns_search:
    {% for awx_container_search_domain in awx_container_search_domains_list %}
      - {{ awx_container_search_domain }}
    {% endfor %}
    {% elif awx_container_search_domains is defined %}
    dns_search: "{{ awx_container_search_domains }}"
    {% endif %}
    {% if (awx_alternate_dns_servers is defined) and (',' in awx_alternate_dns_servers) %}
    {% set awx_alternate_dns_servers_list = awx_alternate_dns_servers.split(',') %}
    dns:
    {% for awx_alternate_dns_server in awx_alternate_dns_servers_list %}
      - {{ awx_alternate_dns_server }}
    {% endfor %}
    {% elif awx_alternate_dns_servers is defined %}
    dns: "{{ awx_alternate_dns_servers }}"
    {% endif %}
    environment:
      http_proxy: {{ http_proxy | default('') }}
      https_proxy: {{ https_proxy | default('') }}
      no_proxy: {{ no_proxy | default('') }}
      SECRET_KEY: {{ secret_key }}
      DATABASE_NAME: {{ pg_database }}
      DATABASE_USER: {{ pg_username }}
      DATABASE_PASSWORD: {{ pg_password }}
      DATABASE_PORT: {{ pg_port }}
      DATABASE_HOST: {{ pg_hostname|default("postgres") }}
      RABBITMQ_USER: guest
      RABBITMQ_PASSWORD: guest
      RABBITMQ_HOST: rabbitmq
      RABBITMQ_PORT: 5672
      RABBITMQ_VHOST: awx
      MEMCACHED_HOST: memcached
      MEMCACHED_PORT: 11211
      AWX_ADMIN_USER: {{ admin_user|default('admin') }}
      AWX_ADMIN_PASSWORD: {{ admin_password|default('password') }}

  task:
    image: {{ awx_task_docker_actual_image }}
    depends_on:
      - rabbitmq
      - memcached
      - web
      {% if pg_hostname is not defined %}
      - postgres
      {% endif %}
    hostname: {{ awx_task_hostname }}
    user: root
    restart: unless-stopped
    {% if (project_data_dir is defined) or (ca_trust_dir is defined) %}
    volumes:
    {% endif %}
    {% if project_data_dir is defined %}
      - "{{ project_data_dir +':/var/lib/awx/projects:rw' }}"
    {% endif %}
    {% if ca_trust_dir is defined %}
      - "{{ ca_trust_dir +':/etc/pki/ca-trust/source/anchors:ro' }}"
    {% endif %}
    {% if (awx_container_search_domains is defined) and (',' in awx_container_search_domains) %}
    {% set awx_container_search_domains_list = awx_container_search_domains.split(',') %}
    dns_search:
    {% for awx_container_search_domain in awx_container_search_domains_list %}
      - {{ awx_container_search_domain }}
    {% endfor %}
    {% elif awx_container_search_domains is defined %}
    dns_search: "{{ awx_container_search_domains }}"
    {% endif %}
    {% if (awx_alternate_dns_servers is defined) and (',' in awx_alternate_dns_servers) %}
    {% set awx_alternate_dns_servers_list = awx_alternate_dns_servers.split(',') %}
    dns:
    {% for awx_alternate_dns_server in awx_alternate_dns_servers_list %}
      - {{ awx_alternate_dns_server }}
    {% endfor %}
    {% elif awx_alternate_dns_servers is defined %}
    dns: "{{ awx_alternate_dns_servers }}"
    {% endif %}
    environment:
      http_proxy: {{ http_proxy | default('') }}
      https_proxy: {{ https_proxy | default('') }}
      no_proxy: {{ no_proxy | default('') }}
      SECRET_KEY: {{ secret_key }}
      DATABASE_NAME: {{ pg_database }}
      DATABASE_USER: {{ pg_username }}
      DATABASE_PASSWORD: {{ pg_password }}
      DATABASE_HOST: {{ pg_hostname|default("postgres") }}
      DATABASE_PORT: {{ pg_port }}
      RABBITMQ_USER: guest
      RABBITMQ_PASSWORD: guest
      RABBITMQ_HOST: rabbitmq
      RABBITMQ_PORT: 5672
      RABBITMQ_VHOST: awx
      MEMCACHED_HOST: memcached
      MEMCACHED_PORT: 11211
      AWX_ADMIN_USER: {{ admin_user|default('admin') }}
      AWX_ADMIN_PASSWORD: {{ admin_password|default('password') }}

  rabbitmq:
    image: {{ rabbitmq_image }}
    restart: unless-stopped
    environment:
      RABBITMQ_DEFAULT_VHOST: awx
      RABBITMQ_ERLANG_COOKIE: cookiemonster

  memcached:
    image: memcached:alpine
    restart: unless-stopped

  {% if pg_hostname is not defined %}
  postgres:
    image: postgres:9.6
    restart: unless-stopped
    volumes:
      - {{ postgres_data_dir }}:/var/lib/postgresql/data:Z
    environment:
      POSTGRES_USER: {{ pg_username }}
      POSTGRES_PASSWORD: {{ pg_password }}
      POSTGRES_DB: {{ pg_database }}
      PGDATA: /var/lib/postgresql/data/pgdata
  {% endif %}
