Debian Codegraph @

doc/source/build_methods/build_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} `boxbuild` command.
32
33 Requirements
34 ------------
35
36 The `boxbuild` command is part of {kiwi}. Add the {kiwi} repo from
37 the Open Build Service. For details, see :ref:`installation-from-obs`.
38 The following package pulls in the host requirements for the
39 `boxbuild` command, like QEMU and the tools for the supported
40 sharing backends:
41
42 .. code:: bash
43
44 $ sudo zypper in kiwi-systemdeps-boxbuild
45
46 .. note::
47
48 The `boxbuild` command was formerly provided by the
49 `kiwi-boxed-plugin`. The plugin is no longer needed and is
50 replaced by the `kiwi-systemdeps-boxbuild` package.
51
52 Building with the boxbuild command
53 ----------------------------------
54
55 The {kiwi} command named `boxbuild` uses KVM as a
56 virtualization technology and runs the {kiwi} `build` command inside
57 a KVM-controlled virtual machine. For running the build process in a
58 virtual machine, it's required to provide VM images that are suitable
59 to perform this job. We call the VM images `boxes`, and they contain
60 kiwi itself as well as all other components needed to build appliances.
61 Those boxes are hosted in the Open Build Service and are publicly
62 available at the `Subprojects` tab in the: `Virtualization:Appliances:SelfContained <https://build.opensuse.org/project/show/Virtualization:Appliances:SelfContained>`__
63 project.
64
65 As a user, you don't need to work with the boxes because this is all done
66 by the `boxbuild` command and provided as a service by the {kiwi} team. The `boxbuild`
67 command knows where to fetch the box and also cares for an update of the
68 box when it has changed.
69
70 Building an image with the `boxbuild` command is similar to building with
71 the `build` command. One part of the `boxbuild` command is exactly the same
72 as with the `build` command. The separation between `boxbuild` and `build`
73 options is done using the `kiwi` subcommand. Everything after `kiwi` is passed
74 along to the `build` command running in the box. The following example shows
75 how to build an example from the `kiwi-descriptions` repo:
76
77 .. code:: bash
78
79 $ git clone https://github.com/OSInside/kiwi-descriptions.git
80
81 $ kiwi-ng --profile Virtual system boxbuild --box leap kiwi \
82 --description kiwi-descriptions/suse/x86_64/suse-leap-15.6 \
83 --target-dir /tmp/myimage
84
85 For compatibility with the former `kiwi-boxed-plugin`, the `--` separator
86 is accepted as an alias for `kiwi`. For all options of the `boxbuild`
87 command, see :ref:`kiwi_system_boxbuild`.
88
89 .. note::
90
91 The provided `--description` and `--target-dir` options are
92 set up as shared folders between the host and the box. No other
93 data will be shared with the host.
94
95 Sharing Backends
96 ----------------
97
98 As mentioned above, the `boxbuild` call shares the two host directories
99 provided in `--description` and `--target-dir` with the box. To do this,
100 the following sharing backends are supported:
101
102 ``--9p-sharing``
103 With QEMU's `9pfs`, you can create virtual filesystem devices
104 (virtio-9p-device) and expose them to the box. For more information,
105 see `9pfs <https://wiki.qemu.org/Documentation/9psetup>`__. Using
106 this sharing backend does not require any setup procedure from the
107 user and is also the default for `boxbuild`.
108
109 ``--sshfs-sharing``
110 SSHFS is a FUSE-based filesystem client for mounting remote
111 directories over a Secure Shell connection (SSH). In `boxbuild`,
112 this is used to mount directories from the host into the box.
113 Because this runs through an SSH connection, the host must allow
114 connections from the box. If you plan to use `sshfs`, add the
115 following SSH public key to the :file:`~/.ssh/authorized_keys`
116 file of the user who is expected to call `boxbuild`:
117
118 .. code:: bash
119
120 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
121
122 The public key mentioned here is associated with an SSH key pair
123 we provide in the pre-built box images.
124
125 .. warning::
126
127 If the `sshfs` backend is used without the host trusting the box,
128 the `boxbuild` call will become interactive at the time of the sshfs
129 mount. In this case, the user might be asked for a passphrase, or
130 depending on the host's `sshd` setup, the request will be declined and
131 the boxbuild will fail.
132
133 ``--virtiofs-sharing``
134 QEMU virtio-fs shared filesystem daemon. Share a host directory tree
135 with a box through a virtio-fs device. For more information,
136 see `virtiofs <https://manpages.ubuntu.com/manpages/jammy/en/man1/virtiofsd.1.html>`__.
137 Using this sharing backend does not require any setup procedure from the
138 user.
139
140 .. warning::
141
142 virtiofs support was added but is considered experimental and
143 not yet stable across the distributions. Feedback is welcome.
144
145 Building in Container
146 ---------------------
147
148 By default, and also as the preferred method, boxbuild runs in a KVM
149 virtual machine. However, support for building in container
150 instances via `podman` is also implemented. The boxes are built as
151 virtual machine images and also as OCI containers hosted on the
152 openSUSE registry. In container mode, boxbuild pulls
153 the requested box from the remote registry to the local registry
154 and starts a container instance. The following example shows how
155 to build the mentioned {kiwi} integration test image in a
156 container:
157
158 .. code:: bash
159
160 $ kiwi-ng --profile Virtual system boxbuild --container --box leap kiwi \
161 --description kiwi-descriptions/suse/x86_64/suse-leap-15.6 \
162 --target-dir /tmp/myimage
163
164 .. note::
165
166 The provided `--description` and `--target-dir` options are
167 set up as shared volumes between the host and the box container.
168 In addition, containers also share the kiwi cache from
169 `/var/cache/kiwi` with the host for better performance.
170
171 .. warning::
172
173 For building in a container, several runtime constraints
174 exist, and the isolation model is not as strict as it is
175 when building in a VM. Please read the following information
176 to get clarity on the existing constraints.
177
178 ``loop devices``
179 As kiwi requires loop devices and calls other operations
180 that require root privileges, `podman` is started through `sudo`.
181 As podman runs daemonless, the calling user must have the
182 privileges to perform the needed kiwi actions. Non-
183 privileged builds are therefore not possible in container
184 mode with kiwi.
185
186 ``linux capabilities``
187 Several Linux capabilities, as they can be found in
188 https://man7.org/linux/man-pages/man7/capabilities.7.html, are
189 set when `boxbuild` starts the container:
190
191 * AUDIT_WRITE
192 * AUDIT_CONTROL
193 * CAP_MKNOD
194 * CAP_SYS_ADMIN
195
196 ``host device nodes``
197 The host device nodes from `/dev` are shared with the container
198 instance. This is required to work with loop devices
199 inside the container. Device isolation is therefore
200 not possible in container mode with kiwi. The loop device
201 handling for container-based builds restricts the number of
202 simultaneous kiwi build processes on this host to the number
203 of available loop device nodes exposed from the host kernel.