| 1 |
Building in the Open Build Service |
| 2 |
================================== |
| 3 |
|
| 4 |
.. note:: **Abstract** |
| 5 |
|
| 6 |
This document gives a brief overview of how to build images with |
| 7 |
{kiwi} in version |version| inside of the Open Build Service. |
| 8 |
A tutorial on the Open Build Service itself can be found here: |
| 9 |
https://en.opensuse.org/openSUSE:Build_Service_Tutorial |
| 10 |
|
| 11 |
|
| 12 |
The next-generation {kiwi} is fully integrated with the Open Build Service. |
| 13 |
To start, it's best to check out one of the integration test |
| 14 |
image build projects from the base Testing project |
| 15 |
`Virtualization:Appliances:Images:Testing_$ARCH:$DISTRO` at: |
| 16 |
|
| 17 |
https://build.opensuse.org |
| 18 |
|
| 19 |
For example, the test images for SUSE on x86 can be found `here |
| 20 |
<https://build.opensuse.org/project/show/Virtualization:Appliances:Images:Testing_x86:leap>`__. |
| 21 |
|
| 22 |
|
| 23 |
Advantages of using the Open Build Service (OBS) |
| 24 |
------------------------------------------------ |
| 25 |
|
| 26 |
The Open Build Service offers multiple advantages over running {kiwi} |
| 27 |
locally: |
| 28 |
|
| 29 |
* OBS will host the latest successful build for you without you having to set up |
| 30 |
a server yourself. |
| 31 |
|
| 32 |
* As {kiwi} is fully integrated into OBS, OBS will automatically rebuild your |
| 33 |
images if one of the included packages, one of its dependencies, or {kiwi} |
| 34 |
itself is updated. |
| 35 |
|
| 36 |
* The builds will no longer have to be executed on your own machine but |
| 37 |
will run on OBS, thereby saving you resources. Nevertheless, if a build |
| 38 |
fails, you will get a notification via email (if enabled in your user's |
| 39 |
preferences). |
| 40 |
|
| 41 |
|
| 42 |
Differences Between Building Locally and on OBS |
| 43 |
----------------------------------------------- |
| 44 |
|
| 45 |
Note that there are a number of differences when building images with {kiwi} using |
| 46 |
the Open Build Service. Your image that built locally just fine might not |
| 47 |
build without modifications. |
| 48 |
|
| 49 |
The notable differences to running {kiwi} locally include: |
| 50 |
|
| 51 |
* OBS will pick the {kiwi} package from the repositories configured in your |
| 52 |
project, which will most likely not be the same version that you are |
| 53 |
running locally. |
| 54 |
This is especially relevant when building images for older versions, like |
| 55 |
SUSE Linux Enterprise. Therefore, include the custom appliances |
| 56 |
repository as described in the following section: |
| 57 |
:ref:`obs-recommended-settings`. |
| 58 |
|
| 59 |
* When {kiwi} runs on OBS, OBS will extract the list of packages from |
| 60 |
:file:`config.xml` and use it to create a build root. In contrast to a |
| 61 |
local build (where your distribution's package manager will resolve the |
| 62 |
dependencies and install the packages), OBS will **not** build your image |
| 63 |
if there are multiple packages that could be chosen to satisfy the |
| 64 |
dependencies of your packages [#f1]_. This shows errors like this: |
| 65 |
|
| 66 |
.. code:: bash |
| 67 |
|
| 68 |
unresolvable: have choice for SOMEPACKAGE: SOMEPACKAGE_1 SOMEPACKAGE_2 |
| 69 |
|
| 70 |
This can be solved by explicitly specifying one of the two packages in |
| 71 |
the project configuration via the following setting: |
| 72 |
|
| 73 |
.. code:: bash |
| 74 |
|
| 75 |
Prefer: SOMEPACKAGE_1 |
| 76 |
|
| 77 |
Place the above line into the project configuration, which can be |
| 78 |
accessed either via the web interface (click on the tab ``Project |
| 79 |
Config`` on your project's main page) or via ``osc meta -e prjconf``. |
| 80 |
|
| 81 |
.. warning:: We strongly encourage you to remove your repositories from |
| 82 |
:file:`config.xml` and move them to the repository configuration in |
| 83 |
your project's settings. This usually prevents the issue of having the |
| 84 |
choice for multiple package versions and results in a much smoother |
| 85 |
experience when using OBS. |
| 86 |
|
| 87 |
* By default, OBS builds only a single build type and the default |
| 88 |
profile. If your appliance uses multiple build types, put |
| 89 |
each build type into a profile, as OBS cannot handle multiple build |
| 90 |
types. |
| 91 |
|
| 92 |
There are two options to build multiple profiles on OBS: |
| 93 |
|
| 94 |
1. Add the `OBS-Profiles` XML comment between the XML declaration |
| 95 |
(`<?xml ..?>`) and the opening `<image>` element: |
| 96 |
|
| 97 |
.. code:: xml |
| 98 |
|
| 99 |
<?xml version="1.0" encoding="utf-8"?> |
| 100 |
|
| 101 |
<!-- OBS-Profiles: foo_profile bar_profile --> |
| 102 |
|
| 103 |
<image schemaversion="{schema_version}" name="openSUSE-Leap-15.1"> |
| 104 |
<!-- image description with the profiles foo_profile and bar_profile --> |
| 105 |
</image> |
| 106 |
|
| 107 |
2. Use the `multibuild <https://openbuildservice.org/help/manuals/obs-user-guide/cha.obs.multibuild.html>`_ feature. |
| 108 |
|
| 109 |
The first option is simpler to use but has the disadvantage that your |
| 110 |
appliances are built sequentially. The `multibuild` feature allows you to |
| 111 |
build each profile as a single package, thereby enabling parallel execution, |
| 112 |
but it requires an additional :file:`_multibuild` file. For the above example, |
| 113 |
:file:`config.xml` would have to be adapted as follows: |
| 114 |
|
| 115 |
.. code:: xml |
| 116 |
|
| 117 |
<?xml version="1.0" encoding="utf-8"?> |
| 118 |
|
| 119 |
<!-- OBS-Profiles: @BUILD_FLAVOR@ --> |
| 120 |
|
| 121 |
<image schemaversion="{schema_version}" name="openSUSE-Leap-15.1"> |
| 122 |
<!-- image description with the profiles foo_profile and bar_profile --> |
| 123 |
</image> |
| 124 |
|
| 125 |
The file :file:`_multibuild` would have the following contents: |
| 126 |
|
| 127 |
.. code:: xml |
| 128 |
|
| 129 |
<multibuild> |
| 130 |
<flavor>foo_profile</flavor> |
| 131 |
<flavor>bar_profile</flavor> |
| 132 |
</multibuild> |
| 133 |
|
| 134 |
|
| 135 |
* Subfolders in OBS projects are ignored by default by :command:`osc` and |
| 136 |
must be explicitly added via `osc add $FOLDER` [#f2]_. Bear that |
| 137 |
in mind when adding the overlay files inside the :file:`root/` directory |
| 138 |
to your project. |
| 139 |
|
| 140 |
* OBS ignores file permissions. Therefore, :file:`config.sh` and |
| 141 |
:file:`images.sh` will **always** be executed through BASH (see also: |
| 142 |
:ref:`working-with-kiwi-user-defined-scripts`). |
| 143 |
|
| 144 |
.. _obs-recommended-settings: |
| 145 |
|
| 146 |
Recommendations |
| 147 |
--------------- |
| 148 |
|
| 149 |
Working with OBS |
| 150 |
^^^^^^^^^^^^^^^^ |
| 151 |
|
| 152 |
Although OBS is an online service, it is not necessary to test every change |
| 153 |
by uploading it. OBS will use the same process as `osc build` does, so if |
| 154 |
your image builds locally via `osc build`, it should also build online on |
| 155 |
OBS. |
| 156 |
|
| 157 |
|
| 158 |
Repository Configuration |
| 159 |
^^^^^^^^^^^^^^^^^^^^^^^^ |
| 160 |
|
| 161 |
When setting up the project, enable the `images` repository: the `images` |
| 162 |
repository's checkbox can be found at the bottom of the selection screen |
| 163 |
that appears when clicking `Add from a Distribution` in the `Repositories` |
| 164 |
tab. Or, specify it manually in the project configuration (it can be |
| 165 |
accessed via `osc meta -e prj`): |
| 166 |
|
| 167 |
.. code:: xml |
| 168 |
|
| 169 |
<repository name="images"> |
| 170 |
<arch>x86_64</arch> |
| 171 |
</repository> |
| 172 |
|
| 173 |
Furthermore, OBS requires additional repositories from which it obtains |
| 174 |
your dependent packages. These repositories can be provided in two ways: |
| 175 |
|
| 176 |
#. Add the repositories to the project configuration on OBS and omit them |
| 177 |
from :file:`config.xml`. Provide only the following repository inside |
| 178 |
the image description: |
| 179 |
|
| 180 |
.. code:: xml |
| 181 |
|
| 182 |
<repository type="rpm-md"> |
| 183 |
<source path="obsrepositories:/"/> |
| 184 |
</repository> |
| 185 |
|
| 186 |
This instructs OBS to inject the repositories from your project into |
| 187 |
your appliance. |
| 188 |
|
| 189 |
Additional repositories can be added by invoking `osc meta -e prj` and |
| 190 |
adding a line of the following form as a child of `<repository |
| 191 |
name="images">`: |
| 192 |
|
| 193 |
.. code:: xml |
| 194 |
|
| 195 |
<path project="$OBS_PROJECT" repository="$REPOSITORY_NAME"/> |
| 196 |
|
| 197 |
The order in which you add repositories matters: if a package is present |
| 198 |
in multiple repositories, then it is taken from the **first** |
| 199 |
repository. The **last** repository is subject to path expansion: its |
| 200 |
repository paths are included as well. |
| 201 |
|
| 202 |
Don't forget to add the repository from the |
| 203 |
`Virtualization:Appliances:Builder` project, providing the latest stable |
| 204 |
version of {kiwi} (which you are very likely using for your local builds). |
| 205 |
|
| 206 |
The following example repository configuration [#f3]_ adds the |
| 207 |
repositories from the `Virtualization:Appliances:Builder` project and |
| 208 |
those from the latest snapshot of openSUSE Tumbleweed: |
| 209 |
|
| 210 |
.. code:: xml |
| 211 |
|
| 212 |
<project name="Virtualization:Appliances:Images:openSUSE-Tumbleweed"> |
| 213 |
<title>Tumbleweed JeOS images</title> |
| 214 |
<description>Host JeOS images for Tumbleweed</description> |
| 215 |
<repository name="images"> |
| 216 |
<path project="Virtualization:Appliances:Builder" repository="Factory"/> |
| 217 |
<path project="openSUSE:Factory" repository="snapshot"/> |
| 218 |
<arch>x86_64</arch> |
| 219 |
</repository> |
| 220 |
</project> |
| 221 |
|
| 222 |
The above can be simplified further using the path expansion of the last |
| 223 |
repository to: |
| 224 |
|
| 225 |
.. code:: xml |
| 226 |
|
| 227 |
<project name="Virtualization:Appliances:Images:openSUSE-Tumbleweed"> |
| 228 |
<title>Tumbleweed JeOS images</title> |
| 229 |
<description>Host JeOS images for Tumbleweed</description> |
| 230 |
<repository name="images"> |
| 231 |
<path project="Virtualization:Appliances:Builder" repository="Factory"/> |
| 232 |
<arch>x86_64</arch> |
| 233 |
</repository> |
| 234 |
</project> |
| 235 |
|
| 236 |
Now, `Virtualization:Appliances:Builder` is the last repository whose |
| 237 |
repositories are included into the search path. As |
| 238 |
`openSUSE:Factory/snapshot` is among these, it can be omitted from the |
| 239 |
repository list. |
| 240 |
|
| 241 |
#. Keep the repositories in your :file:`config.xml` configuration file. If |
| 242 |
you have installed the latest stable {kiwi} as described in |
| 243 |
:ref:`kiwi-installation`, then you should add the following repository to |
| 244 |
your project's configuration (accessible via :command:`osc meta -e |
| 245 |
prj`), so that OBS will pick the latest stable {kiwi} version too: |
| 246 |
|
| 247 |
.. code:: xml |
| 248 |
|
| 249 |
<repository name="images"> |
| 250 |
<path project="Virtualization:Appliances:Builder" repository="$DISTRO"/> |
| 251 |
<arch>x86_64</arch> |
| 252 |
</repository> |
| 253 |
|
| 254 |
Replace `$DISTRO` with the appropriate name for the distribution that |
| 255 |
you are currently building and optionally adjust the architecture. |
| 256 |
|
| 257 |
|
| 258 |
We recommend using the first method, as it integrates better into |
| 259 |
OBS. Note that your image description will then no longer build outside of |
| 260 |
OBS, though. If building locally is required, use the second method. |
| 261 |
|
| 262 |
.. warning:: |
| 263 |
|
| 264 |
Adding the repositories to the project's configuration makes it impossible |
| 265 |
to build images for different distributions from the same project. |
| 266 |
|
| 267 |
Since the repositories are added for every package in your project, all |
| 268 |
your image builds will share the same repositories, thereby resulting in |
| 269 |
conflicts for different distributions. |
| 270 |
|
| 271 |
We recommend creating a separate project for each distribution. If that |
| 272 |
is impossible, you can keep all your repositories (including |
| 273 |
`Virtualization:Appliances:Builder`) in :file:`config.xml`. That, however, |
| 274 |
usually requires a large number of workarounds via `Prefer:` settings in |
| 275 |
the project configuration and is thus **not** recommended. |
| 276 |
|
| 277 |
|
| 278 |
Project Configuration |
| 279 |
^^^^^^^^^^^^^^^^^^^^^ |
| 280 |
|
| 281 |
The Open Build Service will, by default, create the same output file as {kiwi} |
| 282 |
when run locally but with a custom filename ending (that is, unfortunately, |
| 283 |
unpredictable). This has the consequence that the download URL of your |
| 284 |
image will change with every rebuild (and thus break automated |
| 285 |
scripts). OBS can create symbolic links with static names to the latest |
| 286 |
build by adding the following line to the project configuration: |
| 287 |
|
| 288 |
.. code:: bash |
| 289 |
|
| 290 |
Repotype: staticlinks |
| 291 |
|
| 292 |
If you build Vagrant images (see :ref:`setup_vagrant`), add the repository-type |
| 293 |
`vagrant`. OBS creates a `boxes/` subdirectory in your download |
| 294 |
repositories, which contains JSON files for Vagrant [#f4]_. |
| 295 |
|
| 296 |
|
| 297 |
If you have added your repositories to :file:`config.xml`, you will probably see |
| 298 |
errors of the following type: |
| 299 |
|
| 300 |
.. code:: bash |
| 301 |
|
| 302 |
unresolvable: have choice for SOMEPACKAGE: SOMEPACKAGE_1 SOMEPACKAGE_2 |
| 303 |
|
| 304 |
Instead of starting from scratch and manually adding `Prefer:` statements |
| 305 |
to the project configuration, we recommend copying the current project |
| 306 |
configuration of the testing project |
| 307 |
`Virtualization:Appliances:Images:Testing_$ARCH:$DISTRO` into your own project. |
| 308 |
It provides a good starting point and can be adapted to your OBS project. |
| 309 |
|
| 310 |
|
| 311 |
.. [#f1] This is a design decision made by OBS: as its purpose is to build |
| 312 |
packages in a reproducible fashion, it cannot make a decision which |
| 313 |
package to choose from multiple available ones. A package manager built |
| 314 |
for end users, on the other hand, **must** make a choice, as it would |
| 315 |
be otherwise hardly usable. |
| 316 |
|
| 317 |
.. [#f2] `osc` compresses added folders into a `cpio |
| 318 |
<https://en.wikipedia.org/wiki/Cpio>`_ archive and decompresses it |
| 319 |
before running your builds. The only downside of this is that the |
| 320 |
contents of your overlay are not conveniently visible via the web |
| 321 |
interface. |
| 322 |
|
| 323 |
.. [#f3] Taken from the project |
| 324 |
`Virtualization:Appliances:Images:openSUSE-Tumbleweed |
| 325 |
<https://build.opensuse.org/project/show/Virtualization:Appliances:Images:openSUSE-Tumbleweed>`_. |
| 326 |
|
| 327 |
.. [#f4] Vagrant uses these JSON files for automatic updates of your |
| 328 |
Vagrant boxes. |