services: {% for service in services %} {% if inventory_hostname in service.vm %} {{ service.name }}: container_name: {{ service.container_name }} image: {{ service.image }} restart: unless-stopped {% if service.network_mode is not defined %} hostname: {{ service.name }} networks: - net {% endif %} {% if service.ports is defined and service.ports is iterable %} {% if service.ports[0].internal != 'proxy_only' %} ports: {% for port in service.ports %} {% if port.internal != 'proxy_only' %} - {{ port.external }}:{{ port.internal }} {% endif %} {% endfor %} {% endif %} {% endif %} {% if service.ports is defined and service.ports is iterable %} {% set first_http_port = service.ports | default([]) | selectattr('name', 'defined') | selectattr('name', 'search', 'http') | first %} {% set chosen_http_port_value = none %} {% if first_http_port is not none %} {% if first_http_port.internal is defined and first_http_port.internal == 'proxy_only' %} {% if first_http_port.external is defined %} {% set chosen_http_port_value = first_http_port.external %} {% endif %} {% else %} {% set chosen_http_port_value = first_http_port.internal %} {% endif %} {% if chosen_http_port_value is defined %} healthcheck: {% set healthcheck = 'curl' %} {% if service.healthcheck is defined %} {% set healthcheck = service.healthcheck %} {% endif %} {% if healthcheck == 'curl' %} test: ["CMD", "curl", "-f", "--silent", "--show-error", "--connect-timeout", "5", "http://localhost:{{ chosen_http_port_value }}/"] {% elif healthcheck == 'wget' %} test: ["CMD-SHELL", "wget --quiet --spider --timeout=5 http://localhost:{{ chosen_http_port_value }}/ || exit 1"] {% endif %} interval: 30s timeout: 10s retries: 5 start_period: 20s {% endif %} {% endif %} {% endif %} {% if service.cap_add is defined and service.cap_add is iterable %} cap_add: {% for cap in service.cap_add %} - {{ cap }} {% endfor %} {% endif %} {% if service.depends_on is defined and service.depends_on is iterable %} depends_on: {% for dependency in service.depends_on %} - {{ dependency }} {% endfor %} {% endif %} {% if service.network_mode is defined %} network_mode: {{ service.network_mode }} {% endif %} {% if service.privileged is defined %} privileged: {{ service.privileged }} {% endif %} {% if service.volumes is defined and service.volumes is iterable %} volumes: {% for volume in service.volumes %} - {{ volume.external }}:{{ volume.internal }} {% endfor %} {% endif %} {% if service.environment is defined and service.environment is iterable %} environment: {% for env in service.environment %} - {{ env }} {% endfor %} {% endif %} {% if service.devices is defined and service.devices is iterable %} devices: {% for device in service.devices %} - {{ device.external }}:{{ device.internal }} {% endfor %} {% endif %} {% if service.command is defined and service.command is iterable %} command: {% for command in service.command %} - {{ command }} {% endfor %} {% endif %} {% if service.sub_service is defined and service.sub_service is iterable %} {% for sub in service.sub_service %} {% if sub.name is defined and sub.name == "postgres" %} {{ service.name }}-postgres: container_name: {{ service.name }}-postgres image: docker.io/library/postgres:{{ sub.version }} restart: unless-stopped hostname: {{ service.name }}-postgres networks: - net volumes: - /opt/local/{{ service.name }}/postgres/data:/var/lib/postgresql/data environment: POSTGRES_DB: {{ service.name }} POSTGRES_USER: {{ sub.username }} POSTGRES_PASSWORD: {{ sub.password }} {% endif %} {% if sub.name is defined and sub.name == "redis" %} {{ service.name }}-redis: container_name: {{ service.name }}-redis image: docker.io/library/redis:{{ sub.version }} restart: unless-stopped hostname: {{ service.name }}-redis networks: - net volumes: - /opt/local/{{ service.name }}/redis/data:/data {% endif %} {% if sub.name is defined and sub.name == "chrome" %} {{ service.name }}-chrome: image: gcr.io/zenika-hub/alpine-chrome:{{ sub.version }} container_name: {{ service.name }}-chrome restart: unless-stopped networks: - net command: - --no-sandbox - --disable-gpu - --disable-dev-shm-usage - --remote-debugging-address=0.0.0.0 - --remote-debugging-port=9222 - --hide-scrollbars {% endif %} {% if sub.name is defined and sub.name == "meilisearch" %} {{ service.name }}-meilisearch: container_name: {{ service.name }}-meilisearch image: getmeili/meilisearch:{{ sub.version }} restart: unless-stopped hostname: {{ service.name }}-meilisearch networks: - net volumes: - /opt/local/{{ service.name }}/mailisearch/data:/meili_data environment: - MEILI_NO_ANALYTICS=true - NEXTAUTH_SECRET={{ sub.nextauth_secret }} - MEILI_MASTER_KEY={{ sub.meili_master_key }} - OPENAI_API_KEY="{{ sub.openai_key }}" {% endif %} {% endfor %} {% endif %} {% endif %} {% endfor %} networks: net: driver: bridge ipam: driver: default config: - subnet: 172.16.69.0/24