Skip to content

Commit 19cea63

Browse files
committed
nat64_appliance image workflow
Add a workflow to build the nat64_appliance on a weekely schedule and create a uniq release and update the "latest" tag. Depends-On: openstack-k8s-operators/ci-framework#3550 Assisted-By: Claude Code/claude-4.5-sonnet Signed-off-by: Harald Jensås <[email protected]>
1 parent 77556a4 commit 19cea63

File tree

1 file changed

+237
-0
lines changed

1 file changed

+237
-0
lines changed
Lines changed: 237 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,237 @@
1+
name: Build NAT64 Appliance Image
2+
3+
on:
4+
# Allows you to run this workflow manually from the Actions tab
5+
workflow_dispatch:
6+
inputs:
7+
release_tag:
8+
description: 'Release tag (e.g., v1.0.0)'
9+
required: true
10+
ci_framework_repo:
11+
description: 'ci-framework repository in owner/repo format (for testing forks)'
12+
required: false
13+
default: 'openstack-k8s-operators/ci-framework'
14+
ci_framework_ref:
15+
description: 'ci-framework branch/tag/PR (e.g., main, my-branch, refs/pull/123/head)'
16+
required: false
17+
default: 'main'
18+
19+
# Run weekly on Mondays at 00:00 UTC
20+
schedule:
21+
- cron: '0 0 * * 1'
22+
23+
jobs:
24+
build-image:
25+
runs-on: ubuntu-22.04
26+
27+
# Permission needed to create a release and upload assets
28+
permissions:
29+
contents: write
30+
31+
env:
32+
WORK_DIR: ${{ github.workspace }}/ci-framework-data
33+
34+
steps:
35+
- name: 1. Install System Dependencies
36+
run: |
37+
echo "Installing system dependencies for diskimage-builder..."
38+
sudo apt-get update
39+
sudo apt-get install -y \
40+
python3-pip \
41+
python3-venv \
42+
qemu-utils \
43+
dosfstools \
44+
xfsprogs \
45+
kpartx \
46+
debootstrap \
47+
gdisk \
48+
git
49+
echo "System dependencies installed"
50+
51+
- name: 2. Clone ci-framework Repository
52+
uses: actions/checkout@v4
53+
with:
54+
repository: ${{ inputs.ci_framework_repo || 'openstack-k8s-operators/ci-framework' }}
55+
ref: ${{ inputs.ci_framework_ref || 'main' }}
56+
path: ci-framework
57+
fetch-depth: 1
58+
59+
- name: 3. Setup Python Virtual Environment
60+
run: |
61+
echo "Creating Python virtual environment at ~/nat64_venv..."
62+
python3 -m venv ~/nat64_venv
63+
source ~/nat64_venv/bin/activate
64+
65+
pip install --upgrade pip setuptools wheel
66+
67+
echo "Installing Ansible and diskimage-builder..."
68+
pip install ansible-core
69+
pip install diskimage-builder
70+
71+
echo "Environment setup complete"
72+
73+
- name: 4. Create Ansible Playbook for Building NAT64 Image
74+
run: |
75+
cat > ${{ github.workspace }}/build-nat64.yml << 'EOF'
76+
---
77+
- name: Build nat64-appliance image
78+
hosts: localhost
79+
connection: local
80+
gather_facts: true
81+
vars:
82+
cifmw_basedir: "${{ env.WORK_DIR }}"
83+
cifmw_nat64_appliance_run_dib_as_root: false
84+
cifmw_nat64_appliance_use_ci_script: false
85+
cifmw_nat64_appliance_venv_dir: "{{ ansible_env.HOME }}/nat64_venv"
86+
roles:
87+
- nat64_appliance
88+
EOF
89+
90+
echo "Ansible playbook created"
91+
cat ${{ github.workspace }}/build-nat64.yml
92+
93+
- name: 5. Run Ansible Playbook to Build Image
94+
run: |
95+
echo "Building NAT64 appliance image using Ansible..."
96+
echo "Using ci-framework role defaults for DIB configuration"
97+
98+
cd ${{ github.workspace }}/ci-framework
99+
100+
# Activate the venv and run the playbook
101+
source ~/nat64_venv/bin/activate
102+
103+
# Skip 'packages' tag since we already installed dependencies
104+
# Use our venv at ~/nat64_venv instead of letting role create one
105+
ANSIBLE_ROLES_PATH=${{ github.workspace }}/ci-framework/roles \
106+
ansible-playbook -v \
107+
--skip-tags packages \
108+
${{ github.workspace }}/build-nat64.yml
109+
110+
echo "Image build completed successfully"
111+
112+
- name: 6. Verify Built Image
113+
run: |
114+
IMAGE_PATH="${{ env.WORK_DIR }}/nat64_appliance/nat64-appliance.qcow2"
115+
116+
if [ -f "$IMAGE_PATH" ]; then
117+
echo "Built image details:"
118+
ls -lh "$IMAGE_PATH"
119+
qemu-img info "$IMAGE_PATH"
120+
else
121+
echo "ERROR: Image file not found at $IMAGE_PATH"
122+
echo "Checking work directory contents:"
123+
ls -laR "${{ env.WORK_DIR }}"
124+
exit 1
125+
fi
126+
127+
- name: 7. Create Unique Release Tag and Rename Image
128+
id: release_tag
129+
run: |
130+
if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
131+
# Manual run: use provided tag
132+
RELEASE_TAG="${{ inputs.release_tag }}"
133+
else
134+
# Scheduled run: generate timestamp-based tag
135+
RELEASE_TAG="build-$(date +%Y%m%d-%H%M%S)"
136+
fi
137+
138+
echo "release_tag=$RELEASE_TAG" >> $GITHUB_OUTPUT
139+
echo "Release tag: $RELEASE_TAG"
140+
141+
# Rename image to include the release tag
142+
TAGGED_IMAGE="nat64-appliance-${RELEASE_TAG}.qcow2"
143+
mv ${{ env.WORK_DIR }}/nat64_appliance/nat64-appliance.qcow2 \
144+
${{ github.workspace }}/${TAGGED_IMAGE}
145+
146+
echo "tagged_image=$TAGGED_IMAGE" >> $GITHUB_OUTPUT
147+
echo "Image renamed to: $TAGGED_IMAGE"
148+
ls -lh ${{ github.workspace }}/${TAGGED_IMAGE}
149+
150+
- name: 8. Create Versioned GitHub Release
151+
uses: softprops/action-gh-release@v2
152+
with:
153+
tag_name: ${{ steps.release_tag.outputs.release_tag }}
154+
name: "NAT64 Appliance ${{ steps.release_tag.outputs.release_tag }}"
155+
body: |
156+
NAT64 Appliance image built by GitHub Actions.
157+
158+
## Build Configuration
159+
160+
- **ci-framework repository**: `${{ inputs.ci_framework_repo || 'openstack-k8s-operators/ci-framework' }}`
161+
- **ci-framework reference**: `${{ inputs.ci_framework_ref || 'main' }}`
162+
- **Build type**: ${{ github.event_name == 'schedule' && 'Scheduled (weekly)' || 'Manual dispatch' }}
163+
164+
DIB configuration uses defaults from the ci-framework nat64_appliance role.
165+
166+
## Usage
167+
168+
For usage instructions and deployment examples, see the
169+
[nat64_appliance README](https://github.com/openstack-k8s-operators/ci-framework/blob/main/roles/nat64_appliance/README.md).
170+
files: ${{ steps.release_tag.outputs.tagged_image }}
171+
172+
- name: 9. Update 'latest' Release Tag
173+
uses: softprops/action-gh-release@v2
174+
with:
175+
tag_name: latest
176+
name: "NAT64 Appliance (Latest)"
177+
prerelease: true
178+
body: |
179+
This is the latest NAT64 Appliance build. This release is automatically updated.
180+
181+
**Latest Build**: ${{ steps.release_tag.outputs.release_tag }}
182+
183+
## Download
184+
185+
Use the static URL for the latest build:
186+
```bash
187+
curl -L -O https://github.com/openstack-k8s-operators/openstack-k8s-operators-ci/releases/download/latest/nat64-appliance-latest.qcow2
188+
```
189+
190+
Or download a specific version from the [releases page](https://github.com/openstack-k8s-operators/openstack-k8s-operators-ci/releases)
191+
to pin your CI to a known-good build.
192+
193+
## Usage
194+
195+
For usage instructions and deployment examples, see the
196+
[nat64_appliance README](https://github.com/openstack-k8s-operators/ci-framework/blob/main/roles/nat64_appliance/README.md).
197+
files: ${{ steps.release_tag.outputs.tagged_image }}
198+
199+
- name: 10. Upload Image with Static Filename to Latest Release
200+
run: |
201+
echo "Creating static filename copy for easy downloading..."
202+
203+
# Copy the image with a static name
204+
cp ${{ github.workspace }}/${{ steps.release_tag.outputs.tagged_image }} \
205+
${{ github.workspace }}/nat64-appliance-latest.qcow2
206+
207+
echo "Uploading to latest release with static filename..."
208+
# Upload to latest release, replacing any existing file with the same name
209+
gh release upload latest nat64-appliance-latest.qcow2 --clobber --repo ${{ github.repository }}
210+
211+
echo "Static URL available at:"
212+
echo "https://github.com/${{ github.repository }}/releases/download/latest/nat64-appliance-latest.qcow2"
213+
env:
214+
GH_TOKEN: ${{ github.token }}
215+
216+
- name: 11. Cleanup Old Releases (Keep Last 4)
217+
if: github.event_name == 'schedule'
218+
run: |
219+
echo "Cleaning up old scheduled builds, keeping last 4..."
220+
221+
# Get all releases with 'build-' prefix, sort by creation date (newest first)
222+
# Skip the first 4 (keep them), delete the rest
223+
OLD_RELEASES=$(gh release list --limit 100 --json tagName,createdAt --repo ${{ github.repository }} \
224+
| jq -r '.[] | select(.tagName | startswith("build-")) | .tagName' \
225+
| sort -r \
226+
| tail -n +5)
227+
228+
if [ -n "$OLD_RELEASES" ]; then
229+
echo "Deleting old releases:"
230+
echo "$OLD_RELEASES"
231+
echo "$OLD_RELEASES" | xargs -I {} gh release delete {} --yes --cleanup-tag --repo ${{ github.repository }}
232+
echo "Cleanup complete"
233+
else
234+
echo "No old releases to delete (fewer than 5 total)"
235+
fi
236+
env:
237+
GH_TOKEN: ${{ github.token }}

0 commit comments

Comments
 (0)