Skip to content

Commit d5d690f

Browse files
authored
Multi kernel support (#45)
## Description Fixes: # ## How Has This Been Tested? ## How are existing users impacted? What migration steps/scripts do we need? ## Checklist: I have: - [ ] updated the documentation and/or roadmap (if required) - [ ] added unit or e2e tests - [ ] provided instructions on how to upgrade
2 parents 2dcad22 + 17d412e commit d5d690f

File tree

18 files changed

+2099
-167
lines changed

18 files changed

+2099
-167
lines changed

.github/workflows/ci.yml

Lines changed: 28 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ on:
55
- "main"
66
pull_request:
77

8-
env:
9-
KERNEL_VERSION: "6.12.69"
10-
118
permissions:
129
contents: read
1310
packages: write
1411

12+
env:
13+
KERNEL_VERSION: 6.18.16
14+
1515
jobs:
1616
# -------------------------------------------------------------------
1717
# Lint — ruff (lint + format) and pyright (type checking)
@@ -52,19 +52,17 @@ jobs:
5252
uses: actions/cache/restore@v4
5353
with:
5454
path: |
55-
mkosi.output/extra-tree/amd64/usr/lib/modules
56-
mkosi.output/vmlinuz/amd64
57-
key: kernel-amd64-${{ env.KERNEL_VERSION }}-${{ hashFiles('config/defconfig.*', 'Dockerfile') }}
55+
mkosi.output/kernel/${{ env.KERNEL_VERSION }}/amd64
56+
key: kernel-amd64-${{ env.KERNEL_VERSION }}-${{ hashFiles('kernel.configs/*', 'Dockerfile') }}
5857
lookup-only: true
5958

6059
- name: Check arm64 kernel cache
6160
id: arm64-cache
6261
uses: actions/cache/restore@v4
6362
with:
6463
path: |
65-
mkosi.output/extra-tree/arm64/usr/lib/modules
66-
mkosi.output/vmlinuz/arm64
67-
key: kernel-arm64-${{ env.KERNEL_VERSION }}-${{ hashFiles('config/defconfig.*', 'Dockerfile') }}
64+
mkosi.output/kernel/${{ env.KERNEL_VERSION }}/arm64
65+
key: kernel-arm64-${{ env.KERNEL_VERSION }}-${{ hashFiles('kernel.configs/*', 'Dockerfile') }}
6866
lookup-only: true
6967

7068
# -------------------------------------------------------------------
@@ -137,9 +135,8 @@ jobs:
137135
uses: actions/cache/restore@v4
138136
with:
139137
path: |
140-
mkosi.output/extra-tree/${{ matrix.arch }}/usr/lib/modules
141-
mkosi.output/vmlinuz/${{ matrix.arch }}
142-
key: kernel-${{ matrix.arch }}-${{ env.KERNEL_VERSION }}-${{ hashFiles('config/defconfig.*', 'Dockerfile') }}
138+
mkosi.output/kernel/${{ env.KERNEL_VERSION }}/${{ matrix.arch }}
139+
key: kernel-${{ matrix.arch }}-${{ env.KERNEL_VERSION }}-${{ hashFiles('kernel.configs/*', 'Dockerfile') }}
143140

144141
- name: Install Python dependencies
145142
run: pip install -r requirements.txt
@@ -155,17 +152,15 @@ jobs:
155152
uses: actions/cache/save@v4
156153
with:
157154
path: |
158-
mkosi.output/extra-tree/${{ matrix.arch }}/usr/lib/modules
159-
mkosi.output/vmlinuz/${{ matrix.arch }}
160-
key: kernel-${{ matrix.arch }}-${{ env.KERNEL_VERSION }}-${{ hashFiles('config/defconfig.*', 'Dockerfile') }}
155+
mkosi.output/kernel/${{ env.KERNEL_VERSION }}/${{ matrix.arch }}
156+
key: kernel-${{ matrix.arch }}-${{ env.KERNEL_VERSION }}-${{ hashFiles('kernel.configs/*', 'Dockerfile') }}
161157

162158
- name: Upload kernel artifacts
163159
uses: actions/upload-artifact@v4
164160
with:
165161
name: kernel-${{ matrix.arch }}
166162
path: |
167-
mkosi.output/extra-tree/${{ matrix.arch }}/usr/lib/modules
168-
mkosi.output/vmlinuz/${{ matrix.arch }}
163+
mkosi.output/kernel/${{ env.KERNEL_VERSION }}/${{ matrix.arch }}
169164
retention-days: 1
170165

171166
# -------------------------------------------------------------------
@@ -192,8 +187,8 @@ jobs:
192187
uses: actions/cache/restore@v4
193188
with:
194189
path: |
195-
mkosi.output/extra-tree/${{ matrix.arch }}/usr/local/bin
196-
mkosi.output/extra-tree/${{ matrix.arch }}/opt/cni
190+
mkosi.output/tools/${{ matrix.arch }}/usr/local/bin
191+
mkosi.output/tools/${{ matrix.arch }}/opt/cni
197192
key: tools-${{ matrix.arch }}-${{ hashFiles('captain/tools.py') }}
198193

199194
- name: Install Python dependencies
@@ -207,17 +202,17 @@ jobs:
207202
uses: actions/cache/save@v4
208203
with:
209204
path: |
210-
mkosi.output/extra-tree/${{ matrix.arch }}/usr/local/bin
211-
mkosi.output/extra-tree/${{ matrix.arch }}/opt/cni
205+
mkosi.output/tools/${{ matrix.arch }}/usr/local/bin
206+
mkosi.output/tools/${{ matrix.arch }}/opt/cni
212207
key: tools-${{ matrix.arch }}-${{ hashFiles('captain/tools.py') }}
213208

214209
- name: Upload tools artifacts
215210
uses: actions/upload-artifact@v4
216211
with:
217212
name: tools-${{ matrix.arch }}
218213
path: |
219-
mkosi.output/extra-tree/${{ matrix.arch }}/usr/local/bin
220-
mkosi.output/extra-tree/${{ matrix.arch }}/opt/cni
214+
mkosi.output/tools/${{ matrix.arch }}/usr/local/bin
215+
mkosi.output/tools/${{ matrix.arch }}/opt/cni
221216
retention-days: 1
222217

223218
# -------------------------------------------------------------------
@@ -242,13 +237,13 @@ jobs:
242237
uses: actions/download-artifact@v4
243238
with:
244239
name: kernel-${{ matrix.arch }}
245-
path: mkosi.output
240+
path: mkosi.output/kernel/${{ env.KERNEL_VERSION }}/${{ matrix.arch }}
246241

247242
- name: Download tools artifacts
248243
uses: actions/download-artifact@v4
249244
with:
250245
name: tools-${{ matrix.arch }}
251-
path: mkosi.output/extra-tree/${{ matrix.arch }}
246+
path: mkosi.output/tools/${{ matrix.arch }}
252247

253248
- name: Refresh apt cache
254249
run: sudo apt-get update
@@ -333,7 +328,7 @@ jobs:
333328
uses: actions/download-artifact@v4
334329
with:
335330
name: kernel-${{ matrix.arch }}
336-
path: mkosi.output
331+
path: mkosi.output/kernel/${{ env.KERNEL_VERSION }}/${{ matrix.arch }}
337332

338333
- name: Download initramfs artifacts
339334
uses: actions/download-artifact@v4
@@ -343,8 +338,9 @@ jobs:
343338

344339
- name: Stage initramfs for ISO build
345340
run: |
346-
mkdir -p mkosi.output/initramfs/${{ matrix.arch }}
347-
cp out/initramfs-${{ matrix.arch }}.cpio.zst mkosi.output/initramfs/${{ matrix.arch }}/image.cpio.zst
341+
mkdir -p "mkosi.output/initramfs/${KERNEL_VERSION}/${{ matrix.arch }}"
342+
cp "out/initramfs-${KERNEL_VERSION}-${{ matrix.arch }}.cpio.zst" \
343+
"mkosi.output/initramfs/${KERNEL_VERSION}/${{ matrix.arch }}/image.cpio.zst"
348344
349345
- name: Install Python dependencies
350346
run: pip install -r requirements.txt
@@ -356,7 +352,7 @@ jobs:
356352
uses: actions/upload-artifact@v4
357353
with:
358354
name: iso-${{ matrix.arch }}
359-
path: out/captainos-${{ matrix.arch }}.iso
355+
path: out/captainos-${{ env.KERNEL_VERSION }}-${{ matrix.arch }}.iso
360356
retention-days: 1
361357

362358
# -------------------------------------------------------------------
@@ -386,7 +382,7 @@ jobs:
386382
uses: actions/download-artifact@v4
387383
with:
388384
name: kernel-${{ matrix.target }}
389-
path: mkosi.output
385+
path: mkosi.output/kernel/${{ env.KERNEL_VERSION }}/${{ matrix.target }}
390386

391387
- name: Download initramfs artifacts
392388
uses: actions/download-artifact@v4
@@ -436,7 +432,7 @@ jobs:
436432
uses: actions/download-artifact@v4
437433
with:
438434
name: kernel-amd64
439-
path: mkosi.output
435+
path: mkosi.output/kernel/${{ env.KERNEL_VERSION }}/amd64
440436

441437
- name: Download initramfs artifacts (amd64)
442438
uses: actions/download-artifact@v4
@@ -454,7 +450,7 @@ jobs:
454450
uses: actions/download-artifact@v4
455451
with:
456452
name: kernel-arm64
457-
path: mkosi.output
453+
path: mkosi.output/kernel/${{ env.KERNEL_VERSION }}/arm64
458454

459455
- name: Download initramfs artifacts (arm64)
460456
uses: actions/download-artifact@v4

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ mkosi.cache/
44
mkosi.tools/
55
mkosi.tools.manifest
66
mkosi.builddir/
7-
config/.config.resolved.*
7+
kernel.configs/.config.resolved.*
88
out/
99

1010
# Editor

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ It is built with [mkosi](https://github.com/systemd/mkosi), producing a minimal
2626

2727
The build has four stages:
2828

29-
1. **Kernel compilation** (`./build.py kernel`) — builds a Linux kernel from source using minimal defconfigs (`config/defconfig.{amd64,arm64}`)
29+
1. **Kernel compilation** (`./build.py kernel`) — builds a Linux kernel from source using defconfigs from `kernel.configs/`
3030
2. **Tool download** (`./build.py tools`) — fetches pinned binary releases of the container runtime stack
3131
3. **Initramfs build** (`./build.py initramfs`) — assembles a Debian Trixie CPIO initramfs with systemd, injecting the kernel, modules, and tools using `mkosi`
3232
4. **ISO assembly** (`./build.py iso`) — builds a UEFI-bootable ISO with GRUB via `grub-mkrescue`
@@ -38,7 +38,7 @@ The build has four stages:
3838
```bash
3939
pip install -r requirements.txt
4040

41-
# Build with defaults (amd64, kernel 6.12.69)
41+
# Build with defaults (amd64, kernel 6.18.16)
4242
./build.py --help
4343

4444
usage: build.py [flags]
@@ -54,7 +54,7 @@ build configuration:
5454
--no-cache rebuild builder image without Docker cache
5555

5656
kernel:
57-
--kernel-version VER kernel version to build (default: 6.12.69)
57+
--kernel-version VER kernel version to build (default: 6.18.16)
5858
--kernel-src PATH path to local kernel source tree
5959
--kernel-mode {docker,native,skip} kernel stage execution mode (default: docker)
6060
--force-kernel force kernel rebuild even if outputs exist

captain/artifacts.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,18 @@ def _human_size(size: int) -> str:
3232

3333

3434
def collect_kernel(cfg: Config, logger: StageLogger | None = None) -> None:
35-
"""Copy the kernel image from mkosi.output/vmlinuz/{arch}/ to out/."""
35+
"""Copy the kernel image from mkosi.output/kernel/{version}/{arch}/ to out/."""
3636
_log = logger or _default_log
3737
out = ensure_dir(cfg.output_dir)
38-
vmlinuz_dir = cfg.vmlinuz_output
38+
vmlinuz_dir = cfg.kernel_output
3939
vmlinuz_files = sorted(vmlinuz_dir.glob("vmlinuz-*")) if vmlinuz_dir.is_dir() else []
4040
if vmlinuz_files:
4141
vmlinuz_src = vmlinuz_files[0]
42-
vmlinuz_dst = out / f"vmlinuz-{cfg.arch}"
42+
vmlinuz_dst = out / f"vmlinuz-{cfg.kernel_version}-{cfg.arch}"
4343
shutil.copy2(vmlinuz_src, vmlinuz_dst)
4444
_log.log(f"kernel: {vmlinuz_dst} ({_human_size(vmlinuz_dst.stat().st_size)})")
4545
else:
46-
_log.warn("No kernel image found in mkosi.output/vmlinuz/{arch}/")
46+
_log.warn(f"No kernel image found in {cfg.kernel_output}")
4747

4848

4949
def collect_initramfs(cfg: Config, logger: StageLogger | None = None) -> None:
@@ -53,11 +53,11 @@ def collect_initramfs(cfg: Config, logger: StageLogger | None = None) -> None:
5353
cpio_files = sorted(cfg.initramfs_output.glob("*.cpio*"))
5454
if cpio_files:
5555
initrd_src = cpio_files[0]
56-
initrd_dst = out / f"initramfs-{cfg.arch}.cpio.zst"
56+
initrd_dst = out / f"initramfs-{cfg.kernel_version}-{cfg.arch}.cpio.zst"
5757
shutil.copy2(initrd_src, initrd_dst)
5858
_log.log(f"initramfs: {initrd_dst} ({_human_size(initrd_dst.stat().st_size)})")
5959
else:
60-
_log.warn("No initramfs CPIO found in mkosi.output/initramfs/{arch}/")
60+
_log.warn(f"No initramfs CPIO found in {cfg.initramfs_output}")
6161

6262

6363
def collect_iso(cfg: Config, logger: StageLogger | None = None) -> None:
@@ -68,7 +68,7 @@ def collect_iso(cfg: Config, logger: StageLogger | None = None) -> None:
6868
iso_files = sorted(iso_dir.glob("*.iso")) if iso_dir.is_dir() else []
6969
if iso_files:
7070
iso_src = iso_files[0]
71-
iso_dst = out / f"captainos-{cfg.arch}.iso"
71+
iso_dst = out / f"captainos-{cfg.kernel_version}-{cfg.arch}.iso"
7272
shutil.copy2(iso_src, iso_dst)
7373
_log.log(f"iso: {iso_dst} ({_human_size(iso_dst.stat().st_size)})")
7474

0 commit comments

Comments
 (0)