Commit graph

233 commits

Author SHA1 Message Date
Tom Gundersen
ac5f69e757 osbuild: move result serialization from common
In the same way `osbuild.Manifest` is the input to the osbuild API,
`osbuild.Result` is the output. Move it to the `osbuild` package where
it belongs.

This is not a functional change.

Signed-off-by: Tom Gundersen <teg@jklm.no>
2020-08-26 12:12:37 +02:00
Tom Gundersen
b0cd29f78b worker: support returning returning images as StreamOptimized
vCenter requires images to be uploaded as vmdk StreamOptimized. Lorax
always produced images on this format, so we should make sure to do the
same for our VMWare images.

Allow LocalTarget to request the images produced by osbuild be converted
to be streamOptimized before saving in composer, and hook the weldr API
up to enable this option for vmdk images.

Ideally this should simply be an option in osbuild, but that would
require some more work, which we will not manage in time for RHEL8.3.
Therefore do this minimal fix.

Note that that means the images produced by our manifests (including in
our image-test test cases) are not on the format that the weldr API
returns, so the tests we run on them would also, for now, need to
convert before uploading to vCenter.

Signed-off-by: Tom Gundersen <teg@jklm.no>
2020-08-23 14:45:27 +02:00
Tom Gundersen
a2f8a06e79 weldr/upload: don't expose AWS/Azure acconut details
Change the translation from our internal structs to the structs used for
weldr serialization to drop account details. These must obviously be
passed in to configure an upload, but exposing them in the logs may be
surprising.

There is no notion of user accounts in the weldr API, and the state
should not be considered private. However, this is likely to take people
by surprise, so let us guard the secrets entrusted to us.

Fixes #907.

Signed-off-by: Tom Gundersen <teg@jklm.no>
2020-08-18 08:55:57 +02:00
Major Hayden
5d7aa2f699 Add friendly message for logs on running build
Improve the message returned by osbuild-composer when a user asks for
logs of a compose that is still running.

Signed-off-by: Major Hayden <major@redhat.com>
2020-08-17 09:10:50 +02:00
Brian C. Lane
be2ce10b75 weldr: Fix out of range index for missing toml blueprint freeze
The API was crashing if the freeze request was called on a non-existent
blueprint. This changes it to return an empty string, matching
lorax-composer's behavior (since the output is toml it shouldn't return
json).
2020-08-05 11:43:35 +02:00
Brian C. Lane
eb76b9ec8e weldr: Fix the bad blueprint depsolve response
This changes the response to match lorax-composer's behavior. If any of
the blueprints in the list passed to /blueprints/depsolve/... have an
error that error should be appended to the error list, and the blueprint
included in the blueprints list with an empty dependencies section.

It was returning an error 400 and a single error if it hit any depsolve
problems, skipping any other blueprints and returning the wrong
response.

This also adjusts the tests to account for the change.

Fixes #890
2020-07-28 08:18:56 +02:00
Ondřej Budai
b4a57225a7 api/weldr: add missing modtime to tar returned by /compose/logs
This file was surely not created on 1970-01-01, this commit sets the ModTime
to the current datetime.
2020-07-15 08:58:25 +01:00
Ondřej Budai
454e471af8 api/weldr: bring tars back from the future
By default, go's tar archiver uses USTAR header format. Unfortunately, this
format doesn't support sub-second resolution for ModTime. Go solves this by
*rounding* the time. Sometimes, this creates an archive containing a file
with modtime from the future. When such archive is untarred by GNU tar,
the following message is produced:

tar: bf548dfd-0a90-40e6-bbf2-dcdd82fcbb4e.json: time stamp 2020-07-13
13:34:31 is 0.356223173 s in the future

We have two options here:

1) Use gnu header format that supports sub-second resolution. Unfortunately,
   it seems that not all tar archivers support this format (e.g. 7-zip).

2) The other option is to truncate the date (instead of rounding).

I went with option 2.

Also, this commit adds a test to check that the header is not from the future.
Without this fix, the test is actually failing, I verified this manually.

Fixes #854
2020-07-15 08:58:25 +01:00
Tom Gundersen
50d469fe45 distro: replace BasePackages() with Packages()
Rather than getting a set of base packages from the ImageType, and then
appending the requested packages from the blueprint, pass the blueprint
into the new Packages() function, and return the full set of packages to
be depsolved.

