Skip to content

Commit 1917cd5

Browse files
authored
Merge pull request #2802 from OSInside/new_wsl_format
Add support for new tarball-based WSL format
2 parents 2471424 + a2f4ca0 commit 1917cd5

File tree

18 files changed

+307
-8
lines changed

18 files changed

+307
-8
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
3+
<image schemaversion="7.5" name="kiwi-test-image-wsl-ng">
4+
<description type="system">
5+
<author>Marcus Schäfer</author>
6+
<contact>[email protected]</contact>
7+
<specification>WSL test build for WSL >= 2.4.4 new tar spec</specification>
8+
</description>
9+
<preferences>
10+
<version>2.4.4</version>
11+
<packagemanager>zypper</packagemanager>
12+
<rpm-excludedocs>true</rpm-excludedocs>
13+
<rpm-check-signatures>false</rpm-check-signatures>
14+
<locale>en_US</locale>
15+
<keytable>us</keytable>
16+
<type image="wsl"/>
17+
</preferences>
18+
<users>
19+
<user password="$1$wYJUgpM5$RXMMeASDc035eX.NbYWFl0" home="/root" name="root" groups="root"/>
20+
</users>
21+
<repository type="rpm-md">
22+
<source path="obsrepositories:/"/>
23+
</repository>
24+
<packages type="image">
25+
<package name="patterns-openSUSE-base"/>
26+
<package name="systemd"/>
27+
<package name="bash"/>
28+
<package name="acl"/>
29+
<package name="coreutils"/>
30+
<package name="cpio"/>
31+
<package name="findutils"/>
32+
<package name="dracut"/>
33+
<package name="pigz"/>
34+
<package name="iputils"/>
35+
<package name="tar"/>
36+
<package name="psmisc"/>
37+
<package name="lvm2"/>
38+
<package name="fontconfig"/>
39+
<package name="fonts-config"/>
40+
<package name="tar"/>
41+
<package name="sudo"/>
42+
<package name="rsync"/>
43+
</packages>
44+
<packages type="bootstrap">
45+
<package name="gawk"/>
46+
<package name="grep"/>
47+
<package name="gzip"/>
48+
<package name="udev"/>
49+
<package name="xz"/>
50+
<package name="shadow"/>
51+
<package name="filesystem"/>
52+
<package name="glibc-locale"/>
53+
<package name="cracklib-dict-full"/>
54+
<package name="ca-certificates"/>
55+
<package name="ca-certificates-mozilla"/>
56+
<package name="openSUSE-release"/>
57+
</packages>
58+
</image>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[oobe]
2+
defaultUid = 1000
3+
defaultName = SUSE
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[boot]
2+
systemd=true

doc/source/concept_and_workflow/systemdeps.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ following systemdeps packages:
2929
compliant container images.
3030

3131
`kiwi-systemdeps-containers-wsl`:
32-
* Supports building `appx` image types.
32+
* Supports building `appx` and `wsl` image types. The `wsl` type
33+
is the successor for the former `appx` type
3334
* Installs the distribution specific tool chain to build
3435
WSL compliant container images on Windows systems.
3536

doc/source/image_description/elements.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,14 @@ image="appx"
364364
container engine. The image can be loaded From a Windows System
365365
that has support for WSL activated.
366366

367+
image="wsl"
368+
An archive image suitable for the Windows Subsystem For Linux
369+
container engine >= v2.4.4. The image represents a gzip compressed
370+
tar file as described in
371+
https://learn.microsoft.com/en-us/windows/wsl/build-custom-distro
372+
and can be loaded From a Windows System
373+
that has support for WSL in that version activated.
374+
367375
image="kis"
368376
An optional root filesystem image associated with a kernel and initrd.
369377
The use case for this component image type is highly customizable.

doc/source/image_types_and_results.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,14 @@ image="appx"
173173
- **container**:
174174
:file:`{exc_image_base_name}.x86_64-{exc_image_version}.appx`
175175

176+
image="wsl"
177+
An archive image suitable for the Windows Subsystem For Linux
178+
container engine >= v2.4.4. The result is a gzip compressed tar
179+
archive with the `.wsl` extension:
180+
181+
- **container**:
182+
:file:`{exc_image_base_name}.x86_64-{exc_image_version}.wsl`
183+
176184
image="kis"
177185
An optional root filesystem image associated with a kernel and initrd.
178186
All three binaries are packed in a tarball, see :ref:`kis` for further

