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

  web:
{% set container_port = 3000 %}
{% set container_healthcheck = 'health' %}
    container_name: {{ mastodon_name }}
    image: "{{ mastodon_image }}:{{ mastodon_version }}"
{% include 'roles/docker-container/templates/base.yml.j2' %}
    command: bash -c "rm -f /mastodon/tmp/pids/server.pid; bundle exec rails s -p {{ container_port }}"
{% include 'roles/docker-container/templates/healthcheck/wget.yml.j2' %}
    ports:
      - "127.0.0.1:{{ports.localhost.http[application_id]}}:{{ container_port }}"
{% include 'roles/docker-container/templates/depends_on/dmbs_excl.yml.j2' %}
    volumes:
      - data:/mastodon/public/system
{% include 'roles/docker-container/templates/networks.yml.j2' %}

  streaming:
{% set container_port = 4000 %}
{% set container_healthcheck = 'api/v1/streaming/health' %}
    container_name: {{ mastodon_streaming_name }}
    image: "{{ mastodon_streaming_image }}:{{ mastodon_streaming_version }}"
{% include 'roles/docker-container/templates/base.yml.j2' %}
    command: node ./streaming
{% include 'roles/docker-container/templates/healthcheck/wget.yml.j2' %}
    ports:
      - "127.0.0.1:{{ ports.localhost.websocket[application_id] }}:{{ container_port }}"
{% include 'roles/docker-container/templates/depends_on/dmbs_excl.yml.j2' %}
{% include 'roles/docker-container/templates/networks.yml.j2' %}

  sidekiq:
    container_name: {{ mastodon_sidekiq_name }}
    image: "{{ mastodon_image }}:{{ mastodon_version }}"
{% include 'roles/docker-container/templates/base.yml.j2' %}
    command: bundle exec sidekiq
{% include 'roles/docker-container/templates/depends_on/dmbs_excl.yml.j2' %}
    volumes:
      - data:/mastodon/public/system
    healthcheck:
      test: ["CMD-SHELL", "pgrep -f sidekiq || exit 1"]
      interval: 1m
      timeout: 10s
      retries: 3
{% include 'roles/docker-container/templates/networks.yml.j2' %}

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