Commit graph

117 commits

Author SHA1 Message Date
Alexander Larsson
10333fa8ba osbuild-mpp: Report the path of the json file when parsing fails
This makes it a lot easier to understand failures when files are
including other files.
2021-11-18 21:00:13 +01:00
Christian Kellner
15759dd205 tools/osbuild-mpp: add ability to embed data
Add a new pre-processor directive to MPP that allows to define
`org.osbuild.inline` sources on the fly by embedding data or
files into the manifest.
2021-11-18 13:41:06 +01:00
Christian Kellner
22e670050f osbuild-mpp: extract finding files and opening
Extract the code that finds a file and opens it from the existing
method that find manifests and opens them. This is so that the
former code can be re-used.
2021-11-18 13:41:06 +01:00
Alexander Larsson
ffdbdf6235 osbuild-mpp: Support mpp-if
This allows optional manifest json values like "if blah, add stage foo",
or selecting between possible nodes, "if blah, stage is foo, else bar".
2021-11-18 11:33:57 +01:00
Alexander Larsson
04d880852a osbuild-mpp: Break out helper function
This breaks out the fakeroot handling used to rewrite a single node.
We'll use this in some new cases later.
2021-11-18 11:33:57 +01:00
Christian Kellner
c42c19356c mpp: fix long options
The correct way to specify long options is as separate arguments,
not as one argument separated by comma.
2021-10-25 18:01:25 +02:00
Alexander Larsson
611b6846e8 osbuild-mpp: Set the "arch" variable to the current rpm arch 2021-10-25 15:17:04 +02:00
Alexander Larsson
1425f66449 osbuild-mpp: Better handling of variable defaults and propagation
We now allow there to be default variables (none so far) which gets
installed as the initial value of manifest.vars.

Additionally, when including a file the default comes from the current
state of the including manifest, allowing the included manifest to use
variables from the base file.
2021-10-25 15:17:04 +02:00
Alexander Larsson
41db488aaa osbuild-mpp: Better handling of -D overrides
We expand variables in various places during load, like when importing
files, etc. This means that the current approach of merging the
overrides into `manifest.vars` at the end doesn't work.

Instead we track overrides completely separate, and when we do the
expansion that always replaces whatever is in `manifest.vars`.
2021-10-25 15:17:04 +02:00
Alexander Larsson
2d16f1243b osbuild-mpp: Allow using formating in depsolver node
This is very useful so that mpp-join can create a merged
package list.
2021-10-25 15:17:04 +02:00
Alexander Larsson
cedb2426c7 osbuild-mpp: Add mpp-join
This allows you to join a set of lists, its very nice to use
e.g. when constructing the package-list for a depsolve node.
2021-10-25 15:17:04 +02:00
Alexander Larsson
01fbc8c136 osbuild-mpp: Add mpp-eval
This:
 {"mpp-eval": "foo+bar"}

Is essentially the same as using mpp-format with a trivial format
string:

 {"mpp-format-int": "{foo+bar}"}

However, it is less to type, clearer to read, and supports
returning more complex types. For example, you can have a variable
that is a dict and expand that using eval.
2021-10-25 15:17:04 +02:00
Pierre-Yves Chibon
407bb73a12 Copy the local_vars dictionary to avoid eval modifying it
This avoid having the local_vars dictionary getting filled with
a large number of built-in variable that are of no use for this
dictionary.

This commit was created by from Alexander Larsson.

Signed-off-by: Pierre-Yves Chibon <pingou@pingoured.fr>
2021-09-24 13:32:51 +02:00
Pierre-Yves Chibon
65b98448c6 Add support for defining variables from other variables or basic expression
Using this we can now define variables in the variable section using
basic expression that are evaluated as f-string.
For example, you can use the syntax:

```
"mpp-vars": {
   "rootfs_uuid": {"mpp-format-string": "{__import__('uuid').uuid1()}"},
   "bootfs_uuid": "156f0420-627b-4151-ae6f-fda298097515"
},
```

This will automatically call uuid.uuid1() for rootfs_uuid, thus allowing
to dynamically set the uuid for the rootfs variable.
This variable being able to be overridden via the -D argument of the
osbuild-mpp tool.

In addition, you can also define variable based on variables defined
above, for example:

```
"mpp-vars": {
   "rootfs_size": 4294967296,
   "homefs_size": {"mpp-format-string": "{rootfs_size}"}
},
```

For context, we're in particular interested in this for the uuid
generation, as we have had issues with xfs failing to mount a filesystem
if the uuid is already mounted. In particular, if we built e.g. a
raspberry pi image using osbuild and then we use that raspberry pi for building
the same manifest (typically a later version of it) the osbuild fails in the
loopback mount case. Being able to easily support reproducible fixed-uuid
images, as well as ones with a real unique uuid makes a lot of sense.

This commit was created with a lot of inputs from Alexander Larsson.

Signed-off-by: Pierre-Yves Chibon <pingou@pingoured.fr>
2021-09-24 13:32:51 +02:00
Pierre-Yves Chibon
2d4bc41cfc Fix the assert as .sort() returns None
Since `.sort()` returns None, we were checking that None == None
which is not what we aimed to do.

