networks:
  mastodon:
    external: false
    enable_ipv6: true

services:
  redis:
    image: redis:7-alpine
    restart: always
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
    networks:
      - mastodon

  web:
    image: ghcr.io/mastodon/mastodon:v4.3.2
    restart: always
    env_file:
      - path: .env.production
      - path: .env
        required: false
    command: bundle exec puma -C config/puma.rb
    healthcheck:
      # prettier-ignore
      test: ['CMD-SHELL', 'wget -q --spider --proxy=off localhost:3000/health || exit 1']
    networks:
      - mastodon
    ports:
      - "4004:3000"
    depends_on:
      - redis
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.mastodon-web.entrypoints=websecure"
      - "traefik.http.routers.mastodon-web.rule=Host(`toot.gnous.eu`)"
      - "traefik.http.routers.mastodon-web.tls=true"
      - "traefik.http.routers.mastodon-web.tls.certresolver=defaultacme"
      - "traefik.http.routers.mastodon-web.middlewares=proxyHeader@file,proxyError@file"
      # Cron
      - "ofelia.enabled=true"
      - "ofelia.job-exec.clean-media.schedule=@daily"
      - "ofelia.job-exec.clean-media.command=tootctl media remove --days 7"
      - "ofelia.job-exec.clean-account.schedule=@monthly"
      - "ofelia.job-exec.clean-account.command=tootctl accounts cull"

  streaming:
    image: ghcr.io/mastodon/mastodon-streaming:v4.3.2
    restart: always
    env_file:
      - path: .env.production
      - path: .env
        required: false
    command: node ./streaming/index.js
    healthcheck:
      # prettier-ignore
      test: ['CMD-SHELL', "curl -s --noproxy localhost localhost:4000/api/v1/streaming/health | grep -q 'OK' || exit 1"]
    ports:
      - "127.0.0.1:4000:4000"
    depends_on:
      - redis
    networks:
      - mastodon
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.mastodon-streaming.entrypoints=websecure"
      - "traefik.http.routers.mastodon-streaming.rule=(Host(`toot.gnous.eu`) && PathPrefix(`/api/v1/streaming`))"
      - "traefik.http.routers.mastodon-streaming.tls.certresolver=letsencrypt"
      - "traefik.http.routers.mastodon-streaming.tls=true"
      - "traefik.http.routers.mastodon-streaming.tls.certresolver=defaultacme"
      - "traefik.http.routers.mastodon-streaming.middlewares=proxyHeader@file,proxyError@file"

  sidekiq:
    image: ghcr.io/mastodon/mastodon:v4.3.2
    restart: always
    env_file:
      - path: .env.production
      - path: .env
        required: false
    command: bundle exec sidekiq
    healthcheck:
      test: ["CMD-SHELL", "ps aux | grep '[s]idekiq\ 6' || false"]
    networks:
      - mastodon
    depends_on:
      - redis