This allows us to also append packages based on other customizations
too, and use that to append chrony when the timezone is set. This
matches the behavior anaconda had, and there was a TODO item to do this,
which had been overlooked.

Fixes #787.

Signed-off-by: Tom Gundersen <teg@jklm.no>
2020-06-29 16:04:38 +02:00
Lars Karlitski
be10efeb1e weldr: implement cancel route 2020-06-12 10:00:50 +02:00
Tom Gundersen
6a7e57ce8d rpmmd: allow check_gpg to be configured for system repos
The sources weldr API already supports this, so hook it up to be
represented on disk and in our internal state tracking too.

This does not yet hook this up to be respected by osbuild, which
currently takes this to be unconditionally set to true.

Signed-off-by: Tom Gundersen <teg@jklm.no>
2020-06-10 19:25:54 +02:00
Ondřej Budai
3913f419e2 weldr: drop getPkgNameGlob method
Not used anywhere! :-)
2020-06-10 17:40:30 +02:00
Ondřej Budai
0796342fa1 weldr/api: get the package list for depsolving in a better way
blueprint.GetPackages() method was used to depsolve blueprints prior the
dnf-to-rpm switch. However, it got dropped during the switch. This commit
makes weldr use it again.

The nice effect of this change is that we can drop getPkgNameGlob function and
have only one function for getting package name-versions from a blueprint.

Also, blueprint.GetPackages() works better with * version. Previously, we had
issues with composer depsolving bash of version * to both x86_64 and i686
versions of bash package. GetPackages() converts the package to name-version
of just bash, which dnf-json correctly depsolves to just one architecture. On
the contrary, the previous method converted bash to name-version bash-*.*.*,
which confused dnf-json.

Note that conversion to bash-* is also wrong because this will cause dnf-json
to install all packages with prefix "bash-*".
2020-06-10 17:40:30 +02:00
Ondřej Budai
d65057e164 weldr: add support for toml format in /blueprints/freeze
This is needed for lorax parity. When multiple blueprints are being frozen in
toml mode, the API returns an error. This is the same behaviour as in the
/blueprints/info route.

Fixes #667
2020-06-05 13:51:04 +02:00
Ondřej Budai
14a3f2a9d3 weldr: move projects and modules routes towards lorax parity
lorax-composer returns more information about projects and modules. They are
all meaningless, but we need them for parity.

Fixes #664
2020-06-05 10:01:32 +02:00
Brian C. Lane
e37b513560 weldr: Add check for deleting system sources
It was passing it through to the non-system delete function
and not returning an error. This checks for system repos first and
returns a 400, SystemSource error response if it is in the system list.
2020-06-03 21:24:47 +02:00
Brian C. Lane
37258803b4 weldr: Add support for the v1 API to /projects/source/delete
This changes store.DeleteSource to DeleteSourceByName for v0 use and
DeleteSourceByID for v1 usage.

It includes a new client function DeleteSourceV1, adds a new test, and
converts the tests for the previous Source V1 API commits to use
DeleteSourceV1.
2020-06-03 21:24:47 +02:00
Brian C. Lane
982d292a96 weldr: Update projects/source/info to support API v1
This commit changes the store.GetAllSources to distinguish between
getting the source by the Name field, or by the ID (the key to the map)
using GetAllSourcesByName and ...ByID.

SourceConfig.RepoConfig() now takes an id parameter because SourceConfig
only stores the Name, not the ID.

In weldr I split the sourceInfoHandler into 2 separate functions for v0
and v1 behavior, with the core of the old function refactored as
getSourceConfigs and used by both of them.

This also adds new structs for the SourceResponseV0 and SourceResponseV1
as well as helper functions for converting to/from store.SourceConfig
2020-06-03 21:24:47 +02:00
Brian C. Lane
ddd2010815 weldr: Add support for the v1 API to /projects/source/new
This commit changes the store.PushSource function to take the key as
well as the SourceConfig so that it can be used for v0 or v1.

It adds helper functions for decoding the toml/json into a new
SourceConfig interface type which lets the core source/new code be
shared between the versions.

It also adds tests for the new API behavior.
2020-06-03 21:24:47 +02:00
Brian C. Lane
55325a8549 weldr: Add API v1 support to source listing
This is the first patch in a series to add APIv1 support to the
/projects/source routes. The change involves using the store.Sources key
in a different way (as an id instead of as a duplicate of the struct's
Name field) but does not actually involve changing the Sources json in
the store.

