Match compose layout to production dind + runner deployment
This commit is contained in:
1 parent
6d04a924e3
commit
6f2c451187
17 files changed
+303
-785
No files matched your search
@@ -1,31 +0,0 @@
|
||||
FROM gitea/act_runner:0.6.1-dind
|
||||
|
||||
# gVisor release used to sandbox every CI job container.
|
||||
ARG GVISOR_RELEASE=release-20261102.0
|
||||
|
||||
RUN apk add --no-cache curl tar bzip2 \
|
||||
&& curl -fsSL "https://github.com/google/gvisor/releases/download/${GVISOR_RELEASE}/gvisor-x86_64.tar.bz2" \
|
||||
| tar -xj -C /usr/local/bin \
|
||||
&& chmod +x /usr/local/bin/runsc \
|
||||
/usr/local/bin/containerd-shim-runsc-v1 \
|
||||
/usr/local/bin/gvisor-bin/* \
|
||||
&& runsc --version
|
||||
|
||||
COPY daemon.json /etc/docker/daemon.json
|
||||
COPY config.yaml /etc/act_runner/config.yaml
|
||||
COPY gvisor-entrypoint.sh /usr/local/bin/gvisor-entrypoint.sh
|
||||
COPY act-runner-run.sh /etc/s6/act_runner/run
|
||||
COPY docker-run.sh /etc/s6/docker/run
|
||||
COPY start-sandboxed-dind.sh /usr/local/bin/start-sandboxed-dind.sh
|
||||
COPY start-dind.sh /opt/gvisor-dind/start-dind.sh
|
||||
RUN chmod +x /usr/local/bin/gvisor-entrypoint.sh \
|
||||
/usr/local/bin/start-sandboxed-dind.sh \
|
||||
/etc/s6/act_runner/run \
|
||||
/etc/s6/docker/run \
|
||||
/opt/gvisor-dind/start-dind.sh
|
||||
|
||||
ENV CONFIG_FILE=/etc/act_runner/config.yaml
|
||||
|
||||
# Keep the base image's s6 supervision (starts dockerd, then act_runner).
|
||||
ENTRYPOINT ["/usr/local/bin/gvisor-entrypoint.sh"]
|
||||
CMD ["s6-svscan", "/etc/s6"]
|
||||
@@ -1,16 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
set -eu
|
||||
|
||||
# The stock image waits for the Docker s6 service to report "ready". On slow
|
||||
# nested hosts s6-notifyoncheck can time out before dockerd finishes starting,
|
||||
# leaving act_runner blocked forever. Wait for the daemon itself instead.
|
||||
while ! docker info >/dev/null 2>&1; do
|
||||
sleep 1
|
||||
done
|
||||
|
||||
# Start the Docker daemon that CI jobs are allowed to use. It is itself inside
|
||||
# a gVisor sandbox and is completely separate from the privileged runner
|
||||
# daemon.
|
||||
/usr/local/bin/start-sandboxed-dind.sh
|
||||
|
||||
exec /usr/local/bin/run.sh
|
||||
+5
-9
@@ -3,8 +3,6 @@ log:
|
||||
|
||||
runner:
|
||||
file: .runner
|
||||
# The runner is intentionally single-slot. This avoids jobs racing for the
|
||||
# same nested Docker daemon and its workspace volumes.
|
||||
capacity: 1
|
||||
timeout: 3h
|
||||
labels:
|
||||
@@ -12,21 +10,19 @@ runner:
|
||||
- "gvisor:docker://alpine:3.20"
|
||||
- "docker:docker://docker:28-cli"
|
||||
envs:
|
||||
# Jobs talk only to the sandboxed Docker daemon, never the runner's own
|
||||
# privileged daemon.
|
||||
# Jobs run with host networking inside the gVisor dind sandbox, where
|
||||
# dockerd listens on loopback.
|
||||
DOCKER_HOST: tcp://127.0.0.1:2375
|
||||
|
||||
cache:
|
||||
enabled: true
|
||||
|
||||
container:
|
||||
# Share the runner container's network namespace. This lets job containers
|
||||
# resolve the Compose service name "gitea" and is useful for actions/checkout.
|
||||
# The dind service is on the "ci" network.
|
||||
docker_host: tcp://dind:2375
|
||||
# Jobs share dind's sandbox network namespace.
|
||||
network: host
|
||||
privileged: false
|
||||
# "-" means: use the local Docker daemon for runner internals, but never
|
||||
# expose the runner's privileged socket to jobs.
|
||||
docker_host: "-"
|
||||
force_pull: false
|
||||
|
||||
host:
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
{
|
||||
"default-runtime": "runsc-host",
|
||||
"runtimes": {
|
||||
"runsc-host": {
|
||||
"path": "/usr/local/bin/runsc",
|
||||
"runtimeArgs": [
|
||||
"--platform=systrap",
|
||||
"--network=host"
|
||||
]
|
||||
},
|
||||
"runsc-docker": {
|
||||
"path": "/usr/local/bin/runsc",
|
||||
"runtimeArgs": [
|
||||
"--platform=systrap",
|
||||
"--net-raw",
|
||||
"--allow-packet-socket-write"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
set -eu
|
||||
|
||||
# Do not use the stock dind entrypoint here: it always adds a TCP listener.
|
||||
# Jobs use host networking so they can resolve the "gitea" Compose service and
|
||||
# reach the internet, which would also expose tcp://127.0.0.1:2375 to them.
|
||||
# Keep the daemon on its private unix socket only.
|
||||
find /run /var/run -iname 'docker*.pid' -delete 2>/dev/null || true
|
||||
exec dockerd --host=unix:///var/run/docker.sock
|
||||
@@ -1,84 +0,0 @@
|
||||
#!/bin/sh
|
||||
set -eu
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# cgroup v2 workaround for nested dockerd + runsc
|
||||
#
|
||||
# runsc creates a cgroup for each sandbox and must enable controllers on the
|
||||
# root of its cgroup namespace. On cgroup v2, a cgroup with processes in it
|
||||
# cannot have domain controllers enabled ("no internal process" rule). The
|
||||
# container runtime puts this container's processes in the namespace root, so
|
||||
# runsc gets EBUSY on cgroup.subtree_control.
|
||||
#
|
||||
# Moving PID 1 into a child cgroup makes the namespace root empty. Every s6
|
||||
# service (dockerd, containerd, act_runner) inherits that child, so jobs can
|
||||
# still receive real CPU/memory limits from Docker.
|
||||
# ---------------------------------------------------------------------------
|
||||
if [ -f /sys/fs/cgroup/cgroup.controllers ]; then
|
||||
mkdir -p /sys/fs/cgroup/init
|
||||
echo "$$" > /sys/fs/cgroup/init/cgroup.procs 2>/dev/null || true
|
||||
fi
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Block direct access to the outer Docker host from CI jobs.
|
||||
#
|
||||
# Jobs share the runner's network namespace, and the default gateway is the
|
||||
# Docker host that runs this runner. If that host exposes a Docker API (or any
|
||||
# other administrative service) on its bridge address, a workflow could use it
|
||||
# to escape the sandbox entirely. Keep DNS to the gateway working, but reject
|
||||
# other direct traffic to the gateway IP. Outbound traffic to the internet is
|
||||
# unaffected because its destination is not the gateway address.
|
||||
#
|
||||
# Set BLOCK_HOST_GATEWAY=0 to disable this (not recommended).
|
||||
# ---------------------------------------------------------------------------
|
||||
if [ "${BLOCK_HOST_GATEWAY:-1}" = "1" ]; then
|
||||
gateway=$(ip route 2>/dev/null | awk '/^default / {print $3; exit}')
|
||||
if [ -n "${gateway:-}" ]; then
|
||||
if command -v iptables >/dev/null 2>&1; then
|
||||
IPTABLES=iptables
|
||||
elif command -v iptables-legacy >/dev/null 2>&1; then
|
||||
IPTABLES=iptables-legacy
|
||||
else
|
||||
IPTABLES=""
|
||||
fi
|
||||
if [ -n "${IPTABLES}" ]; then
|
||||
if ! "$IPTABLES" -C OUTPUT -d "$gateway" -j REJECT >/dev/null 2>&1; then
|
||||
"$IPTABLES" -I OUTPUT -d "$gateway" -p udp --dport 53 -j ACCEPT 2>/dev/null || true
|
||||
"$IPTABLES" -I OUTPUT -d "$gateway" -p tcp --dport 53 -j ACCEPT 2>/dev/null || true
|
||||
"$IPTABLES" -A OUTPUT -d "$gateway" -j REJECT 2>/dev/null || true
|
||||
echo "Blocked direct CI access to Docker-host gateway ${gateway} (DNS allowed)."
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Optional zero-touch registration.
|
||||
#
|
||||
# If no explicit registration token was supplied, use an existing Gitea admin
|
||||
# account to fetch a global runner registration token from the API. This keeps
|
||||
# the token out of the Compose file and works with a normal admin-created user.
|
||||
# ---------------------------------------------------------------------------
|
||||
if [ -z "${GITEA_RUNNER_REGISTRATION_TOKEN:-}" ] \
|
||||
&& [ -n "${GITEA_ADMIN_USER:-}" ] \
|
||||
&& [ -n "${GITEA_ADMIN_PASSWORD:-}" ]; then
|
||||
echo "Waiting for Gitea to issue a runner registration token..."
|
||||
i=0
|
||||
while [ "$i" -lt 60 ]; do
|
||||
response=$(curl -fsS \
|
||||
-u "${GITEA_ADMIN_USER}:${GITEA_ADMIN_PASSWORD}" \
|
||||
-X POST \
|
||||
"${GITEA_INSTANCE_URL%/}/api/v1/admin/actions/runners/registration-token" \
|
||||
2>/dev/null || true)
|
||||
token=$(printf '%s' "$response" | sed -n 's/.*"token":"\([^"]*\)".*/\1/p')
|
||||
if [ -n "$token" ]; then
|
||||
export GITEA_RUNNER_REGISTRATION_TOKEN="$token"
|
||||
echo "Obtained a runner registration token from the Gitea API."
|
||||
break
|
||||
fi
|
||||
i=$((i + 1))
|
||||
sleep 2
|
||||
done
|
||||
fi
|
||||
|
||||
exec "$@"
|
||||
@@ -1,43 +0,0 @@
|
||||
#!/bin/sh
|
||||
set -eu
|
||||
|
||||
# This script runs *inside* a gVisor sandbox. It starts a Docker daemon whose
|
||||
# containers also live inside that same sandbox. Jobs connect to this daemon
|
||||
# through a shared unix-socket volume; they never see the privileged runner
|
||||
# daemon's socket.
|
||||
|
||||
# In gVisor, `ip route show default` returns all routes, not only the default.
|
||||
route=$(ip route show default | grep '^default ' | head -n1 || true)
|
||||
dev=""
|
||||
addr=""
|
||||
if [ -n "$route" ]; then
|
||||
dev=$(printf '%s\n' "$route" | sed -E 's/.* dev ([^ ]+).*/\1/')
|
||||
addr=$(ip -o -4 addr show dev "$dev" | awk '{print $4}' | cut -d/ -f1)
|
||||
fi
|
||||
|
||||
# Nested containers use the daemon's bridge network. Because dockerd is started
|
||||
# with iptables disabled (required by gVisor), add the SNAT rule ourselves so
|
||||
# those containers can reach the internet.
|
||||
if [ -n "$dev" ] && [ -n "$addr" ]; then
|
||||
echo 1 > /proc/sys/net/ipv4/ip_forward
|
||||
if command -v iptables-legacy >/dev/null 2>&1; then
|
||||
IPTABLES=iptables-legacy
|
||||
else
|
||||
IPTABLES=iptables
|
||||
fi
|
||||
"$IPTABLES" -t nat -A POSTROUTING -o "$dev" -j SNAT --to-source "$addr" -p tcp
|
||||
"$IPTABLES" -t nat -A POSTROUTING -o "$dev" -j SNAT --to-source "$addr" -p udp
|
||||
fi
|
||||
|
||||
rm -f /var/run/docker.sock
|
||||
|
||||
# The TCP listener is published only on the runner container's loopback. A
|
||||
# unix socket created inside a gVisor sandbox cannot usefully be shared through
|
||||
# a Docker volume, so jobs reach this daemon over loopback TCP instead.
|
||||
exec dockerd \
|
||||
--host=unix:///var/run/docker.sock \
|
||||
--host=tcp://0.0.0.0:2375 \
|
||||
--tls=false \
|
||||
--iptables=false \
|
||||
--ip6tables=false \
|
||||
"$@"
|
||||
@@ -1,33 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
# Runs inside the runner container (not inside gVisor). It asks the runner's
|
||||
# private dockerd to launch a second, gVisor-sandboxed Docker daemon and shares
|
||||
# only that daemon's socket volume with CI jobs.
|
||||
|
||||
docker volume create gvisor-dind-data >/dev/null
|
||||
|
||||
docker rm -f gvisor-dind >/dev/null 2>&1 || true
|
||||
docker run -d \
|
||||
--name gvisor-dind \
|
||||
--restart unless-stopped \
|
||||
--runtime=runsc-docker \
|
||||
--privileged \
|
||||
-p 127.0.0.1:2375:2375 \
|
||||
-v gvisor-dind-data:/var/lib/docker \
|
||||
-v /opt/gvisor-dind/start-dind.sh:/opt/gvisor-dind/start-dind.sh:ro \
|
||||
--entrypoint /opt/gvisor-dind/start-dind.sh \
|
||||
docker:28-dind >/dev/null
|
||||
|
||||
echo "Waiting for the sandboxed Docker daemon..."
|
||||
for _ in $(seq 1 120); do
|
||||
if docker exec gvisor-dind docker info >/dev/null 2>&1; then
|
||||
echo "Sandboxed Docker daemon is ready."
|
||||
exit 0
|
||||
fi
|
||||
sleep 1
|
||||
done
|
||||
|
||||
echo "Sandboxed Docker daemon did not become ready" >&2
|
||||
docker logs --tail 120 gvisor-dind >&2 || true
|
||||
exit 1
|
||||
Reference in new issue
Block a user