Commit graph

410 commits

Author SHA1 Message Date
Martin Sehnoutka
8e77e03284 distro: make it impossible to initialize registry with nil values
The current `NewRegistry` implementation allows for nil values in the
map, but this leads to subtle bugs when using the registry. This patch
enforces non-nil values by introducing additional checks before we
insert the value into the map.

The change unfortunately breaks a lot of tests and therefore it is
necessary to create additional mock: distro.

The new mock is used instead of the previous "real" implementation,
which used to contain nil values.
2020-02-19 23:37:45 +01:00
Jacob Kozol
fae51095d2 distro: add fedora 32 support
Images can be built for fedora 32. The pipeline generation and distro
 tests are based off of the fedora 30 ones. Repository information has
 also been added for the fedora 32 repos.
2020-02-19 14:18:58 +01:00
Jacob Kozol
bbbd9b9193 distro: add fedora 31 support
Images can be built for fedora 31. The pipeline generation and distro
tests are based off of the fedora 30 ones. Repository information has
also been added for the fedora 31 repos.
2020-02-18 12:34:17 +01:00
Lars Karlitski
049969911d tools: add prepare-source.sh
A script that runs various go tools (mod tidy, mod vendor, and fmt for
now).

The idea is that it prepares the source to be ready for master. As such,
running it on master shouldn't modify any files. Make sure of that by
adding a test.
2020-02-17 16:09:17 +01:00
Lars Karlitski
6703055925 go: include vendored modules
RHEL requires the source code for dependencies to be included in the
srpm. The spec file already expects that, but we've only included the
vendored modules (i.e., the `vendor` directory) in the `rhel-8.2.`
branch. Move vendoring to master, so that we can build RHEL packages
from it as well.

This commit is the result of running `go mod vendor`, which includes the
vendored sources and updates go.mod and go.sum files.

Fedora requires the opposite: dependencies should not be vendored. The
spec file already ignores the `vendor` directory by default.
2020-02-17 16:09:17 +01:00
Lars Karlitski
4f2ac6a687 tree-wide: format code with gofmt 2020-02-17 16:09:17 +01:00
Ondřej Budai
345cd6a746 compose: fix deep-copying of ImageBuild
I wanted to create a unit test for this method but then I decided not to.
The reason is that if we add another field to ImageBuild but fail to
modify the test it won't catch the bug. I think higher level testing is
needed to cover this function.
2020-02-17 13:44:29 +01:00
Ondřej Budai
94929fdafb compose: drop the image field
I apparently failed to remove it in cc00e0cd probably due to some rebasing
issues.
2020-02-17 13:44:29 +01:00
Jacob Kozol
3d3626287f jobqueue: remove unused compose import
In jobqueue/job internal/compose was imported. This imported is unused
and osbuild-composer fails to build. The import is now removed.
2020-02-14 15:49:33 +01:00
Alexander Todorov
895add8539 Replace local download URL with global mirror URL
which will be resolved to the closes file server
2020-02-14 15:37:24 +01:00
Alexander Todorov
a1c1ba1255 Build osbuild-tests as well 2020-02-14 15:37:24 +01:00
Tom Gundersen
2d675ea51b distro: add a Sources method
This outputs the sources needed for the pipeline generated for the
distro. At the moment no pipelines require sources, and so this
always returns the empty list.

Signed-off-by: Tom Gundersen <teg@jklm.no>
2020-02-14 14:43:27 +01:00
Tom Gundersen
7f97401ef8 osbuild: add RPM stage type
This is the replacement for the DNF stage, containing only GPG
keys and package checksums. It is meant to be used together with
the files source to actually fetch the packages. Depsolving must
be done in composer and the full package list inserted into
the pipeline.

Signed-off-by: Tom Gundersen <teg@jklm.no>
2020-02-14 14:43:27 +01:00
Tom Gundersen
3b774e0e6d osbuild: add source type
This represents the sources objects, for now only org.osbuild.files
is supported.

