Skip to content

Commit 3d7cc9a

Browse files
committed
feat: Add interactive packer build script
This commit implements comprehensive SSH/SCP compatibility fixes and creates an interactive build script for Jenkins Job Builder (JJB) validated Packer image combinations. Make life easy for maintainers to run manual builds at times when new base images need to be uploaded and built manually allowing simultanous builds. - templates/builder.pkr.hcl - templates/builder-aws.pkr.hcl - templates/docker.pkr.hcl - templates/docker-aws.pkr.hcl - templates/devstack.pkr.hcl - templates/devstack-pre-pip-yoga.pkr.hcl - templates/windows-builder.pkr.hcl 1. **Added local_build variable**: Controls SSH compatibility mode - Type: bool, default: false - Description: "Set to true for local builds to enable SSH/scp compatibility" 2. **Added conditional SSH arguments**: Using HCL ternary expressions - For local builds (local_build=true): * `--scp-extra-args "'-O'"` - Fixes SCP upload failures * Enhanced SSH algorithms including PubkeyAcceptedAlgorithms=+ssh-rsa - For CI builds (local_build=false): Standard SSH arguments 3. **Updated ansible provisioner**: Replaced hardcoded extra_arguments with dynamic `local.ssh_extra_args` 4. **Preserved existing functionality**: DevStack yoga templates maintain existing extra-vars while adding SSH compatibility - **JJB Integration**: Reads supported combinations from releng-packer-jobs.yaml - **EOL Platform Exclusion**: Automatically excludes ubuntu-18.04 EOL - **21 Validated Combinations**: Only builds JJB-approved platform+template pairs - **Comprehensive Logging**: Individual timestamped log files per build in /tmp/ - **Execution Modes**: Interactive, dry-run, and background build options - **Auto SSH Compatibility**: Automatically sets local_build=true for all builds - Smart file discovery and validation - User-friendly numbered menus - Real-time build progress tracking - Proper relative path handling - Background process management - Build status reporting with exit codes - Complete usage instructions for JJB-based builds - Prerequisites and environment setup guide - All 21 JJB combination listings by image type - Example usage scenarios - Troubleshooting section with common issues - Comprehensive logging and monitoring documentation This addresses critical SSH/SCP compatibility issues that were causing Packer builds to fail with errors like: scp: dest open "'~user/.ansible/tmp/...": No such file or directory The conditional approach allows: - **Local Development**: Enhanced SSH compatibility when local_build=true - **CI/CD Compatibility**: Preserved existing behavior when local_build=false - **Maintainability**: Centralized SSH logic in reusable locals blocks Validated against Jenkins Job Builder configuration ensuring only approved platform/template combinations are built, improving build reliability and reducing maintenance overhead. Change-Id: I0ff854c63c96d97e98f8b5f436195c7af91fea36 Signed-off-by: Anil Belur <abelur@linuxfoundation.org>
1 parent 441ae63 commit 3d7cc9a

11 files changed

+801
-26
lines changed

README.md

