|
| 1 | +# Packer Templates for GitHub Actions Runner Images |
| 2 | + |
| 3 | +This directory contains Packer templates to build optimized base images for GitHub Actions self-hosted runners on GCP. |
| 4 | + |
| 5 | +## 📁 Structure |
| 6 | + |
| 7 | +```text |
| 8 | +packer/gcp/ |
| 9 | +├── ubuntu/ # Ubuntu LTS templates and scripts |
| 10 | +│ ├── template.pkr.hcl # Packer template |
| 11 | +│ ├── build.sh # Interactive build script |
| 12 | +│ ├── provision.sh # Provisioning script |
| 13 | +│ ├── variables.pkrvars.hcl.example # Variables example |
| 14 | +│ └── config-example.yaml # Runner-manager config example |
| 15 | +│ |
| 16 | +├── rocky/ # Rocky Linux templates and scripts |
| 17 | +│ ├── template.pkr.hcl # Packer template |
| 18 | +│ ├── build.sh # Interactive build script |
| 19 | +│ ├── provision.sh # Provisioning script |
| 20 | +│ ├── variables.pkrvars.hcl.example # Variables example |
| 21 | +│ └── config-example.yaml # Runner-manager config example |
| 22 | +│ |
| 23 | +└── README.md # This file |
| 24 | +``` |
| 25 | + |
| 26 | +## 🚀 Quick Start |
| 27 | + |
| 28 | +### Ubuntu |
| 29 | + |
| 30 | +```bash |
| 31 | +cd packer/gcp/ubuntu |
| 32 | +./build.sh |
| 33 | +``` |
| 34 | + |
| 35 | +### Rocky Linux |
| 36 | + |
| 37 | +```bash |
| 38 | +cd packer/gcp/rocky |
| 39 | +./build.sh |
| 40 | +``` |
| 41 | + |
| 42 | +## 📊 Performance Improvements |
| 43 | + |
| 44 | +### Ubuntu 22.04 |
| 45 | + |
| 46 | +- **Standard spawn time:** 2min09s (129s) |
| 47 | +- **With Packer image:** 1min24s (84s) |
| 48 | +- **Improvement:** 35% faster ⚡ |
| 49 | + |
| 50 | +### Rocky Linux 8 |
| 51 | + |
| 52 | +- **Standard spawn time:** 4min37s (277s) |
| 53 | +- **With Packer image:** 2min21s (141s) |
| 54 | +- **Improvement:** 49% faster ⚡ |
| 55 | + |
| 56 | +### Combined Impact (222 instances/day) |
| 57 | + |
| 58 | +- **Time saved per day:** 3h45min |
| 59 | +- **Cost saved per month:** ~6,204€ (at 75€/h developer cost) |
| 60 | +- **ROI:** 8,163× (Packer costs only 0.76€/month) |
| 61 | + |
| 62 | +## 📦 What's Pre-installed |
| 63 | + |
| 64 | +### Ubuntu Image |
| 65 | + |
| 66 | +- Docker CE + docker-compose |
| 67 | +- System updates and base packages |
| 68 | +- Optimized for fast GitHub Actions runner deployment |
| 69 | + |
| 70 | +### Rocky Image |
| 71 | + |
| 72 | +- Docker CE + containerd |
| 73 | +- EPEL repository (provides most runner dependencies) |
| 74 | +- System updates and base packages |
| 75 | +- Optimized for fast GitHub Actions runner deployment |
| 76 | + |
| 77 | +## 🔧 Configuration |
| 78 | + |
| 79 | +Each OS directory contains: |
| 80 | + |
| 81 | +1. **template.pkr.hcl** - The Packer template |
| 82 | +2. **build.sh** - Interactive build script with prompts |
| 83 | +3. **provision.sh** - Shell provisioning script |
| 84 | +4. **variables.pkrvars.hcl.example** - Example variables file |
| 85 | +5. **config-example.yaml** - Runner-manager configuration example |
| 86 | + |
| 87 | +## 📖 Usage |
| 88 | + |
| 89 | +### Build an Image |
| 90 | + |
| 91 | +```bash |
| 92 | +cd packer/gcp/<ubuntu|rocky> |
| 93 | +./build.sh |
| 94 | +``` |
| 95 | + |
| 96 | +The script will prompt you for: |
| 97 | + |
| 98 | +- GCP Project ID |
| 99 | +- Image name (auto-generated with timestamp) |
| 100 | +- Confirmation before building |
| 101 | + |
| 102 | +## 🛠️ Manual Build |
| 103 | + |
| 104 | +```bash |
| 105 | +cd packer/gcp/<ubuntu|rocky> |
| 106 | + |
| 107 | +# Validate template |
| 108 | +packer validate \ |
| 109 | + -var="project_id=YOUR_PROJECT" \ |
| 110 | + -var="image_name=test-image" \ |
| 111 | + template.pkr.hcl |
| 112 | + |
| 113 | +# Build |
| 114 | +packer build \ |
| 115 | + -var="project_id=YOUR_PROJECT" \ |
| 116 | + -var="image_name=github-runner-base-ubuntu-2204-$(date +%Y%m%d-%H%M%S)" \ |
| 117 | + template.pkr.hcl |
| 118 | +``` |
| 119 | + |
| 120 | +## 📝 Notes |
| 121 | + |
| 122 | +- Images are built on GCP Compute Engine (e2-standard-2 for Ubuntu, e2-standard-2 for Rocky) |
| 123 | +- Build time: ~8-15 minutes per image |
| 124 | +- Images include security updates and are optimized for fast runner startup |
| 125 | +- The `image_family` feature allows automatic use of the latest image version |
| 126 | + |
| 127 | +## 🔗 Related Documentation |
| 128 | + |
| 129 | +- [Packer Documentation](https://www.packer.io/docs) |
| 130 | +- [GCP Compute Engine Images](https://cloud.google.com/compute/docs/images) |
| 131 | +- [Runner Manager Configuration](../README.md) |
| 132 | + |
| 133 | +## 💡 Tips |
| 134 | + |
| 135 | +1. **Use image families** instead of specific image names for automatic updates |
| 136 | +2. **Tag images** with meaningful names including dates |
| 137 | +3. **Test new images** on a small runner group before full deployment |
| 138 | +4. **Monitor startup times** in GCP Cloud Logging to validate improvements |
| 139 | +5. **Rebuild regularly** (weekly recommended) to include security updates |
0 commit comments