Skip to content

Commit 2ccca64

Browse files
committed
ci: setup containerd for integration tests
Signed-off-by: Austin Vazquez <[email protected]>
1 parent 3a4e513 commit 2ccca64

File tree

3 files changed

+196
-0
lines changed

3 files changed

+196
-0
lines changed

.github/.tool-versions

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
golang 1.25.5
22
kernel 6.12.46
3+
containerd 2.2.0
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
name: "Setup containerd"
2+
description: "Downloads and installs containerd for use in the workflow"
3+
inputs:
4+
containerd_version:
5+
description: 'Version of containerd to install'
6+
required: false
7+
default: '2.0.2'
8+
architecture:
9+
description: 'Architecture for containerd binary (amd64, arm64)'
10+
required: false
11+
default: 'amd64'
12+
13+
runs:
14+
using: "composite"
15+
steps:
16+
- name: Download containerd
17+
shell: bash
18+
run: |
19+
VERSION="${{ inputs.containerd_version }}"
20+
ARCH="${{ inputs.architecture }}"
21+
22+
echo "Downloading containerd v${VERSION} for ${ARCH}..."
23+
24+
# Construct download URL
25+
TARBALL="containerd-${VERSION}-linux-${ARCH}.tar.gz"
26+
URL="https://github.com/containerd/containerd/releases/download/v${VERSION}/${TARBALL}"
27+
28+
# Download containerd
29+
curl -fsSL -o "/tmp/${TARBALL}" "${URL}"
30+
31+
echo "Downloaded containerd tarball to /tmp/${TARBALL}"
32+
ls -lh "/tmp/${TARBALL}"
33+
34+
- name: Install containerd
35+
shell: bash
36+
run: |
37+
VERSION="${{ inputs.containerd_version }}"
38+
ARCH="${{ inputs.architecture }}"
39+
TARBALL="containerd-${VERSION}-linux-${ARCH}.tar.gz"
40+
41+
echo "Installing containerd..."
42+
43+
# Extract binaries to /usr/local
44+
sudo tar -C /usr/local -xzf "/tmp/${TARBALL}"
45+
46+
# Verify installation
47+
echo "Verifying containerd installation..."
48+
containerd --version
49+
ctr --version
50+
51+
echo "Containerd installed successfully at:"
52+
which containerd
53+
which ctr
54+
55+
- name: Setup containerd config
56+
shell: bash
57+
run: |
58+
echo "Creating containerd config directory..."
59+
sudo mkdir -p /etc/containerd
60+
61+
# Generate default config
62+
echo "Generating default containerd config..."
63+
sudo containerd config default | sudo tee /etc/containerd/config.toml
64+
65+
echo "Containerd config created at /etc/containerd/config.toml"
66+
67+
- name: Create containerd log directory
68+
shell: bash
69+
run: |
70+
echo "Creating log directory for containerd..."
71+
sudo mkdir -p /var/log/containerd
72+
sudo chmod 755 /var/log/containerd
73+
74+
- name: Start containerd
75+
shell: bash
76+
run: |
77+
echo "Starting containerd..."
78+
79+
# Start containerd in background with logging
80+
sudo nohup containerd > /var/log/containerd/containerd.log 2>&1 &
81+
CONTAINERD_PID=$!
82+
83+
echo "Containerd started with PID: $CONTAINERD_PID"
84+
85+
# Save PID for cleanup
86+
echo "$CONTAINERD_PID" | sudo tee /var/run/containerd.pid
87+
88+
# Wait for containerd to be ready
89+
echo "Waiting for containerd to be ready..."
90+
for i in {1..30}; do
91+
if sudo ctr version >/dev/null 2>&1; then
92+
echo "Containerd is ready!"
93+
break
94+
fi
95+
if [ $i -eq 30 ]; then
96+
echo "Error: Containerd failed to start within 30 seconds"
97+
echo "Containerd logs:"
98+
sudo cat /var/log/containerd/containerd.log
99+
exit 1
100+
fi
101+
echo "Waiting... ($i/30)"
102+
sleep 1
103+
done
104+
105+
# Verify containerd is running
106+
sudo ctr version
107+
echo "Containerd is running successfully"
108+
109+
- name: Installation summary
110+
shell: bash
111+
run: |
112+
echo "## Containerd Setup Summary" >> $GITHUB_STEP_SUMMARY
113+
echo "" >> $GITHUB_STEP_SUMMARY
114+
echo "- **Version**: ${{ inputs.containerd_version }}" >> $GITHUB_STEP_SUMMARY
115+
echo "- **Architecture**: ${{ inputs.architecture }}" >> $GITHUB_STEP_SUMMARY
116+
echo "- **Status**: ✅ Running" >> $GITHUB_STEP_SUMMARY
117+
echo "" >> $GITHUB_STEP_SUMMARY
118+
echo "### Installed Binaries" >> $GITHUB_STEP_SUMMARY
119+
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
120+
containerd --version >> $GITHUB_STEP_SUMMARY
121+
ctr --version >> $GITHUB_STEP_SUMMARY
122+
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
123+
echo "" >> $GITHUB_STEP_SUMMARY
124+
echo "### Binary Locations" >> $GITHUB_STEP_SUMMARY
125+
echo "- containerd: \`$(which containerd)\`" >> $GITHUB_STEP_SUMMARY
126+
echo "- ctr: \`$(which ctr)\`" >> $GITHUB_STEP_SUMMARY
127+
echo "" >> $GITHUB_STEP_SUMMARY
128+
echo "### Process Info" >> $GITHUB_STEP_SUMMARY
129+
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
130+
ps aux | grep containerd | grep -v grep >> $GITHUB_STEP_SUMMARY || echo "No containerd processes found" >> $GITHUB_STEP_SUMMARY
131+
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
132+
echo "" >> $GITHUB_STEP_SUMMARY
133+
echo "### Logs" >> $GITHUB_STEP_SUMMARY
134+
echo "Containerd logs are available at: \`/var/log/containerd/containerd.log\`" >> $GITHUB_STEP_SUMMARY

