Files
act_runner/docker-compose.yml
T
nampdn 98b47cc42b Cache lên volume, ghim image theo digest, xoá runner.sh lộ token
1) Cache act_runner phải nằm trên volume.
   Mặc định cache.dir rỗng -> act_runner ghi vào $HOME/.cache/actcache, tức
   WRITABLE LAYER của container. Đo thực tế trên ba máy: 278 GB / 95 GB / 32 GB
   nằm ở đó, mất sạch chỉ với một lệnh docker compose up -d.
   Thêm volume runner-cache mount vào /cache và đặt cache.dir="/cache".
   Hai chỗ này phải luôn đổi cùng nhau.

2) Ghim image theo digest thay vì :nightly.
   Tag tự cập nhật nghĩa là compose pull có thể tạo lại container sau lưng, kéo
   theo mất cache. Nâng cấp có chủ đích: đổi digest, commit, rồi mới áp dụng.

3) XOÁ runner.sh.
   Nó lỗi thời (đã thay bằng docker compose) và quan trọng hơn: nó chứa
   GITEA_RUNNER_REGISTRATION_TOKEN dạng plaintext đã commit vào git. Ai có token
   đó đăng ký được runner vào Gitea, tức chạy job tuỳ ý trên hạ tầng này.
   XOÁ FILE LÀ CHƯA ĐỦ - token vẫn nằm trong lịch sử git, BẮT BUỘC phải thu hồi
   và cấp lại token trong Gitea.

4) README: bổ sung bước clone cho máy builder mới, cảnh báo phải kiểm tra job
   đang chạy trước khi tạo lại runner (tạo lại là mồ côi job đang chạy), và
   phần dọn rác trong DinD (image/volume/build cache không tự dọn - một máy đo
   được 515 image thừa và 71 GB build cache).
2026-08-28 16:09:11 +00:00

75 lines
3.1 KiB
YAML

services:
# Isolated Docker daemon for the runner's job containers.
# Keeps the host Docker clean and gives reliable cache networking.
dind:
image: docker:27-dind
container_name: gitea-runner-dind
privileged: true
restart: unless-stopped
# The third --host exposes the daemon over a unix socket on a volume shared
# with the runner (dind-sock), *in addition to* its own /var/run/docker.sock.
# act_runner's job-container DooD wiring only understands unix:// (or bare)
# socket paths -- it bind-mounts that path from ITS OWN filesystem into every
# job container as /var/run/docker.sock, it does not pass DOCKER_HOST through
# as an env var. A bare "tcp://..." isn't recognized and silently falls back
# to /var/run/docker.sock, which doesn't exist in the runner container -- so
# this shared socket is what makes `docker build` etc. work inside jobs.
command: ["dockerd", "--host=tcp://0.0.0.0:2375", "--host=unix:///var/run/docker.sock", "--host=unix:///dind-sock/docker.sock", "--tls=false"]
environment:
DOCKER_TLS_CERTDIR: ""
networks:
- runner
volumes:
# Persist pulled job images + docker layer cache => fast Rust rebuilds.
- dind-storage:/var/lib/docker
# Shared with the runner container; see the --host comment above.
- dind-sock:/dind-sock
healthcheck:
test: ["CMD", "docker", "info"]
interval: 5s
timeout: 3s
retries: 10
start_period: 10s
runner:
# Ghim theo digest, KHÔNG dùng :nightly. Tag tự cập nhật + cache nằm trong
# writable layer = một lệnh 'compose pull' là mất sạch cache.
# Nâng cấp có chủ đích: đổi digest ở đây rồi commit.
image: docker.io/gitea/act_runner@sha256:7940221bcfc9df16f3401ddafb2231bf98bba5517bc381224c7a2c504b558974
container_name: gitea-runner-wsl
restart: unless-stopped
depends_on:
dind:
condition: service_healthy
networks:
- runner
environment:
GITEA_INSTANCE_URL: ${GITEA_INSTANCE_URL}
GITEA_RUNNER_REGISTRATION_TOKEN: ${GITEA_RUNNER_REGISTRATION_TOKEN}
GITEA_RUNNER_NAME: ${GITEA_RUNNER_NAME}
GITEA_RUNNER_LABELS: ""
# Point the runner at the DinD daemon. Overridden at startup by act_runner
# itself to config.yaml's container.docker_host (the unix socket below),
# since our labels require docker; kept here as a documented fallback.
DOCKER_HOST: tcp://dind:2375
CONFIG_FILE: /config.yaml
volumes:
- ./config.yaml:/config.yaml:ro
# Persist runner registration so it survives restarts.
- runner-data:/data
# Shared with dind; see the --host comment on the dind service.
- dind-sock:/dind-sock
# Cache của actions/cache. Mặc định act_runner ghi vào
# $HOME/.cache/actcache = WRITABLE LAYER của container -> mất sạch mỗi
# lần container bị tạo lại. Phải khớp với cache.dir trong config.yaml.
- runner-cache:/cache
networks:
runner:
volumes:
dind-storage:
runner-data:
dind-sock:
runner-cache: