
services:
  mastodon:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: mastodon
    restart: always
    env_file:
      - .env.production
    ports:
      - "3001:3000"   # External 3001 maps to internal 3000 (web)
      - "4001:4000"   # External 4001 maps to internal 4000 (streaming)
    depends_on:
      - db
      - redis
      - es
    volumes:
      - mastodon_system:/mastodon/public/system
      - mastodon_log:/mastodon/log
      - mastodon_tmp:/mastodon/tmp
    networks:
      - mastodon_network
    # Adjust the user to match the UID and GID created in the Dockerfile.
    user: "1001:1002"

  es:
    image: elasticsearch:7.17.10
    container_name: mastodon-es
    restart: always
    environment:
      - discovery.type=single-node
      - xpack.security.enabled=false
    ports:
      - "9200:9200"
    volumes:
      - ./elasticsearch_data:/usr/share/elasticsearch/data
    networks:
      - mastodon_network

  db:
    image: postgres:15
    container_name: mastodon-db
    restart: always
    environment:
      POSTGRES_DB: dom_mastodon
      POSTGRES_USER: dom_production
      POSTGRES_PASSWORD: DomDomRW93
    volumes:
      - postgres_data:/var/lib/postgresql/data
      - /home/dom/mastodon/database_setup.sql:/docker-entrypoint-initdb.d/database_setup.sql
    networks:
      - mastodon_network

  redis:
    image: redis:7
    container_name: mastodon-redis
    restart: always
    volumes:
      - redis_data:/data
    networks:
      - mastodon_network

networks:
  mastodon_network:
    driver: bridge

volumes:
  mastodon_system:
    driver: local
  mastodon_log:
    driver: local
  mastodon_tmp:
    driver: local
  postgres_data:
    driver: local
  redis_data:
    driver: local
