Skip to content

Commit 21b2d87

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 <hjensas@redhat.com>
1 parent c5ecc4d commit 21b2d87

File tree

1 file changed

+208
-0
lines changed

1 file changed

+208
-0
lines changed
Lines changed: 208 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,208 @@
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 (for testing forks)'
12+
required: false
13+
default: 'https://github.com/openstack-k8s-operators/ci-framework.git'
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. Checkout Repository
36+
uses: actions/checkout@v4
37+
38+
- name: 2. Clone ci-framework Repository
39+
run: |
40+
CI_REPO="${{ inputs.ci_framework_repo || 'https://github.com/openstack-k8s-operators/ci-framework.git' }}"
41+
CI_REF="${{ inputs.ci_framework_ref || 'main' }}"
42+
43+
echo "Cloning ci-framework..."
44+
echo " Repository: $CI_REPO"
45+
echo " Reference: $CI_REF"
46+
47+
# Check if this is a special ref (like refs/pull/123/head)
48+
if [[ "$CI_REF" == refs/* ]]; then
49+
echo "Detected special ref, using fetch method..."
50+
git clone "$CI_REPO" ${{ github.workspace }}/ci-framework
51+
cd ${{ github.workspace }}/ci-framework
52+
git fetch origin "$CI_REF"
53+
git checkout FETCH_HEAD
54+
else
55+
echo "Detected branch/tag, using direct clone with shallow history..."
56+
git clone --depth 1 --branch "$CI_REF" "$CI_REPO" \
57+
${{ github.workspace }}/ci-framework
58+
fi
59+
60+
echo "ci-framework cloned successfully"
61+
cd ${{ github.workspace }}/ci-framework
62+
echo "Current commit: $(git rev-parse HEAD)"
63+
echo "Current branch/ref: $(git describe --all)"
64+
65+
- name: 3. Install System Dependencies
66+
run: |
67+
echo "Installing system dependencies for diskimage-builder..."
68+
sudo apt-get update
69+
sudo apt-get install -y \
70+
python3-pip \
71+
python3-venv \
72+
qemu-utils \
73+
dosfstools \
74+
xfsprogs \
75+
kpartx \
76+
debootstrap \
77+
gdisk \
78+
git
79+
echo "System dependencies installed"
80+
81+
- name: 4. Setup Python Virtual Environment
82+
run: |
83+
echo "Creating Python virtual environment at ~/nat64_venv..."
84+
python3 -m venv ~/nat64_venv
85+
source ~/nat64_venv/bin/activate
86+
87+
pip install --upgrade pip setuptools wheel
88+
89+
echo "Installing Ansible and diskimage-builder..."
90+
pip install ansible-core
91+
pip install diskimage-builder
92+
93+
echo "Environment setup complete"
94+
95+
96+
- name: 5. Create Ansible Playbook for Building NAT64 Image
97+
run: |
98+
cat > ${{ github.workspace }}/build-nat64.yml << 'EOF'
99+
---
100+
- name: Build nat64-appliance image
101+
hosts: localhost
102+
connection: local
103+
gather_facts: true
104+
vars:
105+
cifmw_basedir: "${{ env.WORK_DIR }}"
106+
cifmw_nat64_appliance_run_dib_as_root: false
107+
cifmw_nat64_appliance_use_ci_script: false
108+
roles:
109+
- nat64_appliance
110+
EOF
111+
112+
echo "Ansible playbook created"
113+
cat ${{ github.workspace }}/build-nat64.yml
114+
115+
- name: 6. Run Ansible Playbook to Build Image
116+
run: |
117+
echo "Building NAT64 appliance image using Ansible..."
118+
echo "Using ci-framework role defaults for DIB configuration"
119+
120+
cd ${{ github.workspace }}/ci-framework
121+
122+
# Activate the venv and run the playbook
123+
source ~/nat64_venv/bin/activate
124+
125+
ANSIBLE_ROLES_PATH=${{ github.workspace }}/ci-framework/roles \
126+
ansible-playbook -v \
127+
${{ github.workspace }}/build-nat64.yml
128+
129+
echo "Image build completed successfully"
130+
131+
- name: 7. Verify Built Image
132+
run: |
133+
IMAGE_PATH="${{ env.WORK_DIR }}/nat64_appliance/nat64-appliance.qcow2"
134+
135+
if [ -f "$IMAGE_PATH" ]; then
136+
echo "Built image details:"
137+
ls -lh "$IMAGE_PATH"
138+
qemu-img info "$IMAGE_PATH"
139+
else
140+
echo "ERROR: Image file not found at $IMAGE_PATH"
141+
echo "Checking work directory contents:"
142+
ls -laR "${{ env.WORK_DIR }}"
143+
exit 1
144+
fi
145+
146+
- name: 8. Create Unique Release Tag and Rename Image
147+
id: release_tag
148+
run: |
149+
if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
150+
# Manual run: use provided tag
151+
RELEASE_TAG="${{ inputs.release_tag }}"
152+
else
153+
# Scheduled run: generate timestamp-based tag
154+
RELEASE_TAG="build-$(date +%Y%m%d-%H%M%S)"
155+
fi
156+
157+
echo "release_tag=$RELEASE_TAG" >> $GITHUB_OUTPUT
158+
echo "Release tag: $RELEASE_TAG"
159+
160+
# Rename image to include the release tag
161+
TAGGED_IMAGE="nat64-appliance-${RELEASE_TAG}.qcow2"
162+
mv ${{ env.WORK_DIR }}/nat64_appliance/nat64-appliance.qcow2 \
163+
${{ github.workspace }}/${TAGGED_IMAGE}
164+
165+
echo "tagged_image=$TAGGED_IMAGE" >> $GITHUB_OUTPUT
166+
echo "Image renamed to: $TAGGED_IMAGE"
167+
ls -lh ${{ github.workspace }}/${TAGGED_IMAGE}
168+
169+
- name: 9. Create Versioned GitHub Release
170+
uses: softprops/action-gh-release@v2
171+
with:
172+
tag_name: ${{ steps.release_tag.outputs.release_tag }}
173+
name: "NAT64 Appliance ${{ steps.release_tag.outputs.release_tag }}"
174+
body: |
175+
NAT64 Appliance image built by GitHub Actions.
176+
177+
## Build Configuration
178+
179+
- **ci-framework repository**: `${{ inputs.ci_framework_repo || 'https://github.com/openstack-k8s-operators/ci-framework.git' }}`
180+
- **ci-framework reference**: `${{ inputs.ci_framework_ref || 'main' }}`
181+
- **Build type**: ${{ github.event_name == 'schedule' && 'Scheduled (weekly)' || 'Manual dispatch' }}
182+
183+
DIB configuration uses defaults from the ci-framework nat64_appliance role.
184+
185+
## Usage
186+
187+
For usage instructions and deployment examples, see the
188+
[nat64_appliance README](https://github.com/openstack-k8s-operators/ci-framework/blob/main/roles/nat64_appliance/README.md).
189+
files: ${{ steps.release_tag.outputs.tagged_image }}
190+
191+
- name: 10. Update 'latest' Release Tag
192+
uses: softprops/action-gh-release@v2
193+
with:
194+
tag_name: latest
195+
name: "NAT64 Appliance (Latest)"
196+
prerelease: true
197+
body: |
198+
This is the latest NAT64 Appliance build. This release is automatically updated.
199+
200+
**Latest Build**: ${{ steps.release_tag.outputs.release_tag }}
201+
202+
For a specific version or to pin your CI to a known-good build, use one of the versioned releases.
203+
204+
## Usage
205+
206+
For usage instructions and deployment examples, see the
207+
[nat64_appliance README](https://github.com/openstack-k8s-operators/ci-framework/blob/main/roles/nat64_appliance/README.md).
208+
files: ${{ steps.release_tag.outputs.tagged_image }}

0 commit comments

Comments
 (0)