Initial commit: Gitea CI jobs in gVisor with sandboxed Docker

This commit is contained in:
agentbox committed 2026-11-05 11:30:31 +00:00
commit 6c14f5d76d
17 files changed
+1084

No files matched your search

+158
View File
@@ -0,0 +1,158 @@
#!/usr/bin/env bash
set -euo pipefail
# End-to-end check for the gVisor-backed Gitea runner.
#
# Run from the deployment directory:
# ./scripts/e2e-test.sh
#
# Environment overrides:
# GITEA_URL default http://localhost:3000
# ADMIN_USER default ciadmin
# ADMIN_PASSWORD default CiAdminPass12345
# REPO default gvisor-e2e-<timestamp>
cd "$(dirname "$0")/.."
GITEA_URL="${GITEA_URL:-http://localhost:3000}"
GITEA_URL="${GITEA_URL%/}"
ADMIN_USER="${ADMIN_USER:-ciadmin}"
ADMIN_PASSWORD="${ADMIN_PASSWORD:-CiAdminPass12345}"
REPO="${REPO:-gvisor-e2e-$(date +%s)}"
WORKFLOW="${WORKFLOW:-scripts/workflow-gvisor.yml}"
SHOW_LOGS="${SHOW_LOGS:-0}"
api() {
curl -fsS -u "${ADMIN_USER}:${ADMIN_PASSWORD}" "$@"
}
echo "==> Building the runner image"
docker build -t gitea-gvisor-runner:latest runner >/dev/null
echo "==> Starting Gitea"
docker compose up -d --no-build gitea >/dev/null
echo "==> Waiting for Gitea at ${GITEA_URL}"
for _ in $(seq 1 90); do
if curl -fsS "${GITEA_URL}/api/healthz" >/dev/null 2>&1; then
break
fi
sleep 2
done
curl -fsS "${GITEA_URL}/api/healthz" >/dev/null
echo "==> Creating admin user (ignore error if it already exists)"
docker compose exec -T -u git gitea gitea admin user create \
--username "${ADMIN_USER}" \
--password "${ADMIN_PASSWORD}" \
--email "${ADMIN_USER}@example.com" \
--admin --must-change-password=false >/dev/null 2>&1 || true
echo "==> Starting runner (auto-registers through the Gitea API)"
GITEA_ADMIN_USER="${ADMIN_USER}" \
GITEA_ADMIN_PASSWORD="${ADMIN_PASSWORD}" \
docker compose up -d --no-build --force-recreate runner >/dev/null
echo "==> Waiting for the runner to come online"
online=0
for _ in $(seq 1 90); do
if api "${GITEA_URL}/api/v1/admin/actions/runners" | grep -q '"status":"online"'; then
online=1
break
fi
sleep 2
done
if [ "${online}" != 1 ]; then
docker compose logs --tail 100 runner
echo "Runner did not come online" >&2
exit 1
fi
echo "==> Creating repository ${ADMIN_USER}/${REPO}"
api -H 'Content-Type: application/json' \
-d "{\"name\":\"${REPO}\",\"private\":false,\"auto_init\":false}" \
"${GITEA_URL}/api/v1/user/repos" >/dev/null 2>&1 || true
tmp="$(mktemp -d)"
trap 'rm -rf "${tmp}"' EXIT
export GIT_CONFIG_GLOBAL="${tmp}/gitconfig"
git config --global user.name "gVisor CI Test"
git config --global user.email "gvisor-ci@example.com"
git config --global init.defaultBranch main
# URL-encode the password minimally for HTTP basic auth in the remote URL.
remote="http://${ADMIN_USER}:${ADMIN_PASSWORD}@${GITEA_URL#http://}/${ADMIN_USER}/${REPO}.git"
echo "==> Pushing workflow to ${ADMIN_USER}/${REPO}"
git clone -q "${remote}" "${tmp}/repo" 2>/dev/null || {
mkdir -p "${tmp}/repo"
git -C "${tmp}/repo" init -q
git -C "${tmp}/repo" remote add origin "${remote}"
}
mkdir -p "${tmp}/repo/.gitea/workflows"
cp "${WORKFLOW}" "${tmp}/repo/.gitea/workflows/gvisor-isolation.yml"
git -C "${tmp}/repo" add .gitea/workflows/gvisor-isolation.yml
git -C "${tmp}/repo" commit -q -m "test: run a job inside gVisor"
git -C "${tmp}/repo" push -q origin HEAD:main
echo "==> Waiting for the workflow run"
run_id=""
status=""
conclusion=""
for _ in $(seq 1 180); do
runs_json=$(api "${GITEA_URL}/api/v1/repos/${ADMIN_USER}/${REPO}/actions/runs" || true)
read -r run_id status conclusion <<< "$(printf '%s' "${runs_json}" | python3 -c '
import json, sys
try:
data = json.load(sys.stdin)
except Exception:
print("")
raise SystemExit(0)
runs = data.get("workflow_runs", data.get("runs", []))
if runs:
r = runs[0]
print(r.get("id", ""), r.get("status", ""), r.get("conclusion", ""))
')"
if [ -n "${run_id}" ] && [ "${status}" = "completed" ]; then
break
fi
sleep 2
done
if [ -z "${run_id}" ]; then
echo "No workflow run was created" >&2
docker compose logs --tail 120 runner
exit 1
fi
echo "==> Workflow run ${run_id}: status=${status} conclusion=${conclusion}"
jobs_json=$(api "${GITEA_URL}/api/v1/repos/${ADMIN_USER}/${REPO}/actions/runs/${run_id}/jobs" || true)
printf '%s' "${jobs_json}" | python3 -m json.tool || true
job_id=$(printf '%s' "${jobs_json}" | python3 -c '
import json, sys
try:
data = json.load(sys.stdin)
except Exception:
print("")
raise SystemExit(0)
jobs = data.get("jobs", data if isinstance(data, list) else [])
print(jobs[0]["id"] if jobs else "")
')
if [ "${conclusion}" != "success" ] || [ "${SHOW_LOGS}" = "1" ]; then
if [ "${conclusion}" != "success" ]; then
echo "Workflow failed; fetching logs" >&2
else
echo "==> Job logs"
fi
if [ -n "${job_id}" ]; then
api "${GITEA_URL}/api/v1/repos/${ADMIN_USER}/${REPO}/actions/jobs/${job_id}/logs" || true
fi
fi
if [ "${conclusion}" != "success" ]; then
exit 1
fi
echo "==> PASS: the workflow ran successfully inside gVisor"
+53
View File
@@ -0,0 +1,53 @@
name: sandboxed-compose-e2e
on:
push:
branches: [main]
workflow_dispatch:
jobs:
compose-e2e:
runs-on: docker
steps:
- name: Write a real Compose file
shell: sh
run: |
set -eu
cat > docker-compose.yml <<'YAML'
services:
web:
image: nginx:alpine
networks:
testnet:
ipv4_address: 172.31.0.10
probe:
image: alpine:3.20
depends_on:
- web
networks:
- testnet
# Docker's embedded DNS at 127.0.0.11 needs Docker-managed
# iptables, which is disabled inside gVisor. Map the service
# name explicitly instead.
extra_hosts:
- "web:172.31.0.10"
command: sh -c "wget -qO- --timeout=10 http://web:80 | grep -q 'Welcome to nginx'"
networks:
testnet:
ipam:
config:
- subnet: 172.31.0.0/24
YAML
docker compose config >/dev/null
- name: Up, probe, down
shell: sh
run: |
set -eu
docker compose up -d web
docker compose run --rm probe
docker compose ps
docker compose down -v
echo "OK: Compose stack ran inside the sandboxed Docker daemon"
+54
View File
@@ -0,0 +1,54 @@
name: sandboxed-docker-e2e
on:
push:
branches: [main]
workflow_dispatch:
jobs:
docker-e2e:
# docker:28-cli has the Docker CLI; DOCKER_HOST is injected by the runner
# and points at the gVisor-sandboxed daemon, not the runner's own daemon.
runs-on: docker
steps:
- name: Talk to the sandboxed Docker daemon
shell: sh
run: |
set -eu
docker info | grep -E 'Server Version|Storage Driver|Cgroup Version'
docker run --rm alpine:3.20 sh -c '
grep -qi gvisor /proc/version
echo "nested kernel: $(uname -r)"
cat /proc/version
'
- name: Nested containers have networking
shell: sh
run: |
set -eu
docker rm -f gvisor-e2e-web >/dev/null 2>&1 || true
docker network rm gvisor-e2e-net >/dev/null 2>&1 || true
docker network create gvisor-e2e-net >/dev/null
docker run -d --name gvisor-e2e-web --network gvisor-e2e-net nginx:alpine >/dev/null
web_ip=$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' gvisor-e2e-web)
test -n "${web_ip}"
for i in $(seq 1 30); do
if docker run --rm --network gvisor-e2e-net alpine:3.20 \
wget -qO- --timeout=2 "http://${web_ip}:80" 2>/dev/null | grep -q "Welcome to nginx"; then
break
fi
sleep 1
done
docker run --rm --network gvisor-e2e-net alpine:3.20 \
wget -qO- --timeout=5 "http://${web_ip}:80" | grep -q "Welcome to nginx"
docker run --rm alpine:3.20 sh -c \
'wget -qO- --timeout=10 http://example.com >/dev/null'
docker rm -f gvisor-e2e-web >/dev/null
docker network rm gvisor-e2e-net >/dev/null
- name: The privileged runner socket is still hidden
shell: sh
run: |
set -eu
test ! -S /var/run/docker.sock
echo "OK: /var/run/docker.sock is not present"
+52
View File
@@ -0,0 +1,52 @@
name: gvisor-isolation
on:
push:
branches: [main]
workflow_dispatch:
jobs:
verify:
# This label is mapped in runner/config.yaml to alpine:3.20. Every job
# container is created by the nested dockerd with default-runtime=runsc.
runs-on: gvisor
steps:
- name: Prove the job runs on the gVisor kernel
shell: sh
run: |
set -eu
echo "uname: $(uname -a)"
echo "proc/version: $(cat /proc/version)"
grep -qi gvisor /proc/version
echo "OK: workflow is running inside gVisor"
- name: The privileged runner socket is hidden; only the sandboxed daemon is reachable
shell: sh
run: |
set -eu
if [ -S /var/run/docker.sock ]; then
echo "ERROR: the privileged runner Docker socket leaked into the job" >&2
exit 1
fi
# TCP 2375 belongs to the separate gVisor-sandboxed Docker daemon.
test "$(wget -qO- --timeout=5 http://127.0.0.1:2375/_ping)" = "OK"
echo "OK: privileged socket hidden; sandboxed Docker daemon is reachable"
- name: Prove service DNS and network access work
shell: sh
run: |
set -eu
wget -qO- --timeout=10 http://gitea:3000/api/healthz >/dev/null
echo "OK: the job can reach Gitea by service name"
- name: Prove the outer Docker host API is not reachable
shell: sh
run: |
set -eu
gateway=$(ip route | awk '/^default / {print $3; exit}')
echo "gateway=${gateway}"
if wget -qO- --timeout=3 "http://${gateway}:2375/version" >/dev/null 2>&1; then
echo "ERROR: the outer Docker host API is reachable from the job" >&2
exit 1
fi
echo "OK: outer Docker host API blocked; Gitea/internet still work"
+58
View File
@@ -0,0 +1,58 @@
name: gvisor-resource-test
on:
push:
branches: [main]
workflow_dispatch:
jobs:
resource-test:
runs-on: gvisor
steps:
- name: Environment
shell: sh
run: |
set -eu
grep -qi gvisor /proc/version
echo "kernel: $(uname -r)"
echo "nproc: $(nproc)"
free -m || true
df -h .
- name: Disk I/O (2 GiB write + read)
shell: sh
run: |
set -eu
echo "Writing 2 GiB to the job workspace..."
sync
dd if=/dev/zero of=./gvisor-disk-test bs=1M count=2048 2>&1 | tail -1
sync
echo "Reading 2 GiB back..."
dd if=./gvisor-disk-test of=/dev/null bs=1M 2>&1 | tail -1
ls -lh ./gvisor-disk-test
rm -f ./gvisor-disk-test
- name: Memory allocation (2 GiB)
shell: sh
run: |
set -eu
start=$(date +%s)
# BusyBox awk: create 2048 one-MiB strings and touch them so the
# allocation really happens inside the gVisor sandbox.
awk 'BEGIN {
for (i = 0; i < 2048; i++) a[i] = sprintf("%01048576s", "");
# Touch every string so the pages really stay resident.
for (i = 0; i < 2048; i++) if (length(a[i]) != 1048576) exit 1;
printf "allocated=%d MiB\n", 2048;
}'
end=$(date +%s)
echo "elapsed_s=$((end - start))"
- name: CPU scheduling (1 core, then 4 parallel workers)
shell: sh
run: |
set -eu
echo "Single-core awk integer loop:"
time awk 'BEGIN { for (i = 0; i < 10000000; i++) x += i; print x }'
echo "Four parallel awk loops:"
time sh -c 'for i in 1 2 3 4; do awk "BEGIN { for (i = 0; i < 5000000; i++) x += i; print x }" & done; wait'