diff --git a/infrastructure/ci/gitea-runner/README.md b/infrastructure/ci/gitea-runner/README.md index cf44fff..eba2561 100644 --- a/infrastructure/ci/gitea-runner/README.md +++ b/infrastructure/ci/gitea-runner/README.md @@ -76,43 +76,66 @@ Gradle·Docker 게이트는 `flock /tmp/claude-gates/heavy.lock`으로 서로 ## 디스크와 정리 안쪽 daemon의 데이터(job 이미지, Testcontainers 이미지, 빌드 cache)는 이름 있는 -볼륨 `gitea-runner_docker`에 쌓인다. desktop root 디스크는 228G 중 182G를 쓰고 -있다(2026-11-07, 여유 34G). 예상 사용량은 다음과 같다. +볼륨 `gitea-runner_docker`에 쌓인다. 이 볼륨은 desktop 루트 SSD에 있고, 운영 k3s와 +같은 디스크다. 설치 이틀 만에 16G가 됐다(2026-11-09: 이미지 12.35G, 빌드 cache 3.4G). +2026-11-11에는 이미지 12.43G, 빌드 cache 8.44G였다. -| 항목 | 크기 | -| --- | --- | -| runner 이미지(`gitea/runner:5.4.1-dind`) | 약 133MB | -| job 이미지(`runner-images:ubuntu-24.04`) | amd64 압축 543MB, 안쪽 daemon에서 2.325GB(2026-11-07 실측) | -| Testcontainers 이미지(PostgreSQL, Ryuk 등) | 수백 MB | -| actions/cache(`/data/cache`) | 상한 5GB | +상한은 두 가지로 건다. -runner는 job이 끝나면 job 컨테이너와 proxy로 만든 컨테이너·네트워크·볼륨을 -지우지만(`container.sweep: true`) 이미지는 지우지 않는다. 정리 주기는 다음과 같다. +| 무엇 | 방법 | 값 | +| --- | --- | --- | +| 빌드 cache | `daemon.json`의 BuildKit GC. 안쪽 daemon이 스스로 지운다 | 최소 2GB, 상한 10GB. 디스크 여유가 35GB 아래면 2GB까지 | +| job 이미지 | 호스트 systemd timer `gitea-runner-prune.timer`. 주 1회 | 만든 지 7일 지난 안 쓰는 이미지, 3일 지난 빌드 cache | +| actions/cache | `config.yaml`의 `cache.size_limit` | 5GB | -- 매주 한 번 사용량을 본다. +- BuildKit 키의 뜻과 값을 고른 이유는 [호스트 설정](../../host/README.md)의 + 「BuildKit 상한 값」에 있다. 호스트와 같은 키에 더 작은 값을 쓴다. +- Docker daemon은 이미지를 스스로 지우지 않는다. 그래서 이미지는 timer로 지운다. +- `image prune --filter until=168h`는 이미지를 **만든** 시각으로 거른다. 마지막으로 쓴 + 시각이 아니다. 그래서 고정한 job 이미지(`runner-images:ubuntu-24.04`, 2026-11-03 생성)도 + 지워지고, 다음 job이 압축 약 543MB를 다시 받는다. 실행 중인 job 컨테이너가 쓰는 + 이미지는 지워지지 않는다. +- timer는 일요일 04:30(KST)에 돈다. 그 시각에 꺼져 있었으면 다음 부팅 때 돈다 + (`Persistent=true`). service는 `donghyeon` 사용자(docker group)로 돌아 root가 필요 없다. - ```bash - docker system df -v | grep gitea-runner - docker exec gitea-runner docker system df - ``` +설치(소유자, sudo 한 번): -- 안쪽 사용량이 15GB를 넘거나 root 디스크 여유가 20G 아래로 내려가면 job이 없을 때 - 안쪽 이미지를 정리한다. 고정된 job 이미지도 지워지므로 다음 job이 압축 약 543MB를 - 다시 받는다. +```bash +sudo install -m 0644 infrastructure/ci/gitea-runner/gitea-runner-prune.service \ + infrastructure/ci/gitea-runner/gitea-runner-prune.timer /etc/systemd/system/ +sudo systemctl daemon-reload +sudo systemctl enable --now gitea-runner-prune.timer +systemctl list-timers gitea-runner-prune.timer +``` - ```bash - docker exec gitea-runner docker image prune -a -f - docker exec gitea-runner docker builder prune -f - ``` +바로 한 번 돌리려면 job이 없을 때 `sudo systemctl start gitea-runner-prune.service`를 +실행하고 `journalctl -u gitea-runner-prune.service -n 30`으로 결과를 본다. -- 볼륨 `gitea-runner_docker` 자체를 지우는 것은 runner를 완전히 지울 때만 한다 - (「되돌리기」). 등록 파일이 있는 `gitea-runner_data`와 섞지 않는다. +되돌리기: + +```bash +sudo systemctl disable --now gitea-runner-prune.timer +sudo rm /etc/systemd/system/gitea-runner-prune.service /etc/systemd/system/gitea-runner-prune.timer +sudo systemctl daemon-reload +``` + +사용량 보기: + +```bash +docker system df -v | grep gitea-runner +docker exec gitea-runner docker system df +docker exec gitea-runner docker buildx inspect default | sed -n '/GC Policy rule#1/,/Min Free/p' +``` + +볼륨 `gitea-runner_docker` 자체를 지우는 것은 runner를 완전히 지울 때만 한다 +(「되돌리기」). 등록 파일이 있는 `gitea-runner_data`와 섞지 않는다. ## 파일과 위치 | 무엇 | 위치 | | --- | --- | -| 원본 설정 | 이 디렉터리의 `compose.yaml`, `config.yaml` | +| 원본 설정 | 이 디렉터리의 `compose.yaml`, `config.yaml`, `daemon.json` | +| 주 1회 정리 | 이 디렉터리의 `gitea-runner-prune.service`·`.timer` → `/etc/systemd/system/` | | desktop 실행 폴더 | `/home/donghyeon/.local/share/gitea-runner/` (`compose.yaml`, `config.yaml`, `secrets/`) | | 등록 파일 `.runner` | Docker 볼륨 `gitea-runner_data`의 `/data/.runner` (runner 자격 증명, Secret으로 취급) | | job 이미지·안쪽 daemon 데이터 | Docker 볼륨 `gitea-runner_docker` (`/var/lib/docker`) | @@ -133,8 +156,10 @@ runner는 job이 끝나면 job 컨테이너와 proxy로 만든 컨테이너·네 ```bash install -d -m 0700 ~/.local/share/gitea-runner ~/.local/share/gitea-runner/secrets - install -m 0644 infrastructure/ci/gitea-runner/compose.yaml infrastructure/ci/gitea-runner/config.yaml ~/.local/share/gitea-runner/ - sha256sum infrastructure/ci/gitea-runner/*.yaml ~/.local/share/gitea-runner/*.yaml + install -m 0644 infrastructure/ci/gitea-runner/compose.yaml infrastructure/ci/gitea-runner/config.yaml \ + infrastructure/ci/gitea-runner/daemon.json ~/.local/share/gitea-runner/ + sha256sum infrastructure/ci/gitea-runner/{compose.yaml,config.yaml,daemon.json} \ + ~/.local/share/gitea-runner/{compose.yaml,config.yaml,daemon.json} ``` 2. 등록 token을 편집기로 `~/.local/share/gitea-runner/secrets/registration-token`에 @@ -170,7 +195,7 @@ runner는 job이 끝나면 job 컨테이너와 proxy로 만든 컨테이너·네 재생성은 실행 중인 job을 취소하므로 job이 없을 때 한다. - 이미지 올리기: `compose.yaml`의 tag와 digest를 함께 바꾼다. 등록 파일은 그대로 유효하다. major가 바뀌면 [Upgrading](https://docs.gitea.com/runner/upgrade/)의 호환 변경을 먼저 읽는다. -- 디스크: 「디스크와 정리」의 주기를 따른다. +- 디스크: 「디스크와 정리」의 상한과 timer가 맡는다. 매주 `list-timers`로 마지막 실행을 본다. ## 되돌리기 diff --git a/infrastructure/ci/gitea-runner/compose.yaml b/infrastructure/ci/gitea-runner/compose.yaml index 8973b99..848bcb5 100644 --- a/infrastructure/ci/gitea-runner/compose.yaml +++ b/infrastructure/ci/gitea-runner/compose.yaml @@ -22,6 +22,8 @@ services: CONFIG_FILE: /config.yaml volumes: - ./config.yaml:/config.yaml:ro + # Caps the build cache of the inner Docker daemon. See README.md. + - ./daemon.json:/etc/docker/daemon.json:ro - ./secrets:/run/gitea-runner:ro - data:/data - docker:/var/lib/docker diff --git a/infrastructure/ci/gitea-runner/daemon.json b/infrastructure/ci/gitea-runner/daemon.json new file mode 100644 index 0000000..6777ff6 --- /dev/null +++ b/infrastructure/ci/gitea-runner/daemon.json @@ -0,0 +1,10 @@ +{ + "builder": { + "gc": { + "enabled": true, + "defaultReservedSpace": "2GB", + "defaultMaxUsedSpace": "10GB", + "defaultMinFreeSpace": "35GB" + } + } +} diff --git a/infrastructure/ci/gitea-runner/gitea-runner-prune.service b/infrastructure/ci/gitea-runner/gitea-runner-prune.service new file mode 100644 index 0000000..ac87845 --- /dev/null +++ b/infrastructure/ci/gitea-runner/gitea-runner-prune.service @@ -0,0 +1,17 @@ +# Weekly cleanup of the Docker daemon inside the gitea-runner container. +# Installed by infrastructure/ci/gitea-runner/README.md ("디스크와 정리"). +[Unit] +Description=Prune old images and build cache in the Gitea runner Docker +Requires=docker.service +After=docker.service + +[Service] +Type=oneshot +# The docker group is enough for docker exec. No root needed at run time. +User=donghyeon +Group=docker +# image prune keeps images used by a running job container; until= filters +# on image creation time, so the pinned job image is pulled again after a week. +ExecStart=/usr/bin/docker exec gitea-runner docker image prune --all --force --filter until=168h +ExecStart=/usr/bin/docker exec gitea-runner docker builder prune --all --force --filter until=72h +ExecStartPost=/usr/bin/docker exec gitea-runner docker system df diff --git a/infrastructure/ci/gitea-runner/gitea-runner-prune.timer b/infrastructure/ci/gitea-runner/gitea-runner-prune.timer new file mode 100644 index 0000000..9cab1ad --- /dev/null +++ b/infrastructure/ci/gitea-runner/gitea-runner-prune.timer @@ -0,0 +1,12 @@ +[Unit] +Description=Weekly prune of the Gitea runner Docker + +[Timer] +# Sunday 04:30 local time (Asia/Seoul), when CI and agent sessions are quiet. +OnCalendar=Sun *-*-* 04:30:00 +RandomizedDelaySec=30min +# Run at the next boot if the machine was off at that time. +Persistent=true + +[Install] +WantedBy=timers.target