Skip to content

Commit 975d747

Browse files
(PTFE-2737) Add packer setup for rocky
1 parent c28657f commit 975d747

File tree

5 files changed

+569
-0
lines changed

5 files changed

+569
-0
lines changed

packer/gcp/rocky/README.md

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
# Rocky Linux Packer Template
2+
3+
This directory contains the Packer template and scripts to build optimized Rocky Linux 8 base images for GitHub Actions self-hosted runners on GCP.
4+
5+
## 📊 Performance
6+
7+
- **Standard spawn time:** 4min37s (277s)
8+
- **With Packer image:** 2min21s (141s)
9+
- **Improvement:** 49% faster ⚡
10+
- **Time saved per instance:** 136 seconds (2min16s)
11+
12+
## 📦 What's Pre-installed
13+
14+
- Docker CE + containerd.io
15+
- EPEL repository (Extra Packages for Enterprise Linux)
16+
- System updates (yum update)
17+
- Base development tools (bind-utils, yum-utils)
18+
- Docker service enabled
19+
- Optimized for GitHub Actions runner deployment
20+
21+
## 🚀 Quick Start
22+
23+
### Build Locally
24+
25+
```bash
26+
./build.sh
27+
```
28+
29+
The script will interactively prompt you for:
30+
31+
- GCP Project ID
32+
- GCP Zone
33+
- Disk size (default: 80 GB)
34+
- Image name (auto-generated with timestamp)
35+
36+
### Manual Build
37+
38+
```bash
39+
# Initialize Packer
40+
packer init template.pkr.hcl
41+
42+
# Validate
43+
packer validate \
44+
-var="project_id=YOUR_PROJECT" \
45+
-var="zone=europe-west1-b" \
46+
-var="disk_size=80" \
47+
-var="image_name=github-runner-base-rocky-8-$(date +%Y%m%d-%H%M%S)" \
48+
template.pkr.hcl
49+
50+
# Build
51+
packer build \
52+
-var="project_id=YOUR_PROJECT" \
53+
-var="zone=europe-west1-b" \
54+
-var="disk_size=80" \
55+
-var="image_name=github-runner-base-rocky-8-$(date +%Y%m%d-%H%M%S)" \
56+
template.pkr.hcl
57+
```
58+
59+
## 📋 Files
60+
61+
- **template.pkr.hcl** - Packer template definition
62+
- **build.sh** - Interactive build script
63+
- **provision.sh** - Shell provisioning script (if used)
64+
- **variables.pkrvars.hcl.example** - Example variables file
65+
- **config-example.yaml** - Runner-manager configuration example
66+
67+
## 🛠️ Customization
68+
69+
To customize the image, edit:
70+
71+
1. **template.pkr.hcl** - Modify build configuration, machine type, disk size
72+
2. **provisioners** - Add/remove provisioning steps
73+
74+
Example: Add additional packages
75+
76+
```hcl
77+
provisioner "shell" {
78+
inline = [
79+
"sudo yum install -y your-package",
80+
]
81+
}
82+
```
83+
84+
## 💡 Why EPEL?
85+
86+
EPEL (Extra Packages for Enterprise Linux) provides most GitHub Actions runner dependencies:
87+
88+
- `lttng-ust`
89+
- `openssl-libs`
90+
- `krb5-libs`
91+
- `zlib`
92+
- `libicu`
93+
94+
By pre-installing EPEL in the Packer image, the runner's `installdependencies.sh` script finds these packages already available, significantly reducing startup time.
95+
96+
## 📝 Notes
97+
98+
- Build machine: e2-standard-2 (2 vCPU, 8 GB RAM)
99+
- Build time: ~10-15 minutes
100+
- Disk size: 80 GB SSD
101+
- Image family: `github-runner-base-rocky-8`
102+
- Source image: `rocky-linux-8` from `rocky-linux-cloud`
103+
104+
## ⚠️ Important
105+
106+
Rocky Linux 8 runners show the **best performance improvement** (49% vs 35% for Ubuntu) because:
107+
108+
1. Standard Rocky VMs take much longer to provision (4min37s vs 2min09s)
109+
2. EPEL installation eliminates most dependency installation time
110+
3. Docker pre-installation is more impactful on Rocky
111+
112+
## 🔗 See Also
113+
114+
- [Main Packer README](../README.md)
115+
- [Runner Manager Documentation](../../README.md)
116+
- [Rocky Linux Documentation](https://docs.rockylinux.org/)
117+
- [Packer GCP Builder Documentation](https://developer.hashicorp.com/packer/integrations/hashicorp/googlecompute)

packer/gcp/rocky/build.sh

Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
#!/bin/bash
2+
# Interactive script to build Rocky Linux 8 GitHub Runner base image with Packer
3+
4+
set -e
5+
6+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
7+
8+
echo "=========================================="
9+
echo " Rocky Linux 8 Runner Image Builder"
10+
echo "=========================================="
11+
echo
12+
13+
# Check prerequisites
14+
echo "Checking prerequisites..."
15+
16+
# Check if packer is installed
17+
if ! command -v packer &>/dev/null; then
18+
echo "❌ Error: Packer is not installed"
19+
echo " Install from: https://www.packer.io/downloads"
20+
exit 1
21+
fi
22+
echo "✅ Packer found: $(packer version)"
23+
24+
# Check if gcloud is installed
25+
if ! command -v gcloud &>/dev/null; then
26+
echo "❌ Error: gcloud CLI is not installed"
27+
echo " Install from: https://cloud.google.com/sdk/docs/install"
28+
exit 1
29+
fi
30+
echo "✅ gcloud CLI found"
31+
32+
# Check gcloud authentication
33+
if ! gcloud auth list --filter=status:ACTIVE --format="value(account)" &>/dev/null; then
34+
echo "❌ Error: No active gcloud authentication"
35+
echo " Run: gcloud auth login"
36+
exit 1
37+
fi
38+
ACTIVE_ACCOUNT=$(gcloud auth list --filter=status:ACTIVE --format="value(account)")
39+
# trunk-ignore-all(shellcheck)
40+
echo "✅ Authenticated as: ${ACTIVE_ACCOUNT}"
41+
42+
echo
43+
echo "Prerequisites check passed!"
44+
echo
45+
46+
# Get configuration
47+
read -p "Enter GCP Project ID [scality-prod-ga-runners]: " PROJECT_ID
48+
PROJECT_ID=${PROJECT_ID:-scality-prod-ga-runners}
49+
50+
read -p "Enter GCP Zone [europe-west1-b]: " ZONE
51+
ZONE=${ZONE:-europe-west1-b}
52+
53+
# Choose Rocky Linux version
54+
echo
55+
echo "Available Rocky Linux versions:"
56+
echo " 1) Rocky Linux 8 (recommended)"
57+
echo " 2) Rocky Linux 9"
58+
echo " 3) Custom version"
59+
read -p "Select Rocky Linux version (1/2/3): " VERSION_CHOICE
60+
61+
case ${VERSION_CHOICE} in
62+
1)
63+
ROCKY_VERSION="8"
64+
echo "✅ Selected: Rocky Linux 8"
65+
;;
66+
2)
67+
ROCKY_VERSION="9"
68+
echo "✅ Selected: Rocky Linux 9"
69+
;;
70+
3)
71+
read -p "Enter Rocky Linux version (e.g., 8 or 9): " ROCKY_VERSION
72+
echo "✅ Selected: Rocky Linux ${ROCKY_VERSION}"
73+
;;
74+
*)
75+
ROCKY_VERSION="8"
76+
echo "⚠️ Invalid choice, defaulting to Rocky Linux 8"
77+
;;
78+
esac
79+
80+
read -p "Enter disk size in GB [80]: " DISK_SIZE
81+
DISK_SIZE=${DISK_SIZE:-80}
82+
83+
# Generate image name with timestamp
84+
TIMESTAMP=$(date +%Y%m%d-%H%M%S)
85+
IMAGE_NAME="github-runner-base-rocky-${ROCKY_VERSION}-${TIMESTAMP}"
86+
87+
echo
88+
echo "=========================================="
89+
echo "Build Configuration:"
90+
echo "=========================================="
91+
echo "Project ID: ${PROJECT_ID}"
92+
echo "Zone: ${ZONE}"
93+
echo "Rocky Version: ${ROCKY_VERSION}"
94+
echo "Disk Size: ${DISK_SIZE}GB"
95+
echo "Image Name: ${IMAGE_NAME}"
96+
echo "Image Family: github-runner-base-rocky-${ROCKY_VERSION}"
97+
echo "=========================================="
98+
echo
99+
100+
read -p "Proceed with build? (yes/no): " CONFIRM
101+
if [[ ${CONFIRM} != "yes" ]]; then
102+
echo "Build cancelled."
103+
exit 0
104+
fi
105+
106+
echo
107+
echo "Starting Packer build..."
108+
echo "This will take approximately 10-15 minutes."
109+
echo
110+
111+
# Initialize Packer
112+
echo "Initializing Packer plugins..."
113+
packer init template.pkr.hcl
114+
115+
# Validate template
116+
echo "Validating Packer template..."
117+
packer validate \
118+
-var="project_id=${PROJECT_ID}" \
119+
-var="zone=${ZONE}" \
120+
-var="image_name=${IMAGE_NAME}" \
121+
-var="rocky_version=${ROCKY_VERSION}" \
122+
-var="disk_size=${DISK_SIZE}" \
123+
template.pkr.hcl
124+
125+
# Build image
126+
echo
127+
echo "Building image (this will take several minutes)..."
128+
packer build \
129+
-var="project_id=${PROJECT_ID}" \
130+
-var="zone=${ZONE}" \
131+
-var="image_name=${IMAGE_NAME}" \
132+
-var="rocky_version=${ROCKY_VERSION}" \
133+
-var="disk_size=${DISK_SIZE}" \
134+
template.pkr.hcl | tee "packer-build-rocky-${TIMESTAMP}.log"
135+
136+
echo
137+
echo "=========================================="
138+
echo "✅ Build completed successfully!"
139+
echo "=========================================="
140+
echo
141+
echo "Image Details:"
142+
echo " Name: ${IMAGE_NAME}"
143+
echo " Family: github-runner-base-rocky-${ROCKY_VERSION}"
144+
echo
145+
echo "To use this image in runner-manager, update your config.yaml:"
146+
echo " runner_groups:"
147+
echo " - name: rocky-${ROCKY_VERSION}-packer-gcloud"
148+
echo " cloud_provider: gcloud"
149+
echo " image_family: github-runner-base-rocky-${ROCKY_VERSION}"
150+
echo " image_project: ${PROJECT_ID}"
151+
echo
152+
echo "Build log saved to: packer-build-rocky-${TIMESTAMP}.log"
153+
echo "Manifest saved to: manifest-rocky.json"
154+
echo

packer/gcp/rocky/provision.sh

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/bin/bash
2+
# Rocky Linux provisioning script for GitHub Actions runner base image
3+
# This script is called by Packer to configure the image
4+
5+
set -e
6+
7+
echo "=========================================="
8+
echo "Rocky Linux Provisioning Starting"
9+
echo "=========================================="
10+
11+
# Update system packages
12+
echo "Step 1/4: Updating system packages..."
13+
yum update -y
14+
15+
# Install base dependencies
16+
echo "Step 2/4: Installing base dependencies..."
17+
yum install -y bind-utils yum-utils
18+
19+
# Install Docker CE
20+
echo "Step 3/4: Installing Docker CE..."
21+
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
22+
yum install -y epel-release docker-ce docker-ce-cli containerd.io
23+
24+
# Configure Docker
25+
systemctl enable docker
26+
groupadd -f docker
27+
28+
# Clean up
29+
echo "Step 4/4: Cleaning up..."
30+
yum clean all
31+
rm -rf /var/cache/yum
32+
rm -rf /tmp/*
33+
rm -f ~/.bash_history
34+
35+
echo "=========================================="
36+
echo "Rocky Linux Provisioning Completed"
37+
echo "=========================================="

0 commit comments

Comments
 (0)