Skip to content

Commit 753926a

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 753926a

File tree

1 file changed

+201
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)