In the V0 API the name of the source was used as the identifier, and
there was no short id. In V1 the source is identified by the API using
a short id, and the Name is just a field in the struct to describe the
source. This will become more obvious with the /projects/source/info
response.

This commit changes the following:

Changes store.ListSources to ListSourcesByName and explicitly pulls the
name from the source struct instead of the key. v0 will use this
function call.

Adds store.ListSourcesById which returns the source key as the
identifier. This is used by v1.

Adds a new weldr.SourcesListV1 response type, even though it is exactly
the same as the V1 response in this specific case. I thought it would be
better to have one called V1 than to reuse the V0 struct and possibly
confuse people.

The /projects/source/list API now lists the sources by name for v0 and id for v1.

A test has been added. You will notice it still uses v0 to push and
delete the sources. These will be updated when the new version of the
functions are added in subsequent commits.
2020-06-03 21:24:47 +02:00
Lars Karlitski
347d69b734 weldr: use compose status for targets as well
Workers don't report status for the osbuild run and the upload targets
separately. Before the move to the jobqueue, we explicitly set the
status of all targets when a compose finished. When I removed that,
the image status broke.

Set the status from what's returned by api.getComposeStatus() to restore
the original behavior.

Fixes #702
2020-06-03 11:49:20 +02:00
Tom Gundersen
0417c6d8bb distro: make the osbuild package internal to the distros
Rather than Manifest() returning an osbuild.Manifest object, introduce a
new distro.Manifest object which represents it as an opaque, JSON
serializable object. This new type has the following properties:

1) its serialization is compatible with the input to osbuild,
2) any valid osbuild input can be deserialized into it, and
3) marshalling and unmarshaling to and from JSON is lossless.

This means that even as we change the subset of valid osbulid manifests
that we support, we can still load any previous state from disk, and it
will continue to work just as before, even though we can no longer
deserialize it into our internal notion of osbuild.Manifest.

This fixes the underlying problem of which #685 was a symptom.

Signed-off-by: Tom Gundersen <teg@jklm.no>
2020-06-03 00:30:01 +02:00
Tom Gundersen
4aced4e749 store/ImageBuild: make Manifest a required property
Any valid ImageBuild must contain a Manifest, so don't allow this to be
nil, simplifying the code a bit in the process.

Signed-off-by: Tom Gundersen <teg@jklm.no>
2020-06-03 00:30:01 +02:00
Brian C. Lane
6b5ab26072 tests: Add unit tests for compose/metadata and compose/results 2020-05-28 00:39:10 +02:00
Brian C. Lane
b07735e2a8 weldr: Add compose/results repsonse
This returns a tar of the metadata json, the logs, and the image if the
compose was successful.
2020-05-28 00:39:10 +02:00
Brian C. Lane
0598be6b9a weldr: Add compose/metadata support
This will return a tar of the compose's json metadata. Inside the tar
the file is named UUID.json
2020-05-28 00:39:10 +02:00
Tom Gundersen
48079b3a4d rpmmd/RepoConf: rename Id to Name
This is how it is used in the rest of the code, as a name to represent
the repository in the weldr API. Rename to match its use, and avoid
confusion with the ID passed to dnf-json, which is not the same.

Signed-off-by: Tom Gundersen <teg@jklm.no>
2020-05-28 00:23:54 +02:00
Lars Karlitski
e06076ed8c worker: add JobArtifact() and DeleteJobArtifacts()
This allows removing the `artifactsDir` from `weldr.API`. It makes more
sense to deal with that directory in one place only.
2020-05-27 16:16:05 +02:00
Lars Karlitski
a1cf3984dc worker: introduce job artifact directory
The `jobs/:job_id/builds/:build_id/image` route was awkward: the
`:jobid` was actually weldr's compose id and `:build_id` was always `0`.

Change it to `jobs/:job_id/artifacts/:name`, where `:job_id` is now a
job id, and `:name` is the name of the artifact to upload. In the
future, it could support uploading more than one artifact.

This allows removing outputs from `store`, which is now back to being a
pure JSON-store. Take care that `weldr` returns (and deletes) images
from the new (or for backwards compatibility, the old) location.

