Skip to content

Commit dbc3b54

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. Signed-off-by: Harald Jensås <hjensas@redhat.com>
1 parent c5ecc4d commit dbc3b54

File tree

1 file changed

+195
-0
lines changed

1 file changed

+195
-0
lines changed
Lines changed: 195 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,195 @@
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. Setup ci-framework Molecule Environment
66+
run: |
67+
echo "Setting up ci-framework environment with make setup_molecule..."
68+
echo "This will create a Python venv at ~/test-python and install all dependencies"
69+
70+
cd ${{ github.workspace }}/ci-framework
71+
72+
# The setup_molecule target installs everything we need:
73+
# - Creates venv at ~/test-python
74+
# - Installs system dependencies via bindep
75+
# - Installs ansible-core, diskimage-builder, and all collections
76+
# - Builds and installs cifmw.general collection properly
77+
make setup_molecule
78+
79+
echo "Environment setup complete"
80+
echo "Installed Ansible version:"
81+
~/test-python/bin/ansible --version
82+
83+
- name: 4. Create Ansible Playbook for Building NAT64 Image
84+
run: |
85+
cat > ${{ github.workspace }}/build-nat64.yml << 'EOF'
86+
---
87+
- name: Build nat64-appliance image
88+
hosts: localhost
89+
connection: local
90+
gather_facts: true
91+
vars:
92+
cifmw_basedir: "${{ env.WORK_DIR }}"
93+
cifmw_nat64_appliance_run_dib_as_root: false
94+
roles:
95+
- nat64_appliance
96+
EOF
97+
98+
echo "Ansible playbook created"
99+
cat ${{ github.workspace }}/build-nat64.yml
100+
101+
- name: 5. Run Ansible Playbook to Build Image
102+
run: |
103+
echo "Building NAT64 appliance image using Ansible..."
104+
echo "Using ci-framework role defaults for DIB configuration"
105+
106+
cd ${{ github.workspace }}/ci-framework
107+
108+
# Activate the venv created by setup_molecule and run the playbook
109+
# The venv has ansible-core, cifmw.general collection, and all dependencies
110+
source ~/test-python/bin/activate
111+
112+
ANSIBLE_ROLES_PATH=${{ github.workspace }}/ci-framework/roles \
113+
ansible-playbook -v \
114+
${{ github.workspace }}/build-nat64.yml
115+
116+
echo "Image build completed successfully"
117+
118+
- name: 6. Verify Built Image
119+
run: |
120+
IMAGE_PATH="${{ env.WORK_DIR }}/nat64_appliance/nat64-appliance.qcow2"
121+
122+
if [ -f "$IMAGE_PATH" ]; then
123+
echo "Built image details:"
124+
ls -lh "$IMAGE_PATH"
125+
qemu-img info "$IMAGE_PATH"
126+
else
127+
echo "ERROR: Image file not found at $IMAGE_PATH"
128+
echo "Checking work directory contents:"
129+
ls -laR "${{ env.WORK_DIR }}"
130+
exit 1
131+
fi
132+
133+
- name: 7. Create Unique Release Tag and Rename Image
134+
id: release_tag
135+
run: |
136+
if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
137+
# Manual run: use provided tag
138+
RELEASE_TAG="${{ inputs.release_tag }}"
139+
else
140+
# Scheduled run: generate timestamp-based tag
141+
RELEASE_TAG="build-$(date +%Y%m%d-%H%M%S)"
142+
fi
143+
144+
echo "release_tag=$RELEASE_TAG" >> $GITHUB_OUTPUT
145+
echo "Release tag: $RELEASE_TAG"
146+
147+
# Rename image to include the release tag
148+
TAGGED_IMAGE="nat64-appliance-${RELEASE_TAG}.qcow2"
149+
mv ${{ env.WORK_DIR }}/nat64_appliance/nat64-appliance.qcow2 \
150+
${{ github.workspace }}/${TAGGED_IMAGE}
151+
152+
echo "tagged_image=$TAGGED_IMAGE" >> $GITHUB_OUTPUT
153+
echo "Image renamed to: $TAGGED_IMAGE"
154+
ls -lh ${{ github.workspace }}/${TAGGED_IMAGE}
155+
156+
- name: 8. Create Versioned GitHub Release
157+
uses: softprops/action-gh-release@v2
158+
with:
159+
tag_name: ${{ steps.release_tag.outputs.release_tag }}
160+
name: "NAT64 Appliance ${{ steps.release_tag.outputs.release_tag }}"
161+
body: |
162+
NAT64 Appliance image built by GitHub Actions.
163+
164+
## Build Configuration
165+
166+
- **ci-framework repository**: `${{ inputs.ci_framework_repo || 'https://github.com/openstack-k8s-operators/ci-framework.git' }}`
167+
- **ci-framework reference**: `${{ inputs.ci_framework_ref || 'main' }}`
168+
- **Build type**: ${{ github.event_name == 'schedule' && 'Scheduled (weekly)' || 'Manual dispatch' }}
169+
170+
DIB configuration uses defaults from the ci-framework nat64_appliance role.
171+
172+
## Usage
173+
174+
For usage instructions and deployment examples, see the
175+
[nat64_appliance README](https://github.com/openstack-k8s-operators/ci-framework/blob/main/roles/nat64_appliance/README.md).
176+
files: ${{ steps.release_tag.outputs.tagged_image }}
177+
178+
- name: 9. Update 'latest' Release Tag
179+
uses: softprops/action-gh-release@v2
180+
with:
181+
tag_name: latest
182+
name: "NAT64 Appliance (Latest)"
183+
prerelease: true
184+
body: |
185+
This is the latest NAT64 Appliance build. This release is automatically updated.
186+
187+
**Latest Build**: ${{ steps.release_tag.outputs.release_tag }}
188+
189+
For a specific version or to pin your CI to a known-good build, use one of the versioned releases.
190+
191+
## Usage
192+
193+
For usage instructions and deployment examples, see the
194+
[nat64_appliance README](https://github.com/openstack-k8s-operators/ci-framework/blob/main/roles/nat64_appliance/README.md).
195+
files: ${{ steps.release_tag.outputs.tagged_image }}

0 commit comments

Comments
 (0)