Skip to content

flycatch/gh-runner-platform

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Ephemeral DigitalOcean GitHub Runner

This repository provides a reusable GitHub Actions workflow that creates a temporary (ephemeral) GitHub Actions runner on DigitalOcean, runs a job on it, and automatically deletes the droplet after the job completes.

This approach is ideal for:

  • Cost-efficient CI/CD
  • Clean, isolated build environments
  • Heavy or untrusted workloads
  • Self-hosted runner scaling

πŸš€ What This Workflow Does

  1. Creates a DigitalOcean droplet
  2. Registers it as a GitHub Actions runner
  3. Runs your job on that runner
  4. Deletes the droplet (state: absent)
  5. Leaves no running infrastructure behind

πŸ”„ Workflow Lifecycle

create-runner  β†’  run-job  β†’  destroy-runner
     β”‚               β”‚              β”‚
     β”‚               β”‚              └─ Deletes droplet
     β”‚               └─ Job runs on ephemeral VM
     └─ Creates VM + GitHub runner

βœ… Key Features

  • βœ” Ephemeral (one-time) runner per job
  • βœ” No idle VMs
  • βœ” Automatic cleanup using DigitalOcean API
  • βœ” Works with any shell command
  • βœ” Safe cleanup using if: always()

πŸ“‚ Workflow File

The reusable workflow is defined at:

.github/workflows/ephemeral-do-runner.yml

πŸ”§ Inputs

Input Name Required Default Description
do_size No s-1vcpu-1gb DigitalOcean droplet size
do_region No nyc1 DigitalOcean region
job_command Yes β€” Shell command(s) to run on the runner

πŸ” Secrets

Secret Name Required Description
DIGITAL_OCEAN_ACCESS_TOKEN Yes DigitalOcean API token with droplet permissions

πŸ§ͺ Example Usage

name: Build on Ephemeral Runner

on:
  workflow_dispatch:

jobs:
  build:
    uses: ./.github/workflows/ephemeral-do-runner.yml
    with:
      job_command: |
        echo "Running on ephemeral DO runner"
        uname -a

πŸ›‘οΈ Cleanup & Leak Prevention

  • The workflow uses if: always() to ensure the destroy step runs even if the job fails
  • The droplet is deleted, not stopped
  • No manual cleanup required

⚠️ In rare cases (GitHub outage, control runner failure), cleanup could be skipped.
For maximum safety, consider adding VM self-shutdown logic inside the runner.


🧠 Best Practices

  • Use small droplet sizes for CI jobs
  • Prefer short-lived workloads
  • Avoid storing persistent data on the runner
  • Treat the runner as disposable

πŸ“Œ Notes

  • Requires a control runner (self-hosted, control-runner) to create and delete droplets
  • The ephemeral runner exists only for the duration of the job
  • Designed for reuse across multiple repositories

πŸ“„ License

MIT License

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published