Commit graph

93 commits

Author SHA1 Message Date
David Rheinsberg
2d6d902428 tree: pep8 + linter fixes
For some reasons I forgot to fix those in the previous runs. Fix a
linter and pep8 warning.

Signed-off-by: David Rheinsberg <david.rheinsberg@gmail.com>
2022-09-23 12:08:10 +02:00
David Rheinsberg
a65cf82b5e osbuild-mpp: fix pylint warnings
Fix a bunch of pylint warnings about coding-style. Nothing really major.

Signed-off-by: David Rheinsberg <david.rheinsberg@gmail.com>
2022-09-13 17:41:27 +02:00
David Rheinsberg
73ad1a3eac osbuild-mpp: avoid symbol shadowing
Avoid using `os` or `input` as symbol names, since they shadow
previously defined symbols.

Signed-off-by: David Rheinsberg <david.rheinsberg@gmail.com>
2022-09-13 17:41:27 +02:00
David Rheinsberg
0f49ed9f98 osbuild-mpp: implement virtual functions
Make sure to correctly implement virtual functions and raise
NotImplementedError, as suggested by the standard library. Pylint will
otherwise complain about unavailable functions being accessed.

Signed-off-by: David Rheinsberg <david.rheinsberg@gmail.com>
2022-09-13 17:41:27 +02:00
David Rheinsberg
0471c646a8 osbuild-mpp: fix YAMLError.problem accessors
The `problem` member is only defined if a problem-mark is present. If
the mark is not set, we get no details on the error whatsoever and have
to just print a generic error message.

Signed-off-by: David Rheinsberg <david.rheinsberg@gmail.com>
2022-09-13 17:41:27 +02:00
David Rheinsberg
8c6049f197 osbuild-mpp: fix PartitionTable.__getitem__() bail-out
The __getitem__() function incorrectly returns `None` if the
partition-type is not found. Make sure to always return IndexError if
the requested value is outside the supported range.

Signed-off-by: David Rheinsberg <david.rheinsberg@gmail.com>
2022-09-13 17:41:27 +02:00
Simon de Vlieger
ea6085fae6 osbuild: run isort on all files 2022-09-12 13:32:51 +02:00
Ygal Blum
42552e0436 osbuild-mpp: Add url option to mpp-embed
Allow the user to pass a URL to be embeded as org.osbuild.curl input

Signed-off-by: Ygal Blum <ygal.blum@gmail.com>
2022-09-06 14:28:06 +03:00
Alexander Larsson
7c0f0c1052 osbuild-mpp: Add comment detailing the stage formating 2022-08-08 14:21:13 +02:00
Alexander Larsson
24e48d2f71 osbuild-mpp: Use empty string for pipeline name if missing
This matches what we did before last commit.
2022-08-08 14:21:13 +02:00
Alexander Larsson
fc2697927a osbuild-mpp: Allow use of mpp-* operations for stages
This mergest the handling of process_stages() and process_format() into
just one process_format(), which incrementally tracks the call stack
of the formating, which allows it to detect when it is hitting a stage
and can call _process_stage().

This means it is possible to mix things like mpp-if and mpp-join with
stages.

For example, you can do complex combinations like:

pipelines:
- name: rootfs
  stages:
    mpp-join:
      - - type: org.ostree.foo
        - mpp-if: use_bar
          then:
            type: org.osbuild.bar
      - mpp-if: use_extra_stages
        then:
          mpp-eval: extra_stages

This is particularly useful if you included something and you want
to mpp-join something that was set in a variable.
2022-08-08 14:21:13 +02:00
Alexander Larsson
ed99aa4bfa osbuild-mpp: Store solver_factory in manifest
We do this instead of passing it around to simplify the APIs so
we don't have to track it. This will help for later changes.
2022-08-08 14:21:13 +02:00
Christian Kellner
219d7469cb osbuild-mpp: small python cleanups
Remove an unused variable and annotate static methods as such.
2022-06-27 10:22:25 +02:00
Jakub Rusz
62f2bf608c tools: add set-env-variables.sh
Very simple script to set env variables.
2022-04-13 14:57:27 +02:00
Alexander Larsson
dbaed75b46 osbuild-mpp: Support mpp-resolve-image for container images 2022-02-10 14:43:17 +01:00
Alexander Larsson
66cc2900c9 obuild-mpp: Add process_stage() helper
Both file embedding and depsolves start by iterating over all stages,
and we want to add another similar one for container installs, so
break out the iteration over the containers so that it is done in
one place only.
2022-02-10 14:43:17 +01:00
Achilleas Koutsou
bef387848f osbuild-mpp: Add support for a pacman resolver
This introduces a new dependency resolver to osbuild-mpp for Arch Linux
which uses the pacman package manager. The used solver is determined by
the `solver` field in the `mpp-depsolve` object inside the manifest
file, if it does not exists it falls back to the DepSolver for dnf/rpm.

Co-Authored-By: Jelle van der Waa <jvanderwaa@redhat.com>
2021-12-15 23:22:15 +01:00
Jelle van der Waa
76c1b5cf25 osbuild-mpp: ConstructorError was undefined
ConstructorError is part of the yaml.constructor module.
2021-12-02 17:33:46 +01:00
Jelle van der Waa
03af8c632a osbuild-mpp: Apply autopep8
Make the code confirm to PEP8.
2021-12-02 17:33:46 +01:00
Alexander Larsson
eefc52333e osbuild-mpp: Allow mpp-define-image nodes to use formating
We just process the formats after removing the mpp node, just like
we do in e.g. mpp-depsolv.
2021-11-26 11:51:42 +00:00
Alexander Larsson
4901e97236 osbuild-mpp: Allow included files to define partitions too 2021-11-26 11:51:42 +00:00
Alexander Larsson
ba8bc3a60a osbuild-mpp: Support nested includes
This moves the handling of includes to the manifest loader, thus
supporting nested includes. search_dirs is moved to a property of the
Manifest so that it can be tracked during loads.

In addition we need to fix Manifest.path to the actual path that was
loaded instead of whatever the parent include said, so that relative
includes are handled from the proper location of the loaded manifest.
2021-11-26 11:51:42 +00:00
Alexander Larsson
12335f9e5f osbuild-mpp: Be more careful about keys existing
In process_embed_files(), it assumed that a stage had a "type" field,
which breaks if a stage is e.g. a `mpp-if` node, so use .get() instead
of raw dict lookups.
2021-11-26 11:51:42 +00:00
Alexander Larsson
bfa619f1a2 osbuild-mpp: Fix default value for ManifestV2.pipelines
This should be [], not {}. This  was probably from copying the V1
value which is {} (for `pipeline`).
2021-11-26 11:51:42 +00:00
Alexander Larsson
29ecb1df67 osbuild-mpp: Support mpp-pipelines to include all or a subset of the pipelines
This makes a lot of sense, as some include could be built in a way the
includer doesn't know about that requires sub-pipelines.
2021-11-26 11:51:42 +00:00
Alexander Larsson
52c3cb12ba osbuild-mpp: Support loading yaml as well as json files
yaml files are essentially compatible with json files, although
they have some advantages, like allowing comments and being easier
for humans to read/write.

This changes the reading of the file to use a yaml parser instead of
a json parser, but still produces json at the end. I tried manually
converting a json file to yaml and running osbuild-mpp, and it produced
an identical file.

By default the yaml parser doesn't respect order so i had to tweak
the loader a bit to use OrderedDict.
2021-11-19 13:35:12 +01:00
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