## Denne stack er justeret mod den nuvaerende Synology Gitea-DB opsaetning.
## Hvis den eksisterende Gitea-container bruger andre porte eller paths, skal de tilpasses i .env.infrastructure.

services:
  mosquitto:
    container_name: mosquitto
    image: eclipse-mosquitto:2
    restart: unless-stopped
    ports:
      - "1883:1883"
      - "9001:9001"
    volumes:
      - ${DOCKER_ROOT:-/volume1/docker}/mosquitto/config:/mosquitto/config
      - ${DOCKER_ROOT:-/volume1/docker}/mosquitto/data:/mosquitto/data
      - ${DOCKER_ROOT:-/volume1/docker}/mosquitto/log:/mosquitto/log
    healthcheck:
      test: ["CMD-SHELL", "mosquitto_sub -h 127.0.0.1 -p 1883 -t '$$SYS/broker/version' -C 1 -W 3 >/dev/null 2>&1 || exit 1"]
      interval: 30s
      timeout: 10s
      retries: 5
      start_period: 20s

  gitea-db:
    container_name: gitea-db
    image: postgres:${GITEA_DB_IMAGE_TAG:-17}
    restart: unless-stopped
    environment:
      POSTGRES_DB: ${GITEA_DB_NAME:-gitea}
      POSTGRES_USER: ${GITEA_DB_USER:-giteauser}
      POSTGRES_PASSWORD: ${GITEA_DB_PASSWORD}
    volumes:
      - ${GITEA_DB_DATA_PATH:-/volume1/docker/gitea/db}:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U ${GITEA_DB_USER:-giteauser} -d ${GITEA_DB_NAME:-gitea}"]
      interval: 15s
      timeout: 5s
      retries: 10
      start_period: 20s

  gitea:
    container_name: gitea
    image: gitea/gitea:${GITEA_IMAGE_TAG:-latest}
    restart: unless-stopped
    depends_on:
      gitea-db:
        condition: service_healthy
    environment:
      USER: git
      GITEA_CUSTOM: ${GITEA_CUSTOM_PATH:-/data/gitea}
      USER_UID: ${PUID:-1038}
      USER_GID: ${PGID:-100}
      GITEA__database__DB_TYPE: postgres
      GITEA__database__HOST: gitea-db:5432
      GITEA__database__NAME: ${GITEA_DB_NAME:-gitea}
      GITEA__database__USER: ${GITEA_DB_USER:-giteauser}
      GITEA__database__PASSWD: ${GITEA_DB_PASSWORD}
      GITEA__server__DOMAIN: ${GITEA_DOMAIN:-dethlefsen}
      GITEA__server__ROOT_URL: ${GITEA_ROOT_URL:-http://dethlefsen:12080/}
      GITEA__server__SSH_DOMAIN: ${GITEA_SSH_DOMAIN:-dethlefsen}
      GITEA__server__SSH_PORT: ${GITEA_SSH_PORT:-12022}
    ports:
      - "${GITEA_HTTP_PORT:-12080}:3000"
      - "${GITEA_SSH_PORT:-12022}:22"
    volumes:
      - ${GITEA_DATA_PATH:-/volume1/docker/gitea/data}:/data
      - /etc/localtime:/etc/localtime:ro
    healthcheck:
      test: ["CMD-SHELL", "wget -q --spider http://127.0.0.1:3000/ || exit 1"]
      interval: 30s
      timeout: 10s
      retries: 10
      start_period: 40s