Lines changed: 296 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,296 @@
1+
# Packer Image Builder Script
2+
3+
This repository contains an interactive script for building packer images using
4+
Jenkins Job Builder (JJB) validated combinations, excluding End-of-Life platforms.
5+
6+
## Prerequisites
7+
8+
### 1. Environment Setup
9+
10+
Before running any packer builds, you must configure your environment:
11+
Ensure the latest version of the ci-management repository is cloned on
12+
a host with the cloud tenant access. If you are running this locally
13+
ensure you have a loopback ssh tunnel to the bastion host (IP address of
14+
the Jenkins sandbox) on a separate terminal.
15+
16+
```bash
17+
# Set Python version using pyenv
18+
pyenv global 3.10.13
19+
20+
# Activate ansible virtual environment
21+
source ~/virtualenv/ansible/bin/activate
22+
23+
# Verify setup
24+
python --version # Should show Python 3.10.13
25+
which python # Should show pyenv path
26+
```
27+
28+
### 2. Required Files
29+
30+
Ensure these files exist in the parent directory:
31+
32+
- `cloud-env.json` - OpenStack cloud configuration
33+
- `OS_CLOUD` environment variable set to `odlci`
34+
- `.config/openstack/clouds.yaml` - OpenStack credentials
35+
36+
### 3. Directory Structure
37+
38+
The script expects this structure:
39+
40+
```
41+
ci-management/ # Repository root
42+
├── jjb/
43+
│ └── releng-packer-jobs.yaml # JJB configuration (validates combinations)
44+
├── packer/
45+
│ ├── common-packer/ # This directory
46+
│ │ ├── build-packer-images.sh # Interactive JJB script
47+
│ │ ├── vars/ # Variable files
48+
│ │ │ ├── ubuntu-22.04.pkrvars.hcl
49+
│ │ │ ├── ubuntu-24.04.pkrvars.hcl
50+
│ │ │ └── ...
51+
│ │ └── templates/ # Common templates
52+
│ │ ├── builder.pkr.hcl
53+
│ │ ├── docker.pkr.hcl
54+
│ │ └── ...
55+
│ └── templates/ # Additional templates
56+
│ ├── devstack.pkr.hcl
57+
│ ├── robot.pkr.hcl
58+
│ └── ...
59+
└── cloud-env.json # OpenStack cloud configuration
60+
```
61+
62+
## Usage
63+
64+
### Interactive JJB Script (Recommended)
65+
66+
1. **Navigate to the repository root:**
67+
68+
```bash
69+
cd builder
70+
```
71+
72+
2. **Run the JJB-based interactive script:**
73+
74+
```bash
75+
./packer/common-packer/build-packer-images.sh
76+
```
77+
78+
3. **Follow the prompts:**
79+
- **Option 1**: Build all JJB combinations (21 validated builds, ubuntu-18.04 EOL excluded)
80+
- **Option 2**: Select specific combinations by number
81+
- **Option 3**: Exit
82+
83+
4. **Choose execution mode:**
84+
- **Mode 1**: Execute builds immediately (sequential) with live output + log files
85+
- **Mode 2**: Generate build commands only (dry-run)
86+
- **Mode 3**: Execute builds in background (parallel) with individual log files
87+
88+
### JJB Validated Combinations (21 total)
89+
90+
The script only builds combinations validated in `jjb/releng-packer-jobs.yaml`:
91+
92+
**Builder images (6 platforms):**
93+
94+
- centos-7, centos-cs-8, centos-cs-9, ubuntu-20.04, ubuntu-22.04, ubuntu-24.04
95+
96+
**Docker images (3 platforms, ubuntu-18.04 EOL excluded):**
97+
98+
- centos-7, ubuntu-20.04, ubuntu-22.04
99+
100+
**DevStack variants (centos-7 only):**
101+
102+
- devstack, devstack-pre-pip-queens, devstack-pre-pip-rocky, devstack-pre-pip-stein
103+
104+
**Specialized images:**
105+
106+
- helm (centos-7)
107+
- mininet-ovs-217 (ubuntu-22.04, ubuntu-24.04)
108+
- robot (centos-7, centos-cs-8, centos-cs-9, ubuntu-22.04, ubuntu-24.04)
109+
110+
### Direct Command Line
111+
112+
For individual builds, use this format:
113+
114+
```bash
115+
# Set environment first
116+
pyenv global 3.10.13
117+
source ~/virtualenv/ansible-new/bin/activate
118+
119+
# Run packer build
120+
OS_CLOUD=odlci packer.io build \
121+
-only=openstack.<template-name> \
122+
-var-file=cloud-env.json \
123+
-var-file=common-packer/vars/<var-file>.pkrvars.hcl \
124+
templates/<template-file>.pkr.hcl
125+
```
126+
127+
#### Build Target Examples:
128+
129+
- Builder: `-only=openstack.builder`
130+
- Docker: `-only=openstack.docker`
131+
- Devstack: `-only=openstack.devstack`
132+
- Robot: `-only=openstack.robot`
133+
- Helm: `-only=openstack.helm`
134+
135+
## Available Configurations
136+
137+
### Variable Files (OS/Architecture)
138+
139+
- `centos-7.pkrvars.hcl`, `centos-7-arm64.pkrvars.hcl`
140+
- `centos-8.pkrvars.hcl`
141+
- `centos-cs-8.pkrvars.hcl`, `centos-cs-9.pkrvars.hcl`
142+
- `ubuntu-16.04.pkrvars.hcl`, `ubuntu-16.04-arm64.pkrvars.hcl`
143+
- `ubuntu-18.04.pkrvars.hcl`, `ubuntu-18.04-arm64.pkrvars.hcl`
144+
- `ubuntu-20.04.pkrvars.hcl`, `ubuntu-20.04-arm64.pkrvars.hcl`
145+
- `ubuntu-22.04.pkrvars.hcl`
146+
- `ubuntu-24.04.pkrvars.hcl`, `ubuntu-24.04-arm64.pkrvars.hcl`
147+
- `windows-server-2016.pkrvars.hcl`
148+
149+
### Template Files (Image Types)
150+
151+
- `builder.pkr.hcl` - Basic builder image
152+
- `docker.pkr.hcl` - Docker-enabled image
153+
- `devstack.pkr.hcl` - OpenStack DevStack image
154+
- `helm.pkr.hcl` - Kubernetes Helm image
155+
- `robot.pkr.hcl` - Robot Framework testing image
156+
- `mininet-ovs-217.pkr.hcl` - Mininet networking image
157+
- Various devstack pre-pip templates
158+
159+
## Example Usage Scenarios
160+
161+
### Scenario 1: Test Single Configuration
162+
163+
```bash
164+
cd /home/abelur/git/builder
165+
./packer/common-packer/build-packer-images.sh
166+
# Choose: 2 (select specific combinations)
167+
# Enter: 15 (ubuntu-22.04 + builder)
168+
# Choose: 2 (dry-run mode)
169+
```
170+
171+
### Scenario 2: Build All Ubuntu Builder Images
172+
173+
```bash
174+
cd /home/abelur/git/builder
175+
./packer/common-packer/build-packer-images.sh
176+
# Choose: 2 (select specific combinations)
177+
# Enter: 13 15 7 (ubuntu-20.04, ubuntu-22.04, ubuntu-24.04 + builder)
178+
# Choose: 3 (execute in background)
179+
```
180+
181+
### Scenario 3: Build All JJB Combinations
182+
183+
```bash
184+
cd /home/abelur/git/builder
185+
./packer/common-packer/build-packer-images.sh
186+
# Choose: 1 (build all 21 JJB combinations)
187+
# Choose: 3 (execute in background)
188+
```
189+
190+
## Build Process
191+
192+
Each packer build follows this process:
193+
194+
1. **Environment Setup**: Creates OpenStack instance with specified OS
195+
2. **Python Installation**: Installs Python and configures package mirrors
196+
3. **Ansible Setup**: Creates virtual environment and installs Ansible roles
197+
4. **Provisioning**: Runs Ansible playbooks to configure the image
198+
5. **Image Creation**: Snapshots the configured instance as a reusable image
199+
200+
## Troubleshooting
201+
202+
### Common Issues
203+
204+
1. **Python 3.10 not found**
205+
206+
```bash
207+
# Solution: Set pyenv before running builds
208+
pyenv global 3.10.13
209+
```
210+
211+
2. **Ansible virtual environment missing**
212+
213+
```bash
214+
# Solution: Activate ansible venv
215+
source ~/virtualenv/ansible-new/bin/activate
216+
```
217+
218+
3. **netselect download failures**
219+
- The script automatically handles version compatibility
220+
- Ubuntu ≤ 20.04 uses older netselect version
221+
- Ubuntu > 20.04 uses newer version
222+
223+
4. **Wrong build target**
224+
- The script automatically determines correct targets
225+
- Manual commands: use `-only=openstack.<template-basename>`
226+
227+
5. **Cloud configuration issues**
228+
```bash
229+
# Verify cloud-env.json exists and OS_CLOUD is set
230+
ls -la ../cloud-env.json
231+
echo $OS_CLOUD # Should show: odlci
232+
```
233+
234+
### Network Issues
235+
236+
If ansible-galaxy role downloads fail:
237+
238+
- Check network connectivity
239+
- Retry the build - temporary network issues often resolve
240+
- Use `--ignore-errors` flag in ansible-galaxy calls if needed
241+
242+
## Performance Tips
243+
244+
- **Parallel builds**: Use background execution mode for multiple builds
245+
- **Selective building**: Use dry-run mode first to verify commands
246+
- **Resource limits**: Monitor OpenStack quota when running many parallel builds
247+
- **Build time**: Each build takes 15-45 minutes depending on complexity
248+
249+
## Build Output and Logging
250+
251+
### Log Files
252+
253+
All builds are automatically logged to `/tmp/` with detailed filenames:
254+
255+
- **Format**: `/tmp/packer-build-{platform}-{template}-{timestamp}.log`
256+
- **Examples**:
257+
- `/tmp/packer-build-ubuntu-22.04-builder-20250912-143022.log`
258+
- `/tmp/packer-build-centos-7-docker-20250912-143055.log`
259+
- **Contents**: Complete packer output, Ansible logs, error details
260+
261+
### Build Monitoring
262+
263+
- **Sequential mode (1)**: Live output + log files using `tee`
264+
- **Background mode (3)**: Monitor with `tail -f /tmp/packer-build-*.log`
265+
- **Status check**: Use `jobs` and `wait` commands
266+
267+
Successful builds create:
268+
269+
- **OpenStack Images**: Registered in the OpenStack image service
270+
- **Build Logs**: Complete execution logs in `/tmp/`
271+
- **Ansible Details**: Provisioning steps and configuration changes
272+
273+
Failed builds:
274+
275+
- **Error Logs**: Detailed failure information in log files
276+
- **Cleanup**: Automatically clean up temporary resources
277+
- **Retry**: Can be safely retried after fixing issues
278+
279+
## Script Features
280+
281+
- **Auto-discovery**: Finds all variable and template files automatically
282+
- **Smart filtering**: Excludes configuration files (cloud-env.\*)
283+
- **Interactive selection**: User-friendly numbered menus
284+
- **Flexible execution**: Immediate, dry-run, or background modes
285+
- **Path handling**: Works with any repository name/structure
286+
- **Error handling**: Validates inputs and file existence
287+
- **Progress tracking**: Clear indication of build progress
288+
289+
## Support
290+
291+
For issues:
292+
293+
1. Check the troubleshooting section above
294+
2. Verify all prerequisites are met
295+
3. Use dry-run mode to validate commands
296+
4. Review packer and ansible logs for specific errors

0 commit comments

Comments
 (0)