Quick reproducer:
```
>>> assert [1,2,3].sort() == [2,3,4].sort()
>>> assert sorted([1,2,3]) == sorted([2,3,4])
Traceback (most recent call last):
  File "<input>", line 1, in <module>
    assert sorted([1,2,3]) == sorted([2,3,4])
AssertionError
```

Signed-off-by: Pierre-Yves Chibon <pingou@pingoured.fr>
2021-09-21 16:09:47 +02:00
Christian Kellner
9e599fca17 tools/mpp: expand basurl after dep-solving
We create the urls for the packages after dep-solving. During the
big refactoring (802f4010) the code that would expand the base url
during that step got lost. Re-introduce that so that local repos
work correctly again.
Also make sure the path is absolute before calling `as_uri` since
it is not guranteed that the result will be a `file:///` uri.

Reported-by: Stephen Smoogen <smooge@smoogespace.com>
2021-07-20 13:23:58 +02:00
Christian Kellner
403dd5e2ec tools/lorax-templates-pkg: set executable bit 2021-07-15 23:08:51 +01:00
Christian Kellner
c4db24c481 tools/mpp: substitute vars in mpp blocks
Allow the manifest variables, defined via mpp-vars, to be used from
within the mpp blocks. For this template strings are used, where
variables are marked via `$`. We cannot use the `mpp-format` logic
easily there, since that is processed after other mpp directives
have been processed.
As a result remove the built-in substitution from support from dnf
dep-solving, since we had to post-process the resulting urls with
variable substitution afterwards. Now that is covered with this
more generic mechanism.
2021-07-14 23:51:34 +02:00
Christian Kellner
4a00895ba5 tools/mpp: sort import
Makes David happy, which makes us happy.
2021-07-14 23:51:34 +02:00
Christian Kellner
fd1b688f78 tools/mpp: single mpp node retrieval method
Introduce a helper method that will return the mpp node of a given
name or `None` if it does not exist. Delete it from the parent
dictionary if it did.

Reorder the typing imports as well to be sorted below the non-
`from` imports.
2021-07-14 23:51:34 +02:00
Christian Kellner
fdb0faca86 tools/mpp: extract vars initialization
Move the initialization for manifest vars out of `__init__`.
2021-07-14 23:51:34 +02:00
Christian Kellner
368d0a5c18 tools/mpp: support multiple image definitions
Support more than one image definition by introducing a `id` attribute
which can be used to specify how the variable for the definition is
called.
2021-07-09 19:50:38 +01:00
Christian Kellner
042a3424e4 tools/mpp: support skip_if_unavailable
Add `skip_if_unavailable` as an supported attribute
for the repository configuration.
2021-07-09 19:50:38 +01:00
Christian Kellner
d39e3a239e tools/mpp: support for defining partitions
It is now possible to define a partition layout via `mpp-define-image`.
The defined layout is actually written to a temporary sparse file and
read back via `sfdisk`, so that all partition data like `size` and
`start` include actual padding and such. The `image` variable will be
defined with `size` and `layout` keys, the latter containing the
partition layout data. It can be accessed via the "String expansion"
mechanism.
2021-07-08 22:47:45 +02:00
Christian Kellner
1dc845f331 tools/mpp: properly support substitutions
Previous versions of mpp would already set the arch and basearch
substitution, which would work for dep-solving itself, but not
properly re-write the resulting URLs which means that the manifest
was broken. Fix this by properly replacing the substitutions in
the URL. Also support official 'releasever' substitution.
2021-07-07 15:10:00 +02:00
Christian Kellner
7c9035e48a tools/mpp: set module_platform_id again
This, together with the "ignore-weak-deps" option got lost in the
refactoring. Add it back.
2021-07-07 15:10:00 +02:00
Christian Kellner
d47f735112 tools/mpp: create PkgInfo class for package info
Instead of passing dictionaries around that are inconvenient to
use in code and even more in the `mpp-format-*` directives, use
a simple class to represent package information. Use that in
the `pkginfo` dict that can be accessed via `mpp-format-*`. Use
the `evra` property instead of string manipulation in the
`fedora-boot.mpp.json` and `-ostree-bootiso.mpp.json` manifest.
2021-07-02 11:28:43 +02:00
Christian Kellner
8a27de0d10 tools/osbuild-mpp: include nevra in package list
Include the nevra in the list of dep-solved packages. Use that for the
package info. Adapt the boot manifest accordingly.
2021-07-02 11:28:43 +02:00
Christian Kellner
ff76b6fade tools/osbuild-mpp: small whitespace fixes
Since David is on leave, I have to do them. Also Move the pylint
comment above the line, not next to it.
2021-07-02 11:28:43 +02:00
Christian Kellner
44fec6cd91 tools/mpp: rename mpp.py to osbuild-mpp
Prepare the optional installation of the script via a more unique
and langauge independent name.
2021-07-02 11:28:43 +02:00
Alexander Larsson
53af328b7c mpp: Use the right format for the file secrets
I was getting:

