Debian Codegraph @

doc/source/plugins/self_contained.rst

raw
1 .. _self_contained:
2
3 Building in a Self-Contained Environment
4 ========================================
5
6 .. note:: **Abstract**
7
8 Users building images with {kiwi} face problems if they want
9 to build an image matching one of the following criteria:
10
11 * The build should happen as a non-root user.
12
13 * The build should happen on a host system distribution for which
14 no {kiwi} packages exist.
15
16 * The build happens on an incompatible host system distribution
17 compared to the target image distribution. For example,
18 building an apt/dpkg-based system on an rpm-based system.
19
20 * Run more than one build process at the same time on the
21 same host.
22
23 * Run a build process for a different target architecture
24 compared to the host architecture (Cross-Arch Image Build).
25
26 This document describes how to perform the build process in
27 a self-contained environment using fast-booting virtual
28 machines to address the issues listed above.
29
30 The changes on the machine to become a build host will
31 be reduced to the requirements of the {kiwi} `boxed plugin`.
32
33 Requirements
34 ------------
35
36 Add the {kiwi} repo from the Open Build Service. For details, see
37 :ref:`installation-from-obs`. The following {kiwi} plugin needs to be
38 installed on the build system:
39
40 .. code:: bash
41
42 $ sudo zypper in python3-kiwi_boxed_plugin
43
44 Building with the boxbuild command
45 ----------------------------------
46
47 The installation of the {kiwi} boxed plugin has registered a new kiwi
48 command named `boxbuild`. The command implementation uses KVM as a
49 virtualization technology and runs the {kiwi} `build` command inside
50 a KVM-controlled virtual machine. For running the build process in a
51 virtual machine, it's required to provide VM images that are suitable
52 to perform this job. We call the VM images `boxes`, and they contain
53 kiwi itself as well as all other components needed to build appliances.
54 Those boxes are hosted in the Open Build Service and are publicly
55 available at the `Subprojects` tab in the: `Virtualization:Appliances:SelfContained <https://build.opensuse.org/project/show/Virtualization:Appliances:SelfContained>`__
56 project.
57
58 As a user, you don't need to work with the boxes because this is all done
59 by the plugin and provided as a service by the {kiwi} team. The `boxbuild`
60 command knows where to fetch the box and also cares for an update of the
61 box when it has changed.
62
63 Building an image with the `boxbuild` command is similar to building with
64 the `build` command. The plugin validates the given command call with the
65 capabilities of the `build` command. Thus, one part of the `boxbuild` command
66 is exactly the same as with the `build` command. The separation between
67 `boxbuild` and `build` options is done using the `--` separator. The following
68 example shows how to build an example from the `kiwi-descriptions` repo:
69
70 .. code:: bash
71
72 $ git clone https://github.com/OSInside/kiwi-descriptions.git
73
74 $ kiwi-ng --profile Virtual system boxbuild --box leap -- \
75 --description kiwi-descriptions/suse/x86_64/suse-leap-15.6 \
76 --target-dir /tmp/myimage
77
78 .. note::
79
80 The provided `--description` and `--target-dir` options are
81 set up as shared folders between the host and the box. No other
82 data will be shared with the host.
83
84 Sharing Backends
85 ----------------
86
87 As mentioned above, the `boxbuild` call shares the two host directories
88 provided in `--description` and `--target-dir` with the box. To do this,
89 the following sharing backends are supported:
90
91 ``--9p-sharing``
92 With QEMU's `9pfs`, you can create virtual filesystem devices
93 (virtio-9p-device) and expose them to the box. For more information,
94 see `9pfs <https://wiki.qemu.org/Documentation/9psetup>`__. Using
95 this sharing backend does not require any setup procedure from the
96 user and is also the default for `boxbuild`.
97
98 ``--sshfs-sharing``
99 SSHFS is a FUSE-based filesystem client for mounting remote
100 directories over a Secure Shell connection (SSH). In `boxbuild`,
101 this is used to mount directories from the host into the box.
102 Because this runs through an SSH connection, the host must allow
103 connections from the box. If you plan to use `sshfs`, add the
104 following SSH public key to the :file:`~/.ssh/authorized_keys`
105 file of the user who is expected to call `boxbuild`:
106
107 .. code:: bash
108
109 echo "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQCtiqDaYgEMkr7za7qc4iPXftgu/j3sodPOtpoG8PinwRX6/3xZteOJzCH2qCZjEgA5zsP9lxy/119cWXvdxFUvyEINjH77unzRnaHj/yTXPhHuhHgAiEubuHer2gZoOs+UH4cGJLKCrabjTjZdeK9KvL+hoAgJaWxDUvGsXYDQTBHXlKjniOL1MGbltDBHnYhu4k+PjjJ+UEBN+8+F74Y5fYgIovXXY88WQrybuEr1eAYjhvk/ln6TKw1P6uvVMuIbAGUgnZFntDCI91Qw8ps1j+lX3vNc8ZBoOwM6nHZqq4FAqbXuH+NvQFS/xDM6wwZQhAe+14dTQBA5F1mgCVf+fSbteb0/CraSGmgKIM8aPnK8rfF+BY6Jar3AJFKVRPshRzrQj6CWYu3BfmOLupCpqOK2XFyoU2lEpaZDejgPSJq/IBGZdjKplWJFF8ZRQ01a8eX8K2fjrQt/4k9c7Pjlg1aDH8Sf+5+vcehlSNs1d50wnFoaIPrgDdy04omiaJ8= kiwi@boxbuild" >> ~/.ssh/authorized_keys
110
111 The public key mentioned here is associated with an SSH key pair
112 we provide in the pre-built box images.
113
114 .. warning::
115
116 If the `sshfs` backend is used without the host trusting the box,
117 the `boxbuild` call will become interactive at the time of the sshfs
118 mount. In this case, the user might be asked for a passphrase, or
119 depending on the host's `sshd` setup, the request will be declined and
120 the boxbuild will fail.
121
122 ``--virtiofs-sharing``
123 QEMU virtio-fs shared filesystem daemon. Share a host directory tree
124 with a box through a virtio-fs device. For more information,
125 see `virtiofs <https://manpages.ubuntu.com/manpages/jammy/en/man1/virtiofsd.1.html>`__.
126 Using this sharing backend does not require any setup procedure from the
127 user.
128
129 .. warning::
130
131 virtiofs support was added but is considered experimental and
132 not yet stable across the distributions. Feedback is welcome.
133
134 Building in Container
135 ---------------------
136
137 By default, and also as the preferred method, boxbuild runs in a KVM
138 virtual machine. However, support for building in container
139 instances via `podman` is also implemented. The boxes are built as
140 virtual machine images and also as OCI containers hosted on the
141 openSUSE registry. In container mode, boxbuild pulls
142 the requested box from the remote registry to the local registry
143 and starts a container instance. The following example shows how
144 to build the mentioned {kiwi} integration test image in a
145 container:
146
147 .. code:: bash
148
149 $ kiwi-ng --profile Virtual system boxbuild --container --box leap -- \
150 --description kiwi-descriptions/suse/x86_64/suse-leap-15.6 \
151 --target-dir /tmp/myimage
152
153 .. note::
154
155 The provided `--description` and `--target-dir` options are
156 set up as shared volumes between the host and the box container.
157 In addition, containers also share the kiwi cache from
158 `/var/cache/kiwi` with the host for better performance.
159
160 .. warning::
161
162 For building in a container, several runtime constraints
163 exist, and the isolation model is not as strict as it is
164 when building in a VM. Please read the following information
165 to get clarity on the existing constraints.
166
167 ``loop devices``
168 As kiwi requires loop devices and calls other operations
169 that require root privileges, `podman` is started through `sudo`.
170 As podman runs daemonless, the calling user must have the
171 privileges to perform the needed kiwi actions. Non-
172 privileged builds are therefore not possible in container
173 mode with kiwi.
174
175 ``linux capabilities``
176 Several Linux capabilities, as they can be found in
177 https://man7.org/linux/man-pages/man7/capabilities.7.html, are
178 set when `boxbuild` starts the container:
179
180 * AUDIT_WRITE
181 * AUDIT_CONTROL
182 * CAP_MKNOD
183 * CAP_SYS_ADMIN
184
185 ``host device nodes``
186 The host device nodes from `/dev` are shared with the container
187 instance. This is required to work with loop devices
188 inside the container. Device isolation is therefore
189 not possible in container mode with kiwi. The loop device
190 handling for container-based builds restricts the number of
191 simultaneous kiwi build processes on this host to the number
192 of available loop device nodes exposed from the host kernel.