Skip to content

Commit 2a5888d

Browse files
(PTFE-2736) Add packer setup for ubuntu
1 parent c28657f commit 2a5888d

File tree

6 files changed

+808
-0
lines changed

6 files changed

+808
-0
lines changed

packer/README.md

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
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

packer/gcp/ubuntu/README.md

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
# Ubuntu LTS Packer Template
2+
3+
This directory contains the Packer template and scripts to build optimized Ubuntu 22.04 LTS base images for GitHub Actions self-hosted runners on GCP.
4+
5+
## 📊 Performance
6+
7+
- **Standard spawn time:** 2min09s (129s)
8+
- **With Packer image:** 1min24s (84s)
9+
- **Improvement:** 35% faster ⚡
10+
- **Time saved per instance:** 45 seconds
11+
12+
## 📦 What's Pre-installed
13+
14+
- Docker CE + docker-compose
15+
- containerd.io
16+
- System updates (apt update + upgrade)
17+
- Base development tools
18+
- Optimized for GitHub Actions runner deployment
19+
20+
## 🚀 Quick Start
21+
22+
### Build Locally
23+
24+
```bash
25+
./build.sh
26+
```
27+
28+
The script will interactively prompt you for:
29+
30+
- GCP Project ID
31+
- GCP Zone
32+
- Image name (auto-generated with timestamp)
33+
34+
### Manual Build
35+
36+
```bash
37+
# Initialize Packer
38+
packer init template.pkr.hcl
39+
40+
# Validate
41+
packer validate \
42+
-var="project_id=YOUR_PROJECT" \
43+
-var="zone=europe-west1-b" \
44+
-var="image_name=github-runner-base-ubuntu-2204-$(date +%Y%m%d-%H%M%S)" \
45+
template.pkr.hcl
46+
47+
# Build
48+
packer build \
49+
-var="project_id=YOUR_PROJECT" \
50+
-var="zone=europe-west1-b" \
51+
-var="image_name=github-runner-base-ubuntu-2204-$(date +%Y%m%d-%H%M%S)" \
52+
template.pkr.hcl
53+
```
54+
55+
## 📋 Files
56+
57+
- **template.pkr.hcl** - Packer template definition
58+
- **build.sh** - Interactive build script
59+
- **provision.sh** - Shell provisioning script (if used)
60+
- **variables.pkrvars.hcl.example** - Example variables file
61+
- **config-example.yaml** - Runner-manager configuration example
62+
63+
## 🛠️ Customization
64+
65+
To customize the image, edit:
66+
67+
1. **template.pkr.hcl** - Modify build configuration, machine type, disk size
68+
2. **provisioners** - Add/remove provisioning steps
69+
70+
Example: Add additional packages
71+
72+
```hcl
73+
provisioner "shell" {
74+
inline = [
75+
"sudo apt-get install -y your-package",
76+
]
77+
}
78+
```
79+
80+
## 📝 Notes
81+
82+
- Build machine: n2-standard-4 (4 vCPU, 16 GB RAM)
83+
- Build time: ~8-10 minutes
84+
- Disk size: 80 GB SSD
85+
- Image family: `github-runner-base-ubuntu-2204`
86+
- Source image: `ubuntu-2204-lts` from `ubuntu-os-cloud`
87+
88+
## 🔗 See Also
89+
90+
- [Main Packer README](../README.md)
91+
- [Runner Manager Documentation](../../README.md)
92+
- [Packer GCP Builder Documentation](https://developer.hashicorp.com/packer/integrations/hashicorp/googlecompute)

0 commit comments

Comments
 (0)