Signed-off-by: Tom Gundersen <teg@jklm.no>
2020-02-14 14:43:27 +01:00
Tom Gundersen
fefe5db4ce distro/pipeline: take depsolved packages as argument
This is unused for now, but will allow us to generate pipelines with
the pre-depsolved NEVRAs, so osbuild does not need to depsolve again.

Signed-off-by: Tom Gundersen <teg@jklm.no>
2020-02-14 14:43:27 +01:00
Tom Gundersen
59da8b066f osbuild-pipeline: include base and build packages in depsolving
This will detect inconsistent blueprints, and in the future will
allow us to use the returned packages for generating the pipeline.

Signed-off-by: Tom Gundersen <teg@jklm.no>
2020-02-14 14:43:27 +01:00
Tom Gundersen
6d94028976 weldr: include build and base packages in final depsolve
The packag selection shown in the UI does not include the base
packages that will be included in the image, and they cannot,
because the base packages depends on the output type, and the UI
packages shown in the UI are independent of the output type.

It is possible to select packages incompatible with the base
packages. Discover this sooner rather than later, by including
the base packages in the final depsolve before creating the
pipeline.

In the future the result of the depsolve will be used to create
the pipeline, so this is another prerequisite for moving from
the dnf to the rpm stage.

Also depsolve the build packages for the same reason. Note that we
always set clean to false in this case, as the depsolving of the
main packages would have performed any cleaning necessary.

Also extend dnf-json to support excluding packages from depsolving.

Signed-off-by: Tom Gundersen <teg@jklm.no>
2020-02-14 14:43:27 +01:00
Tom Gundersen
cdd1912e78 dnf-json: make independent from the host
We must avoid depending on the host's state in any way. This achieves
isolation in the following ways:
 - rather than the default config file /dev/null is used
 - rather than sharing the host persistent state dir a temporary one
   is used and thrown away for each call
 - the module_platform_id is set explicitly per supported distro, rather
   than taken from /etc/os-release.

Optionally, the cache directory can be configured, as we may want to keep
this separate from the host, if for no other reason than accounting.
However, the cache appears to be well-behaved, so we can keep sharing
it between calls (or even with the host). This speeds up things
considerably, so this is definitely what we want.

Signed-off-by: Tom Gundersen <teg@jklm.no>
2020-02-14 14:43:27 +01:00
Tom Gundersen
b6d9268810 dnf-json: support excluding packages
In our base distro definitions we exclude packages in addition to
including them. Extend dnf-json to support this, so we can depsolve
the base package set as well as the packages added in blueprints.

Signed-off-by: Tom Gundersen <teg@jklm.no>
2020-02-14 14:43:27 +01:00
Tom Gundersen
b4bb73a195 dnf-json: expose each RPM location and content hash
In adition to the NEVRA, include the location and hash over the rpm
file. This allows us to separately fetch and verify that refernces
to RPMs are correct, as the NEVRA alone is not sufficient for fetching
nor verifying.

This is a prerequisite for using the rpm rather than the dnf stage
in our osbuild pipelines.

Signed-off-by: Tom Gundersen <teg@jklm.no>
2020-02-14 14:43:27 +01:00
Tom Gundersen
7f0f6c001e distro: expose BuildPackages
We want to be able to include the build packages when depsolving a
blueprint, so expose the list.

Signed-off-by: Tom Gundersen <teg@jklm.no>
2020-02-14 14:43:27 +01:00
Tom Gundersen
42e8ca19be distro: expose BasePackages
We want to be able to include the base packages when depsolving a
blueprint, so expose the list.

Signed-off-by: Tom Gundersen <teg@jklm.no>
2020-02-14 14:43:27 +01:00
Tom Gundersen
f0f2e80a97 distro: expose the ModulePlatfromID
This is needed for depsolving, so expose it from the distro package
so it can be passed to dnf-json (and not only to osbuild) as that does
depsolving too.

Signed-off-by: Tom Gundersen <teg@jklm.no>
2020-02-14 14:43:27 +01:00
Tom Gundersen
d133454d91 pipeline: rename package to osbuild
Rename the package from `pipeline` to `osbuild` to reflect that it
will no longer be specific to pipelines, but rather covers all
osbuild datatypes.

