Skip to content

An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.

4.5 KB
Raw Blame
# documentation: https://forgejo.org/docs
# slogan: Forgejo is a self-hosted lightweight software forge. Easy to install and low maintenance, it just does the job.
# category: git
# tags: version control, collaboration, code, hosting, lightweight, runner, actions, cicd, ci
# logo: svgs/forgejo.svg
# port: 3000

services:
  forgejo:
    image: codeberg.org/forgejo/forgejo:15
    environment:
      - SERVICE_URL_FORGEJO_3000
      - FORGEJO__server__ROOT_URL=${SERVICE_URL_FORGEJO}
      - FORGEJO__migrations__ALLOWED_DOMAINS=${FORGEJO__migrations__ALLOWED_DOMAINS}
      - FORGEJO__migrations__ALLOW_LOCALNETWORKS=${FORGEJO__migrations__ALLOW_LOCALNETWORKS:-false}
      - FORGEJO__server__DOMAIN=${SERVICE_FQDN_FORGEJO}
      - FORGEJO__server__SSH_DOMAIN=${SERVICE_FQDN_FORGEJO}
      - FORGEJO__server__SSH_PORT=${FORGEJO_SSH_PORT:-22222}
      - USER_UID=1000
      - USER_GID=1000
      - RUNNER_SHARED_SECRET=${SERVICE_HEX_64_RUNNER}
      - FORGEJO__security__INSTALL_LOCK=true
      - FORGEJO_ADMIN_USER=${SERVICE_USER_ADMIN}
      - FORGEJO_ADMIN_PASSWORD=${SERVICE_PASSWORD_ADMIN}
      - FORGEJO_ADMIN_EMAIL=${FORGEJO_ADMIN_EMAIL:[email protected]}
      - FORGEJO__repository__ENABLE_PUSH_CREATE_USER=true
      - FORGEJO__repository__DEFAULT_PUSH_CREATE_PRIVATE=false
      - FORGEJO__repository__DEFAULT_REPO_UNITS=repo.code,repo.actions
    volumes:
      - forgejo-data:/data
      - forgejo-timezone:/etc/timezone:ro
      - forgejo-localtime:/etc/localtime:ro
    ports:
      - ${FORGEJO_SSH_PORT:-22222}:22
    # Healthy only after the runner is registered, so the runner starts after it.
    healthcheck:
      test: ["CMD-SHELL", "curl -fs http://127.0.0.1:3000 > /dev/null && test -f /tmp/runner-registered"]
      interval: 5s
      timeout: 10s
      retries: 30
    command: >-
      bash -c '
      /usr/bin/s6-svscan /etc/s6 &
      until su -c "forgejo forgejo-cli actions register --keep-labels --secret $${RUNNER_SHARED_SECRET:0:40}" git ; do sleep 5 ; done ;
      su -c "forgejo admin user create --admin --username \"$$FORGEJO_ADMIN_USER\" --password \"$$FORGEJO_ADMIN_PASSWORD\" --email \"$$FORGEJO_ADMIN_EMAIL\" --must-change-password=false" git || true ;
      touch /tmp/runner-registered ;
      wait
      '

  docker-in-docker:
    image: docker:dind
    hostname: docker
    privileged: true
    healthcheck:
      test: ["CMD", "docker", "-H", "unix:///var/run/docker.sock", "info"]
      interval: 10s
      timeout: 30s
      retries: 10
    environment:
      - DOCKER_TLS_CERTDIR=/certs
      - DOCKER_HOST=docker-in-docker
    volumes:
      - forgejo-did-certs:/certs

  runner-register:
    image: data.forgejo.org/forgejo/runner:13.2.0
    restart: 'no'
    exclude_from_hc: true
    environment:
      - RUNNER_SHARED_SECRET=${SERVICE_HEX_64_RUNNER}
    volumes:
      - forgejo-runner-data:/data
    user: 0:0
    command: >-
      bash -ec '
      secret=$${RUNNER_SHARED_SECRET:0:40} ;
      uuid=$$(printf %s "$${secret:0:16}" | od -An -tx1 | tr -d " \n" | sed -E "s/(.{8})(.{4})(.{4})(.{4})(.{12})/\1-\2-\3-\4-\5/") ;
      forgejo-runner generate-config > config.yml ;
      sed -i -e "s|  labels: \[\]|  labels: [\"docker:docker://node:22-bookworm\", \"ubuntu-latest:docker://catthehacker/ubuntu:act-22.04\", \"ubuntu-22.04:docker://catthehacker/ubuntu:act-22.04\"]|" config.yml ;
      sed -i -e "s|network: .*|network: host|" config.yml ;
      sed -i -e "s|^  envs:$$|  envs:\n    DOCKER_HOST: tcp://docker:2376\n    DOCKER_TLS_VERIFY: 1\n    DOCKER_CERT_PATH: /certs/client|" config.yml ;
      sed -i -e "s|^  options:|  options: -v /certs/client:/certs/client|" config.yml ;
      sed -i -e "s|  valid_volumes: \[\]$$|  valid_volumes:\n    - /certs/client|" config.yml ;
      sed -i -e "s|  connections:|  connections:\n    default:\n      url: http://forgejo:3000\n      uuid: $$uuid\n      token: $$secret|" config.yml ;
      chown -R 1000:1000 /data
      '

  runner:
    image: data.forgejo.org/forgejo/runner:13.2.0
    depends_on:
      forgejo:
        condition: service_healthy
      docker-in-docker:
        condition: service_healthy
      runner-register:
        condition: service_completed_successfully
    environment:
      - DOCKER_HOST=tcp://docker:2376
      - DOCKER_CERT_PATH=/certs/client
      - DOCKER_TLS_VERIFY=1
    user: 1000:1000
    volumes:
      - forgejo-runner-data:/data
      - forgejo-did-certs:/certs
    healthcheck:
      test: ["CMD", "pgrep", "forgejo-runner"]
      interval: 10s
      timeout: 30s
      retries: 10
    command: forgejo-runner --config config.yml daemon