services:
  gitea:
    container_name: gitea
    image: docker.io/gitea/gitea:1.26.2
    restart: unless-stopped
    networks:
      - homelab-network
    security_opt:
      - no-new-privileges:true
    environment:
      - USER_UID=1000
      - USER_GID=1000
      - GITEA__database__DB_TYPE=postgres
      - GITEA__database__HOST=gitea-db
      - GITEA__database__NAME=${GITEA_POSTGRES_DB}
      - GITEA__database__USER=${GITEA_POSTGRES_USER}
      - GITEA__database__PASSWD=${GITEA_POSTGRES_PASSWORD}
      - GITEA__mailer__ENABLED=true
      - GITEA__mailer__FROM=${MAIL_FROM_ADDRESS}
      - GITEA__mailer__PROTOCOL=smtps
      - GITEA__mailer__SMTP_ADDR=${SMTP_HOST}
      - GITEA__mailer__USER=${SMTP_NAME}
      - GITEA__mailer__PASSWD="""${SMTP_PASSWORD}"""
      - GITEA__service__DISABLE_REGISTRATION=true
      - GITEA_RUNNER_REGISTRATION_TOKEN=${GITEA_RUNNER_REGISTRATION_TOKEN}
    volumes:
      - ~/docker-volumes/gitea/data:/data/
      - /etc/timezone:/etc/timezone:ro
      - /etc/localtime:/etc/localtime:ro
    ports:
      - 4020:3000
      - 4021:22
    healthcheck:
      test: ["CMD", "curl", "-f", "https://git.rodneyosodo.com"]
      interval: 10s
      retries: 3
      start_period: 30s
      timeout: 10s

  gitea-db:
    container_name: gitea-db
    image: docker.io/postgres:16.1
    restart: unless-stopped
    networks:
      - homelab-network
    security_opt:
      - no-new-privileges:true
    volumes:
      - ~/docker-volumes/gitea/db:/var/lib/postgresql/data
    environment:
      - POSTGRES_USER=${GITEA_POSTGRES_USER}
      - POSTGRES_PASSWORD=${GITEA_POSTGRES_PASSWORD}
      - POSTGRES_DB=${GITEA_POSTGRES_DB}
    healthcheck:
      test:
        [
          "CMD-SHELL",
          "pg_isready -U '${GITEA_POSTGRES_USER}' -d '${GITEA_POSTGRES_DB}'",
        ]
      interval: 5s
      timeout: 5s
      retries: 5

  gitea-runner:
    container_name: gitea-runner
    image: docker.io/gitea/runner:1.0.7
    restart: unless-stopped
    networks:
      - homelab-network
    security_opt:
      - no-new-privileges:true
    environment:
      - GITEA_INSTANCE_URL=https://git.rodneyosodo.com
      - GITEA_RUNNER_REGISTRATION_TOKEN=${GITEA_RUNNER_REGISTRATION_TOKEN}
    volumes:
      - ~/docker-volumes/gitea/runner/data:/data
      - /var/run/docker.sock:/var/run/docker.sock
    depends_on:
      gitea:
        condition: service_healthy
        restart: true