Signed-off-by: Tom Gundersen <teg@jklm.no>
2020-02-14 14:43:27 +01:00
Ondřej Budai
3ff88c336f fix ineffectual assignments found by golangci-lint 2020-02-14 12:41:09 +01:00
Ondřej Budai
55d3854033 targets/local: drop Location field
When support for osbuild result was added into osbuild-composer it was in
a bit hacky way - localtarget's location was reused as a path for the
result. This didn't make much sense because we want to store the result
even when image build has no localtarget.

Several past commits made store less dependant on the localtarget. The
responsibility for "holding the paths" to build artifacts was gradually
switched from the localtarget to the store while still maintaining
backwards compatibility - localtarget.Location still pointed at the
correct location.

This commit finishes the switch: local target now has no Location field.
The store is now fully responsible for managing the artifacts and paths
to them. LocalTarget is now just a simple "switch" - if image build has it,
then worker uploads an image into the store and it's then available for
download using the weldr API.
2020-02-14 11:53:38 +01:00
Ondřej Budai
6902f730cb worker: upload local target image using jobqueue api
Prior this commit local target copied the image from a worker to a composer
using cp(1) command. This prevented the local target to work on remote
workers.

This commit switches the local target implementation to using the jobqueue
API introduced in the previous commit. I had some concerns about speed
of this solution (imho nothing can beat pure cp(1) implementation) but
ad hoc sanity tests showed the copying of the image using the jobqueue API
when running the worker on the same machine as the composer is still
more or less instant.
2020-02-14 11:53:38 +01:00
Ondřej Budai
98aac91083 api/jobqueue: add route to upload images 2020-02-14 11:53:38 +01:00
Ondřej Budai
08c5eaf6a6 store disk artifacts per image build instead of per compose
In #221 Compose was refactored: Now it can have multiple image builds. More
image builds result in more jobs. Each job has its own result (logs from
osbuild). Additionally, also targets are now a part of image build. With
local target this effectively means we can have multiple images per compose.

However, these artifacts (images & results) were stored only per compose
prior this commit, thus rendering the behaviour of composes with multiple
image builds undefined and racy.

This commit fixes it by storing all the artifacts per image build instead of
per compose. To achieve this feature, getComposeDirectory and
getImageBuildDirectory methods were created to centralize the path assembly.

