services:
  server:
    image: docker.gitea.com/gitea:latest
    container_name: gitea
    environment:
      - USER_UID=${USER_UID}
      - USER_GID=${USER_GID}
      - GITEA__database__DB_TYPE=postgres
      - GITEA__database__HOST=db:5432
      - GITEA__database__NAME=${POSTGRES_USER}
      - GITEA__database__USER=${POSTGRES_USER}
      - GITEA__database__PASSWD=${POSTGRES_PASSWORD}
    restart: always
    networks:
      - gitea
    volumes:
      - gitea:/data
      - /etc/timezone:/etc/timezone:ro
      - /etc/localtime:/etc/localtime:ro
    ports:
      - ${GITEA_HTTP_PORT:-3500}:3000
      - ${GITEA_SSH_PORT:-2229}:22
    depends_on:
      - db
    labels:
      - diun.enable=true
    healthcheck:
      test:
        - CMD
        - curl
        - -f
        - http://localhost
      interval: 10s
      retries: 3
      start_period: 30s
      timeout: 10s
      
  db:
    image: docker.io/library/postgres:14
    restart: always
    environment:
      - POSTGRES_USER=${POSTGRES_USER}
      - POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
      - POSTGRES_DB=${POSTGRES_DB}
    networks:
      - gitea
    volumes:
      - postgres:/var/lib/postgresql/data

  runner:
    image: gitea/act_runner:latest
    container_name: gitea-runner
    restart: always
    networks:
      - gitea
    volumes:
      - runner:/data
      - /var/run/docker.sock:/var/run/docker.sock
    environment:
      - GITEA_INSTANCE_URL=http://server:3000
      - GITEA_RUNNER_REGISTRATION_TOKEN=${GITEA_RUNNER_REGISTRATION_TOKEN}
      - GITEA_RUNNER_NAME=docker-runner
    depends_on:
      - server
    labels:
      - diun.enable=true

networks:
  gitea:
    external: false
    
volumes:
  gitea:
  postgres:
  runner:
