Skip to content

Commit 48a516c

Browse files
committed
ci: add build kernel workflow
Signed-off-by: Austin Vazquez <austin.vazquez@docker.com>
1 parent e6a8f6e commit 48a516c

File tree

2 files changed

+205
-5
lines changed

2 files changed

+205
-5
lines changed

.github/workflows/build-kernel.yml

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
name: Build Kernel
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
kernel_version:
7+
description: 'Kernel version to build'
8+
required: true
9+
default: '6.12.46'
10+
kernel_arch:
11+
description: 'Kernel architecture'
12+
required: true
13+
default: 'x86_64'
14+
type: choice
15+
options:
16+
- x86_64
17+
- arm64
18+
kernel_nproc:
19+
description: 'Number of parallel build processes'
20+
required: false
21+
default: '4'
22+
23+
permissions:
24+
contents: read
25+
26+
jobs:
27+
build-kernel:
28+
name: Build Kernel ${{ inputs.kernel_version }}-${{ inputs.kernel_arch }}
29+
runs-on: ubuntu-latest
30+
timeout-minutes: 60
31+
32+
steps:
33+
- name: Checkout code
34+
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
35+
36+
- name: Set up Docker Buildx
37+
uses: docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435 # v3.11.1
38+
39+
- name: Calculate kernel cache key
40+
id: cache-key
41+
run: |
42+
# Hash the kernel config and patches to create a unique cache key
43+
CONFIG_FILE="kernel/config-${{ inputs.kernel_version }}-${{ inputs.kernel_arch }}"
44+
45+
if [ ! -f "$CONFIG_FILE" ]; then
46+
echo "Error: Kernel config file $CONFIG_FILE not found"
47+
exit 1
48+
fi
49+
50+
# Calculate hash of config file and all patches
51+
CONFIG_HASH=$(sha256sum "$CONFIG_FILE" | cut -d' ' -f1)
52+
PATCHES_HASH=$(find kernel/patches -type f -name "*.patch" -exec sha256sum {} \; | sort | sha256sum | cut -d' ' -f1)
53+
54+
# Combine version, arch, config hash, and patches hash
55+
CACHE_KEY="kernel-${{ inputs.kernel_version }}-${{ inputs.kernel_arch }}-${CONFIG_HASH:0:8}-${PATCHES_HASH:0:8}"
56+
57+
echo "cache-key=${CACHE_KEY}" >> $GITHUB_OUTPUT
58+
echo "config-hash=${CONFIG_HASH:0:8}" >> $GITHUB_OUTPUT
59+
echo "patches-hash=${PATCHES_HASH:0:8}" >> $GITHUB_OUTPUT
60+
61+
echo "Kernel cache key: ${CACHE_KEY}"
62+
echo "Config hash: ${CONFIG_HASH:0:8}"
63+
echo "Patches hash: ${PATCHES_HASH:0:8}"
64+
65+
- name: Check cache for existing kernel
66+
id: cache-kernel
67+
uses: actions/cache@1bd1e32a3bdc45362d1e726936510720a7c30a57 # v4.2.0
68+
with:
69+
path: _output/nerdbox-kernel-${{ inputs.kernel_arch }}
70+
key: ${{ steps.cache-key.outputs.cache-key }}
71+
lookup-only: true
72+
73+
- name: Build kernel
74+
if: steps.cache-kernel.outputs.cache-hit != 'true'
75+
run: |
76+
docker buildx bake kernel \
77+
--set kernel.args.KERNEL_VERSION=${{ inputs.kernel_version }} \
78+
--set kernel.args.KERNEL_ARCH=${{ inputs.kernel_arch }} \
79+
--set kernel.args.KERNEL_NPROC=${{ inputs.kernel_nproc }}
80+
81+
- name: Verify kernel artifact
82+
if: steps.cache-kernel.outputs.cache-hit != 'true'
83+
run: |
84+
KERNEL_FILE="_output/nerdbox-kernel-${{ inputs.kernel_arch }}"
85+
if [ ! -f "$KERNEL_FILE" ]; then
86+
echo "Error: Kernel file $KERNEL_FILE not found after build"
87+
exit 1
88+
fi
89+
90+
echo "Kernel built successfully:"
91+
ls -lh "$KERNEL_FILE"
92+
file "$KERNEL_FILE"
93+
94+
- name: Save kernel to cache
95+
if: steps.cache-kernel.outputs.cache-hit != 'true'
96+
uses: actions/cache/save@1bd1e32a3bdc45362d1e726936510720a7c30a57 # v4.2.0
97+
with:
98+
path: _output/nerdbox-kernel-${{ inputs.kernel_arch }}
99+
key: ${{ steps.cache-key.outputs.cache-key }}
100+
101+
- name: Upload kernel artifact
102+
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
103+
with:
104+
name: nerdbox-kernel-${{ inputs.kernel_version }}-${{ inputs.kernel_arch }}
105+
path: _output/nerdbox-kernel-${{ inputs.kernel_arch }}
106+
retention-days: 90
107+
if-no-files-found: error
108+
109+
- name: Cache summary
110+
run: |
111+
echo "## Kernel Build Summary" >> $GITHUB_STEP_SUMMARY
112+
echo "" >> $GITHUB_STEP_SUMMARY
113+
echo "- **Version**: ${{ inputs.kernel_version }}" >> $GITHUB_STEP_SUMMARY
114+
echo "- **Architecture**: ${{ inputs.kernel_arch }}" >> $GITHUB_STEP_SUMMARY
115+
echo "- **Cache Key**: \`${{ steps.cache-key.outputs.cache-key }}\`" >> $GITHUB_STEP_SUMMARY
116+
echo "- **Config Hash**: ${{ steps.cache-key.outputs.config-hash }}" >> $GITHUB_STEP_SUMMARY
117+
echo "- **Patches Hash**: ${{ steps.cache-key.outputs.patches-hash }}" >> $GITHUB_STEP_SUMMARY
118+
echo "- **Cache Hit**: ${{ steps.cache-kernel.outputs.cache-hit == 'true' && '✅ Yes (reused existing)' || '❌ No (built from scratch)' }}" >> $GITHUB_STEP_SUMMARY
119+
echo "" >> $GITHUB_STEP_SUMMARY
120+
121+
if [ -f "_output/nerdbox-kernel-${{ inputs.kernel_arch }}" ]; then
122+
echo "### Kernel Details" >> $GITHUB_STEP_SUMMARY
123+
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
124+
ls -lh "_output/nerdbox-kernel-${{ inputs.kernel_arch }}" >> $GITHUB_STEP_SUMMARY
125+
file "_output/nerdbox-kernel-${{ inputs.kernel_arch }}" >> $GITHUB_STEP_SUMMARY
126+
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
127+
fi

.github/workflows/ci.yml

Lines changed: 78 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,18 +98,91 @@ jobs:
9898
#
9999
integration:
100100
name: Integration Tests
101-
runs-on: ubuntu-latest
101+
runs-on: ${{ matrix.os }}
102102
timeout-minutes: 20
103103

104+
strategy:
105+
matrix:
106+
os: [ubuntu-latest, macos-latest]
107+
108+
env:
109+
KERNEL_VERSION: "6.12.46"
110+
111+
# Set based on runner
112+
KERNEL_ARCH: ""
113+
104114
steps:
105115
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
106116

107-
- uses: ./.github/actions/install-go
108-
109117
- uses: docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435 # v3.11.1
110118

111-
- name: Build project
112-
run: make all
119+
- name: Set env
120+
shell: bash
121+
run: |
122+
echo "KERNEL_ARCH=$(uname -m)" >> $GITHUB_ENV
123+
124+
- name: Calculate kernel cache key
125+
id: cache-key
126+
run: |
127+
# Hash the kernel config and patches to create a unique cache key
128+
CONFIG_FILE="kernel/config-${KERNEL_VERSION}-${KERNEL_ARCH}"
129+
130+
if [ ! -f "$CONFIG_FILE" ]; then
131+
echo "Error: Kernel config file $CONFIG_FILE not found"
132+
exit 1
133+
fi
134+
135+
# Calculate hash of config file and all patches
136+
CONFIG_HASH=$(sha256sum "$CONFIG_FILE" | cut -d' ' -f1)
137+
PATCHES_HASH=$(find kernel/patches -type f -name "*.patch" -exec sha256sum {} \; | sort | sha256sum | cut -d' ' -f1)
138+
139+
# Combine version, arch, config hash, and patches hash
140+
CACHE_KEY="kernel-${KERNEL_VERSION}-${KERNEL_ARCH}-${CONFIG_HASH:0:8}-${PATCHES_HASH:0:8}"
141+
142+
echo "cache-key=${CACHE_KEY}" >> $GITHUB_OUTPUT
143+
echo "Kernel cache key: ${CACHE_KEY}"
144+
145+
- name: Restore cached kernel
146+
id: cache-kernel
147+
uses: actions/cache/restore@1bd1e32a3bdc45362d1e726936510720a7c30a57 # v4.2.0
148+
with:
149+
path: _output/nerdbox-kernel-${{ env.KERNEL_ARCH }}
150+
key: ${{ steps.cache-key.outputs.cache-key }}
151+
152+
- name: Build kernel (if cache miss)
153+
if: steps.cache-kernel.outputs.cache-hit != 'true'
154+
run: |
155+
echo "Cache miss - building kernel from scratch"
156+
docker buildx bake kernel \
157+
--set kernel.args.KERNEL_VERSION=${KERNEL_VERSION} \
158+
--set kernel.args.KERNEL_ARCH=${KERNEL_ARCH} \
159+
--set kernel.args.KERNEL_NPROC=12
160+
161+
- name: Save kernel to cache
162+
if: steps.cache-kernel.outputs.cache-hit != 'true'
163+
uses: actions/cache/save@1bd1e32a3bdc45362d1e726936510720a7c30a57 # v4.2.0
164+
with:
165+
path: _output/nerdbox-kernel-${{ env.KERNEL_ARCH }}
166+
key: ${{ steps.cache-key.outputs.cache-key }}
167+
168+
- name: Build remaining artifacts (initrd and shim)
169+
run: |
170+
echo "Building initrd and shim..."
171+
docker buildx bake initrd shim
172+
173+
- name: Verify artifacts
174+
run: |
175+
echo "Verifying build artifacts:"
176+
ls -lh _output/
177+
echo ""
178+
echo "Kernel:"
179+
file _output/nerdbox-kernel-${KERNEL_ARCH}
180+
echo ""
181+
echo "Initrd:"
182+
file _output/nerdbox-initrd
183+
echo ""
184+
echo "Shim:"
185+
file _output/containerd-shim-nerdbox-v1
113186
114187
- name: Run integration tests
115188
run: go test -v ./integration/...

0 commit comments

Comments
 (0)