Paths to artifacts prior this commit:
${COMPOSER_STATE_DIR}/outputs/${COMPOSE_ID}/*

Paths to artifacts after this commit:
${COMPOSER_STATE_DIR}/outputs/${COMPOSE_ID}/${IMAGE_BUILD_ID}/*
2020-02-14 11:53:38 +01:00
Ondřej Budai
b64bbaa0bb api/jobqueue: move build id to url
Imho it makes more sense from REST perspective. Also, in the future there
will be ROUTE for uploading image to image build. As it's not a good idea
transport file inside JSON, all the parameters (compose id and image
build id) need to be inside the URL. Therefore for the sake of consistency,
all these routes should have compose id and image build id in the URL.

There is another solution to embedding multiple values inside http body
which allows file transport - multipart/form-data. I think using form-data
is worth when doing more complex stuff, for our usecase transporting all
the metadata in the URL is more appropriate solution.
2020-02-14 11:53:38 +01:00
Ondřej Budai
188b24e26e api/jobqueue: actually write errors to response body if any occur 2020-02-14 11:53:38 +01:00
Ondřej Budai
cc00e0cdc9 drop the Compose.Image field
Everything that this field contained can be computed in another way:

- path: just lookup the local target and read the path from there
- mime: can be derived from distribution and compose output type
- size: can be derived from the path

Therefore it imho doesn't make much sense to store these information multiple
times.
2020-02-14 11:53:38 +01:00
Ondřej Budai
a9633d29e9 weldr: clean up the image size code
There's no connection between user-specified image size and actual image
size (which might differ du to a compression). Therefore, it's not needed
to check if the actual image exists if we want to return just the
user-specified size.
2020-02-14 11:53:38 +01:00
Jacob Kozol
238d2b562e weldr: add filtering to compose route
When requesting the compose status, a user may want to filter the list
of composes by blueprint name, compose status, and/or compose type. These
filters can now be set in the /compose/status route's url as the queries
blueprint, status, and type.
2020-02-12 19:23:40 +01:00
Jacob Kozol
c312f40d27 weldr/tests: fix indentation of expected aws compose
The Blueprint struct is misaligned, increase its indentation by 4.
2020-02-12 19:23:40 +01:00
Ondřej Budai
3e7a96e5ea api/jobqueue: return 500 error when updating job unexpectedly failed
Prior this commit these errors would just disappear.
2020-02-12 11:18:02 +01:00
Martin Sehnoutka
05b1093170 osbuild-pipeline: use the new types 2020-02-12 11:17:26 +01:00
Martin Sehnoutka
f4f8603db5 osbuild-compose: store now takes a distro registry
previously it took only a single distro, but now it requires the whole
registry
2020-02-12 11:17:26 +01:00
Martin Sehnoutka
edf081153a distro: remove previous implementation of testing distro
See internal/distro/fedoratest for a replacement
2020-02-12 11:17:26 +01:00
Martin Sehnoutka
83afb1f821 target: use the new types from common package 2020-02-12 11:17:26 +01:00
Martin Sehnoutka
ab6b6da76c Weldr API: use the new compose/store API
The compose now contains multiple image builds, but Weldr API does not
support this feature. Use the first image build every time.

Also start using the new types instead of plain strings.
2020-02-12 11:17:26 +01:00
Martin Sehnoutka
962365251d store: refactor compose handling
All the preceding changes in jobqueue, compose package, common types
etc. were a base for refactoring the store so that a compose can handle
multiple image builds. This commit introduces the change in a backwards
compatible way, so that the weldr api don't change.
2020-02-12 11:17:26 +01:00
Martin Sehnoutka
d02bac15fe distro: use the new types in distro packages
Each distro is now represented by a strongly typed value but it can also
provide its name as a string.
2020-02-12 11:17:26 +01:00
Martin Sehnoutka
80e01bb397 jobqueue: include image build id
The compose will soon move to a concept of including multiple image
builds per one compose, we need to accommodate extra identifier to
handle this scenario.
2020-02-12 11:17:26 +01:00
Martin Sehnoutka
73994eb06d distro/fedoratest: create new testing distribution
The problem with the previous one was that we used artifical image
types, architectures, and distribution but that is not possible any more
because we don't want to use plain strings any more. This commit
introduces a new testing distro which uses proper, existing types.
2020-02-12 11:17:26 +01:00
Martin Sehnoutka
eb6c0f6fce compose: refactor compose related structure into its own package
The store package is getting too big and convoluted, this new package
will help with separation of the compose logic from our current
implementation of the store.

The current implementation will be removed in following commits.
2020-02-12 11:17:26 +01:00
Martin Sehnoutka
62d186cd1b common: refactor build states into a separate file
These states will be used for tracking the image builds and compose
states in the rest of our codebase. There should be no change in the
behavior. It is a 1 to 1 replacement with the only difference of using
type alias instead of plain string.
2020-02-12 11:17:26 +01:00
Martin Sehnoutka
9c91b12076 common: compose request should include full bp and repositories
we want to move to a state where composer is a stateless service,
therefore we cannot take blueprints by name (and fetch them from a
storage) or assume repositories by the distribution. This commit
introduces both of these parameters as part of the structure.
2020-02-12 11:17:26 +01:00
Martin Sehnoutka
cffa74f0a1 common: extend common types with helper functions
It is very common that a string is required in the rest of our code and
also for user input/output. These helper functions will make this easy.
2020-02-12 11:17:26 +01:00
Martin Sehnoutka
7f66147888 RCM API: return bad request instead of internal server error
push compose returns nil in case of any error, until we can
differentiate between internal server error and bad request, just return
bad request
2020-02-12 11:17:26 +01:00