The `org.osbuild.local` target continues to exist as a marker for the
worker to know whether it should upload artifacts.
2020-05-26 10:42:20 +02:00
Tom Gundersen
8f7a9b3439 weldr/compose: add support for ostree-specific options
Similarly to how some image types accept a size-argument, some image
types require  ostree-specific options. For now this is only used by
Fedora IoT on Fedora 32.

composer-cli nor cockpit-composer currently has the ability to pass in
these options, but the change is backwards compatible and existing image
types are unaffected. If the options are omitted for image types that
require them, sensible defaults are chosen.

Signed-off-by: Tom Gundersen <teg@jklm.no>
2020-05-25 22:37:29 +02:00
Tom Gundersen
0b3702cb19 distro/Manifest: generalize the size argument
When generating an osbuild manifest for an image type, we take a
customizations struct, which specifies the image-type-independent
customizations to apply. We also take the size argument, which is
specific to the image build and not part of the blueprint.

Introduce a new argument ImageOptions, which for now just wraps the size
argument. These options are specific to the image build/type, and
therefore does not belong with the other customizations.

For now this is a non-functional change, but follow-up commits will
introduce more types of image options.

Signed-off-by: Tom Gundersen <teg@jklm.no>
2020-05-25 22:37:29 +02:00
Lars Karlitski
8e0dd790b7 weldr: messages → msgs in status route
composer-cli expects `msgs`, not `messages`, and throws an exception if
it doesn't exist:

    https://github.com/weldr/lorax/blob/master/src/composer/cli/status.py#L52

It is not used anywhere else, so this is a safe change.
2020-05-25 16:20:47 +02:00
Ondřej Budai
d4c083ee9a api/weldr: fix the missing logs
The store-jobqueue split broke the retrieval of logs in weldr API. Weldr API
still retrieved the logs from store but they are now stored in the jobqueue.
This commit fixes that by taking advantage of the fact that getComposeStatus()
now returns the compose result from which the logs can be generated.
2020-05-19 22:20:20 +02:00
Ondřej Budai
3b6bc69c37 api/weldr: propagate the ComposeResult to ComposeStatus
When a job doesn't exist for a compose, just return an empty result.
In the future this will cause logs disappear from jobs created before the
store-jobqueue split but we decided we can live with that, they are still
in /var for those who really want them.
2020-05-19 22:20:20 +02:00
Ondřej Budai
65c7b78d4e api/weldr: make composeToComposeEntry() take composeStatus
This makes all the calls to composeToComposeEntry() method slightly easier
to read.

Not a functional change.
2020-05-19 22:20:20 +02:00
Ondřej Budai
5806e3ea08 api/weldr: make getComposeStatus() return composeStatus struct
The reasoning is the same as in one of the previous commits. I think that
returning multiple values from one method can be confusing and potentially
error-prone. Also, this method will return ComposeResult soon too.

Also, I chose to create a new composeStatus struct instead of reusing
worker.JobStatus. I think that's a good thing in terms of consistency and
reducing the dependencies between packages.

Not a functional change.
2020-05-19 22:20:20 +02:00
Ondřej Budai
fffec5fc38 api/weldr: getComposeState() -> getComposeStatus()
State is just one of the returned values, this will make more sense when
composeStatus struct is introduced.

Not a functional change.
2020-05-19 22:20:20 +02:00
Ondřej Budai
fa5b775718 worker/server: make JobStatus() return JobStatus struct
Personally, I don't like methods returning too much values. I think it's
easy to assign the values in an incorrect order and thus interpreting them
in a wrong way. Also, the following commits will make JobStatus() return
also the JobResult, which would make the number of returned values even
higher.

Not a functional change.
2020-05-19 22:20:20 +02:00
Tom Gundersen
fba2af5f51 store: drop support for multi-image composes
The store only serves the weldr API, and that hard-codes the assumption
of only one image build per compose all over the place. Move this
assumption into the json serialization handler.

Signed-off-by: Tom Gundersen <teg@jklm.no>
2020-05-18 11:50:15 +02:00
Tom Gundersen
1fd3b9d543 weldr/ComposeEntry: marshal to strings rather than common.ImageType
This ended up being marshalled to the wrong strings, causing errors
in the queue display in cockpit-composer. This continues our effort
to keep plain strings in the JSON structs and resolve them separately
from marshal/unmarshal.