.github/workflows/ci.yml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ jobs:
1515
runs-on: ubuntu-latest
1616
outputs:
1717
kernel-version: ${{ steps.set-vars.outputs.kernel-version }}
18+
containerd-version: ${{ steps.set-vars.outputs.containerd-version }}
1819
steps:
1920
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
2021
with:
@@ -26,6 +27,8 @@ jobs:
2627
run: |
2728
kernel_version=$(grep -E '^kernel [0-9.]+$' .github/.tool-versions | sed -E 's/^kernel ([0-9.]+)$/\1/')
2829
echo "kernel-version=${kernel_version}" >> $GITHUB_OUTPUT
30+
containerd_version=$(grep -E '^containerd [0-9.]+$' .github/.tool-versions | sed -E 's/^containerd ([0-9.]+)$/\1/')
31+
echo "containerd-version=${containerd_version}" >> $GITHUB_OUTPUT
2932
3033
linters:
3134
permissions:
@@ -227,5 +230,63 @@ jobs:
227230
with:
228231
go-version-file: '.github/.tool-versions'
229232

233+
- name: Setup containerd
234+
uses: ./.github/actions/setup-containerd
235+
with:
236+
containerd_version: ${{ needs.setup.outputs.containerd-version }}
237+
architecture: ${{ matrix.arch == 'x86_64' && 'amd64' || 'arm64' }}
238+
230239
- name: Run integration tests
240+
id: integration-tests
231241
run: go test -v ./integration/...
242+
243+
- name: Output containerd logs on failure
244+
if: failure() && steps.integration-tests.outcome == 'failure'
245+
run: |
246+
echo "Integration tests failed. Outputting containerd logs..."
247+
echo "==================== CONTAINERD LOGS ===================="
248+
sudo cat /var/log/containerd/containerd.log || echo "No containerd logs found"
249+
echo "========================================================="
250+
echo ""
251+
echo "Containerd process status:"
252+
ps aux | grep containerd | grep -v grep || echo "No containerd processes running"
253+
254+
- name: Stop containerd
255+
if: always()
256+
run: |
257+
echo "Stopping containerd..."
258+
259+
# Try to stop containerd gracefully using pkill
260+
if pgrep -x containerd > /dev/null; then
261+
echo "Found running containerd process(es)"
262+
sudo pkill -TERM containerd || true
263+
264+
# Wait up to 10 seconds for graceful shutdown
265+
for i in {1..10}; do
266+
if ! pgrep -x containerd > /dev/null; then
267+
echo "Containerd stopped gracefully"
268+
break
269+
fi
270+
if [ $i -eq 10 ]; then
271+
echo "Containerd did not stop gracefully, forcing shutdown..."
272+
sudo pkill -KILL containerd || true
273+
fi
274+
sleep 1
275+
done
276+
else
277+
echo "No containerd process found running"
278+
fi
279+
280+
# Clean up PID file if it exists
281+
if [ -f /var/run/containerd.pid ]; then
282+
sudo rm -f /var/run/containerd.pid
283+
echo "Cleaned up containerd PID file"
284+
fi
285+
286+
# Verify containerd is stopped
287+
if pgrep -x containerd > /dev/null; then
288+
echo "Warning: Containerd process still running after cleanup attempt"
289+
ps aux | grep containerd | grep -v grep
290+
else
291+
echo "Containerd stopped successfully"
292+
fi

0 commit comments

Comments
 (0)