@@ -315,3 +315,56 @@ docker run -d --restart always --name github-runner \
315315 -v /tmp/github-runner-your-repo:/tmp/github-runner-your-repo \
316316 myoung34/github-runner:latest
317317` ` `
318+
319+ # # Ephemeral mode
320+
321+ GitHub's hosted runners are completely ephemeral. You can remove all its data without breaking all future jobs.
322+
323+ To achieve the same resilience in a self-hosted runner :
324+ 1. override the command for your runner with `/ephemeral-runner.sh` (which will terminate after one job executes)
325+ 2. don't mount a local folder into `RUNNER_WORKDIR` (to ensure no filesystem persistence)
326+ 3. run the container with `--rm` (to delete it after termination)
327+ 4. wrap the container execution in a system service that restarts (to start a fresh container after each job)
328+
329+ Here's an example service definition for systemd :
330+
331+ ` ` `
332+ # Install with:
333+ # sudo install -m 644 ephemeral-github-actions-runner.service /etc/systemd/system/
334+ # sudo systemctl daemon-reload
335+ # sudo systemctl enable ephemeral-github-actions-runner
336+ # Run with:
337+ # sudo systemctl start ephemeral-github-actions-runner
338+ # Stop with:
339+ # sudo systemctl stop ephemeral-github-actions-runner
340+ # See live logs with:
341+ # journalctl -f -u ephemeral-github-actions-runner.service --no-hostname --no-tail
342+
343+ [Unit]
344+ Description=Ephemeral GitHub Actions Runner Container
345+ After=docker.service
346+ Requires=docker.service
347+
348+ [Service]
349+ TimeoutStartSec=0
350+ Restart=always
351+ ExecStartPre=-/usr/bin/docker stop %n
352+ ExecStartPre=-/usr/bin/docker rm %n
353+ ExecStartPre=-/usr/bin/docker pull myoung34/github-runner:latest
354+ ExecStart=/usr/bin/docker run --rm --env-file /etc/ephemeral-github-actions-runner.env --name %n myoung34/ephemeral-github-actions-runner:latest /ephemeral-runner.sh
355+
356+ [Install]
357+ WantedBy=multi-user.target
358+ ` ` `
359+
360+ And an example of the corresponding env file that the service reads from :
361+
362+ ` ` `
363+ # Install with:
364+ # sudo install -m 600 ephemeral-github-actions-runner.env /etc/
365+ REPO_URL=https://github.com/your-org/your-repo
366+ RUNNER_NAME=your-runner-name-here
367+ ACCESS_TOKEN=foo-access-token
368+ RUNNER_WORKDIR=/tmp/runner/work
369+ LABELS=any-custom-labels-go-here
370+ ` ` `
0 commit comments