Signed-off-by: Tom Gundersen <teg@jklm.no>
2020-05-18 11:50:15 +02:00
Tom Gundersen
2fe4450620 store/compose/ImageType: use distro.ImageType objects
This reduces the amount of resolving and error checking we have to do.
This exposed a bug in weldr's ComposeEntry type, which will be fixed in
a follow-up commit.

Signed-off-by: Tom Gundersen <teg@jklm.no>
2020-05-18 11:50:15 +02:00
Tom Gundersen
5ba7e21a72 store/compose: rename 'Id' to 'ID' to make linter happy
Signed-off-by: Tom Gundersen <teg@jklm.no>
2020-05-18 11:50:15 +02:00
Tom Gundersen
df7a0fec22 store: merge the compose package into the store
The types exposed by the compose package are only used in the store API,
so move them there where they belong.

Making the ownership of the types clear, rather than having them live in
a package for themselves, will make it clearer how the types can be
modified in follow-up commits.

Also remove the JSON annotations, as these types are no longer used for
serialization.

Signed-off-by: Tom Gundersen <teg@jklm.no>
2020-05-18 11:50:15 +02:00
Tom Gundersen
4c4bad5444 weldr/api_test: don't access what should be private Store fields
In a follow-up these will be made private.

Signed-off-by: Tom Gundersen <teg@jklm.no>
2020-05-18 11:50:15 +02:00
Tom Gundersen
dc794a6d31 blueprint: DeepCopy() cannot fail
Don't return an error value, as it is always nil.

Signed-off-by: Tom Gundersen <teg@jklm.no>
2020-05-18 11:50:15 +02:00
Brian C. Lane
369312989f blueprints: Fix handling of invalid blueprint names in the API code
Empty names are not allowed, and blueprint names should only contain
characters matching: ^[a-zA-Z0-9._-]+$

This also adds tests for the various places where the blueprint name
could potentially be wrong.
2020-05-13 20:00:52 +02:00
Lars Karlitski
b5769add2c store: move queue out of the store
The store is responsible for two things: user state and the compose queue. This
is problematic, because the rcm API has slightly different semantics from weldr
and only used the queue part of the store. Also, the store is simply too
complex.

This commit splits the queue part out, using the new jobqueue package in both
the weldr and the rcm package. The queue is saved to a new directory `queue/`.

The weldr package now also has access to a worker server to enqueue and list
jobs. Its store continues to track composes, but the `QueueStatus` for each
compose (and image build) is deprecated. The field in `ImageBuild` is kept for
backwards compatibility for composes which finished before this change, but a
lot of code dealing with it in package compose is dropped.

store.PushCompose() is degraded to storing a new compose. It should probably be
renamed in the future. store.PopJob() is removed.

Job ids are now independent of compose ids. Because of that, the local
target gains ComposeId and ImageBuildId fields, because a worker cannot
infer those from a job anymore. This also necessitates a change in the
worker API: the job routes are changed to expect that instead of a
(compose id, image build id) pair. The route that accepts built images
keeps that pair, because it reports the image back to weldr.

worker.Server() now interacts with a job queue instead of the store. It gains
public functions that allow enqueuing an osbuild job and getting its status,
because only it knows about the specific argument and result types in the job
queue (OSBuildJob and OSBuildJobResult). One oddity remains: it needs to report
an uploaded image to weldr. Do this with a function that's passed in for now,
so that the dependency to the store can be dropped completely.

The rcm API drops its dependencies to package blueprint and store, because it
too interacts only with the worker server now.

Fixes #342
2020-05-08 14:53:00 +02:00
Lars Karlitski
9968358c49 weldr: remove stale comment 2020-05-08 14:53:00 +02:00
Lars Karlitski
37b42d452b store: make PushCompose() take a manifest
Code that's calling PushCompose() had to depsolve packages and fetch the
right ImageType from a distro, but not create the osbuild manifest. That
was left for PushCompose to do. Move it out of there to the callers, so
that the store is mainly concerned with storing things.

This also simplifies the argument list of PushCompose().
2020-05-08 14:53:00 +02:00
Lars Karlitski
d74a63f4f2 weldr: inline composesToComposeEntries
This function had two modes (`uuids == nil` and `uuids != nil`). Instead
of splitting it up into one function for each mode, inline it at call
sites. It was only used three times.
2020-05-08 14:53:00 +02:00