services:
  forgejo-db:
    image: postgres:16-alpine
    container_name: forgejo-local-db
    restart: unless-stopped
    environment:
      POSTGRES_DB: ${POSTGRES_DB}
      POSTGRES_USER: ${POSTGRES_USER}
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
    volumes:
      - ./db:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER} -d ${POSTGRES_DB}"]
      interval: 10s
      timeout: 5s
      retries: 10

  forgejo:
    image: codeberg.org/forgejo/forgejo:11-rootless
    container_name: forgejo-local
    restart: unless-stopped
    depends_on:
      forgejo-db:
        condition: service_healthy
    environment:
      USER_UID: "1000"
      USER_GID: "1000"
      FORGEJO__database__DB_TYPE: postgres
      FORGEJO__database__HOST: forgejo-db:5432
      FORGEJO__database__NAME: ${POSTGRES_DB}
      FORGEJO__database__USER: ${FORGEJO_DB_USER}
      FORGEJO__database__PASSWD: ${FORGEJO_DB_PASSWORD}
      FORGEJO__security__SECRET_KEY: ${FORGEJO_SECRET_KEY}
      FORGEJO__security__INTERNAL_TOKEN: ${FORGEJO_INTERNAL_TOKEN}
      FORGEJO__server__DOMAIN: localhost
      FORGEJO__server__ROOT_URL: http://localhost:${FORGEJO_HTTP_PORT}/
      FORGEJO__server__SSH_DOMAIN: localhost
      FORGEJO__server__SSH_PORT: ${FORGEJO_SSH_PORT}
      FORGEJO__server__START_SSH_SERVER: "true"
      FORGEJO__service__DISABLE_REGISTRATION: "false"
      FORGEJO__service__REQUIRE_SIGNIN_VIEW: "false"
      FORGEJO__picture__DISABLE_GRAVATAR: "true"
      FORGEJO__lfs__JWT_SECRET: ${FORGEJO_LFS_JWT_SECRET}
      FORGEJO__actions__ENABLED: "true"
    ports:
      - "${FORGEJO_HTTP_PORT}:3000"
      - "${FORGEJO_SSH_PORT}:2222"
    volumes:
      - ./data:/var/lib/gitea