.sources.org.osbuild.curl.items.sha256:02c8f76fd8b13972c541e4fa3bd2101681b7d4baa1320e3101bc4167b5531685:
  {'url': 'https://cdn.redhat.com/content/dist/rhel8/8/aarch64/baseos/os/Packages/e/elfutils-libelf-0.182-3.el8.aarch64.rpm', 'secrets': 'org.osbuild.rhsm'} is not valid under any of the given schemas

Because the secrets key should have an object, not a string value.
2021-07-01 18:15:00 +02:00
Alexander Larsson
bdfef651eb mpp: Set a variable to the set of depsolved rpms
This allows you to format strings based on what will get installed.
A common example here is extracting the kernel version for the
dracut stage.
2021-07-01 15:06:57 +02:00
Alexander Larsson
e541c1c196 mpp: Add support for formating strings
This lets a mpp manifest define some variables and then use
these variables inside python f-strings to expand things in a
flexible way. This allows a single value such as `rootfs_size` to
be expanded in various places, including using computations to
e.g. define the partition offsets/sizes.
2021-07-01 15:06:57 +02:00
Christian Kellner
fbbefa0f48 tools/mpp: remove separate mpp tools
Those got unified in tools/mpp.py, which should be used now instead.
2021-06-30 20:26:07 +01:00
Christian Kellner
3b7320d114 tools/mpp: remove elif after return
Pylint will complain otherwise.
2021-06-30 20:26:07 +01:00
Christian Kellner
1202085883 tools/mpp: move main code into main function
Move all the global code into a `main` function and call that. This
fixes a lot of pylint warnings where variable names were re-used
from the main, and thus global, context.
2021-06-30 20:26:07 +01:00
Christian Kellner
802f401069 tools/mpp: refactor dep-solving
Create a DepSolver class that carries the global state such as dirs
and subscription information, as well as local state, like the 
repositories and basedir. The latter can be reset so the class can
easily be re-used for all dep-solve sections.
This avoids having any global state.
2021-06-30 20:26:07 +01:00
Christian Kellner
77c5c8e8a6 tools/mpp: silence bare-except warning
In that case we don't care what exactly went wrong.
2021-06-30 20:26:07 +01:00
Christian Kellner
f37c83ec25 tools/mpp: raise exception from None
Raise the `ValueError` that is thrown when we are unable to get
the secrets from `None`.
2021-06-30 20:26:07 +01:00
Christian Kellner
c600ea60a4 tools/mpp: don't compare None with ==
Either use `is` or the truth-y-ness directly.
2021-06-30 20:26:07 +01:00
Christian Kellner
bb620d727d tools/mpp: use python3 style super invocation
In Python3 there is no need for arguments in the `super` invocation
itself.
2021-06-30 20:26:07 +01:00
Christian Kellner
fdd757dd28 tools/mpp: sort the source urls
Sort the checksum: urls dictionary via the url, so that no matter
where the urls came from (import or any dep-solve section), the
checksum: url dict is the same for the same set of urls.
2021-06-30 20:26:07 +01:00
Christian Kellner
ec68369daf tools/mpp: support search dirs for manifests
Add support for additional paths that are searched when trying to
load a manifest. Currently only the path of the manifest that has
the include is searched. With this changed additional directories
will be included after that, in the order they were given ton the
command line.
2021-06-30 20:26:07 +01:00
Christian Kellner
2230dfe566 mpp: use simple urls if possible
If no `secrets` is required to download a package we can use the
simple checksum: url mapping, instead of the checksum: {url: }
one.
2021-06-30 20:26:07 +01:00
Christian Kellner
1b4f96c4e7 mpp: unify add package code path
Both v1 and v2 code paths used the same logic to add the resolved
dependencies to the `source_urls` dict, which is already stored
in the base class. Move the logic into the base class too.
2021-06-30 20:26:07 +01:00
Christian Kellner
4add7c69ff mpp: turn comment into doc string 2021-06-30 20:26:07 +01:00
Christian Kellner
3298a6461e mpp: small whitespace fixes
Be PEP-8 complaint.
2021-06-30 20:26:07 +01:00
Alexander Larsson
ab453bf81a mpp: combine depsolve and import into mpp.py
Rewrite image pre-processor to single tool so that it is easier to use.
Now also supports `ignore-weak-deps` when dep-solving and supports
relative paths for local files.
Also create a symlink to the osbuild package, so that the tools can be
run from the source checkout and have access to the osbuild package.
2021-06-30 20:26:07 +01:00
Christian Kellner
a350602a77 tools/mpp: sort urls for v2 manifests
The logic to sort urls was added globally in `mpp-import-pipeline`
but only the in the v1 code path was the `state.manifest_urls`
variable set and thus for v2 the actual sorting did not happen.
Fix this and set the `manifest_urls` to the `org.osbuild.curl`
items, which makes sense because we only know how to sort those.
2021-06-22 21:10:49 +02:00
Christian Kellner
aa00e62fed tools/mpp: sort source urls
In both mpp-depsolve and mpp-import-pipeline, sort the packages to
url dictionary before writing the JSON. This makes it easier to
look for packages but more importantly ensures that the resulting
set of packages has the same ordering in the sources section
independently of how it was assembled.
2021-06-21 18:04:13 +02:00