kiwi/builder/container.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,15 @@ def __init__(
9292
self.system_setup = SystemSetup(
9393
xml_state=xml_state, root_dir=self.root_dir
9494
)
95+
self.special_needs = ['appx', 'wsl']
9596
self.filename = ''.join(
9697
[
9798
target_dir, '/',
9899
xml_state.xml_data.get_name(),
99100
'.' + Defaults.get_platform_name(),
100101
'-' + xml_state.get_image_version(),
101102
'.', self.requested_container_type,
102-
'.tar' if self.requested_container_type != 'appx' else ''
103+
'.tar' if self.requested_container_type not in self.special_needs else ''
103104
]
104105
)
105106
self.result = Result(xml_state)
@@ -115,6 +116,7 @@ def create(self) -> Result:
115116
* image="docker"
116117
* image="oci"
117118
* image="appx"
119+
* image="wsl"
118120
119121
:return: result
120122
@@ -148,7 +150,8 @@ def create(self) -> Result:
148150
self.filename, self.base_image or '', self.ensure_empty_tmpdirs,
149151
self.runtime_config.get_container_compression()
150152
# appx containers already contains a compressed root
151-
if self.requested_container_type != 'appx' else False
153+
# wsl containers recommends gzip and we default to it
154+
if self.requested_container_type not in self.special_needs else False
152155
)
153156
Result.verify_image_size(
154157
self.runtime_config.get_max_size_constraint(),

kiwi/container/__init__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,14 @@ def new(name: str, root_dir: str, custom_args: Dict=None) -> ContainerImageBase:
4545
name_map = {
4646
'docker': 'OCI',
4747
'oci': 'OCI',
48-
'appx': 'Appx'
48+
'appx': 'Appx',
49+
'wsl': 'Wsl'
4950
}
5051
args_map = {
5152
'docker': [root_dir, 'docker-archive', custom_args],
5253
'oci': [root_dir, 'oci-archive', custom_args],
53-
'appx': [root_dir, custom_args]
54+
'appx': [root_dir, custom_args],
55+
'wsl': [root_dir, custom_args]
5456
}
5557
try:
5658
container_image = importlib.import_module(

kiwi/container/setup/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ def new(name: str, root_dir: str, custom_args: Dict=None): # noqa: E252
4141
name_map = {
4242
'docker': 'Docker',
4343
'oci': 'OCI',
44-
'appx': 'Appx'
44+
'appx': 'Appx',
45+
'wsl': 'Wsl'
4546
}
4647
try:
4748
container_setup = importlib.import_module(

kiwi/container/setup/wsl.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Copyright (c) 2025 SUSE LLC. All rights reserved.
2+
#
3+
# This file is part of kiwi.
4+
#
5+
# kiwi is free software: you can redistribute it and/or modify
6+
# it under the terms of the GNU General Public License as published by
7+
# the Free Software Foundation, either version 3 of the License, or
8+
# (at your option) any later version.
9+
#
10+
# kiwi is distributed in the hope that it will be useful,
11+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
# GNU General Public License for more details.
14+
#
15+
# You should have received a copy of the GNU General Public License
16+
# along with kiwi. If not, see <http://www.gnu.org/licenses/>
17+
#
18+
import os
19+
20+
# project
21+
from kiwi.container.setup.base import ContainerSetupBase
22+
from kiwi.exceptions import KiwiContainerSetupError
23+
24+
25+
class ContainerSetupWsl(ContainerSetupBase):
26+
"""
27+
WSL new tar setup
28+
"""
29+
def setup(self):
30+
"""
31+
Setup container metadata
32+
"""
33+
# It's expected that the container metadata for the
34+
# new WSL format is provided by a package or via overlay
35+
# data. Thus this setup routine only checks for the
36+
# presence of the data and fails when missing
37+
distribution_conf = os.path.normpath(
38+
os.sep.join([self.root_dir, 'etc', 'wsl-distribution.conf'])
39+
)
40+
wsl_conf = os.path.normpath(
41+
os.sep.join([self.root_dir, 'etc', 'wsl.conf'])
42+
)
43+
if not os.path.exists(distribution_conf):
44+
raise KiwiContainerSetupError(
45+
f'Mandatory WSL {distribution_conf} not found in root tree'
46+
)
47+
if not os.path.exists(wsl_conf):
48+
raise KiwiContainerSetupError(
49+
f'Mandatory WSL {wsl_conf} not found in root tree'
50+
)

0 commit comments

Comments
 (0)