services:
  postgres:
    image: postgres:17
    container_name: mattermost-db
    restart: unless-stopped

    environment:
      POSTGRES_DB: mattermost
      POSTGRES_USER: mattermost
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
      TZ: Europe/Berlin

    volumes:
      - mattermost-db:/var/lib/postgresql/data

    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U mattermost -d mattermost"]
      interval: 10s
      timeout: 5s
      retries: 10

    networks:
      - proxy

  mattermost:
    image: mattermost/mattermost-team-edition:latest
    container_name: mattermost
    restart: unless-stopped

    depends_on:
      postgres:
        condition: service_healthy

    environment:
      TZ: Europe/Berlin

      MM_SQLSETTINGS_DRIVERNAME: postgres
      MM_SQLSETTINGS_DATASOURCE: postgres://mattermost:${POSTGRES_PASSWORD}@postgres:5432/mattermost?sslmode=disable&connect_timeout=10

      MM_SERVICESETTINGS_SITEURL: https://chat.deinedomain.de

    volumes:
      - mattermost-config:/mattermost/config
      - mattermost-data:/mattermost/data
      - mattermost-logs:/mattermost/logs
      - mattermost-plugins:/mattermost/plugins
      - mattermost-clientplugins:/mattermost/client/plugins
      - mattermost-bleve:/mattermost/bleve-indexes

    ports:
      - "8065:8065"

    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:8065/api/v4/system/ping"]
      interval: 30s
      timeout: 10s
      retries: 5

    networks:
      - proxy

networks:
  proxy:
    external: true

volumes:
  mattermost-db:
  mattermost-config:
  mattermost-data:
  mattermost-logs:
  mattermost-plugins:
  mattermost-clientplugins:
  mattermost-bleve: