Commit graph

695 commits

Author SHA1 Message Date
Brian C. Lane
dfb69dc8e7 golangci-lint: The parameters passed to exec.Command are safe
None of these parameters are user controlled, they are either
constructed from paths or are constants.
2022-09-15 03:57:40 -07:00
Achilleas Koutsou
8e24f5720d osbuild-composer-cli-tests: new weldr-client compatibility
The newest weldr-client (35.6) changed its responses to always be
arrays/lists of json objects.  The tests have been updated to parse this
structure as well.

The current workflow for parsing responses from the weldr-client is as
follows:
- If weldr-client is installed on the system:
    - Try to parse the newest structure version: array of objects, each
      with a body field.
    - If that fails, initialise the first element of the array and parse
      the response into it.
- If the weldr-client is not installed, initialise the array with one
  element and parse the response into the body field of the first
  element of the array.
2022-09-13 16:06:19 +01:00
Lukas Zapletal
b03a131f13 dbjobqueue: use background context when closing listener 2022-09-02 12:52:50 +02:00
Brian C. Lane
c32f94d6f2 weldr: Preload metadata at startup
For each of the supported distros start a goroutine to depsolve
'filesystem' which will preload the metadata making subsequent responses
faster.

This is safe to do without limits because we only supposed a limited
number of distros, and without additional locking because this is the
the same as hitting the API with multiple depsolve requests at the same
time.
2022-08-31 12:18:51 +01:00
Sanne Raymaekers
0fe3f1b2ae jobqueue: Query job dependents 2022-08-30 16:14:52 +02:00
Sanne Raymaekers
099b34b301 worker: Define new jobs to handle copying and resharing of images
The copy job copies from one region to another. It does not preserve the
sharing on the ami and it's snapshot, that needs to be queued
separately.
2022-08-30 16:14:52 +02:00
Achilleas Koutsou
7bf0277175 gen-manifests: don't fail on invalid distro-arch-image combos
When the user specifies any of the distro, arch, or image type values to
filter generation, invalid combinations would cause a panic, which made
it hard to filter requests based just on an image type.
Instead of failing, print an error message to inform the user, but
continue with the rest of the jobs.
This way, a user is informed that a certain combination is invalid if
they make a mistake, but can also filter on a single image type and only
get valid manifests out of the run.
2022-08-29 13:58:43 +02:00
Tomas Hozza
af65baa6fe worker/osbuild: use os-release to determine host OS
When running an osbuild job, we read `/etc/redhat-release` to get the
host OS name to attach as metadata to the job result.

Only Fedora and RHEL ship this file, which makes the osbuild job always
fail on other distributions.

The main reason to report host OS back to the worker server is due to
Koji composes and the koji-finalize job, which pushes it to Koji. The
motivation is to have enough information to potentially re-instantiate
/ identify the original builder host OS. There are no specific
requirements on the string.

Modify the code to use `/etc/os-release` to determine the host OS. Fall
back to using `linux` as the host OS, in case reading `os-release`
fails, log the error and continue with the job. The `linux` fallback is
suggested by the `os-release` spec [1]

[1] https://www.freedesktop.org/software/systemd/man/os-release.html#ID=

Co-authored-by: Achilleas Koutsou <achilleas@koutsou.net>
2022-08-25 08:25:35 +01:00
Brian C. Lane
3c0fa94c69 mock-dnf-json: Add support for search command
The search response from mocks/dnfjson is a map of responses indexed by the
comma-separated list of packages and globs being requested. Add support
for this.
2022-08-23 22:47:46 +01:00
Tomas Hozza
24c52c8d69 osbuild-mock-openid-provider: support client_credentials grant type
Extend the implementation of mock openid server to take the `grant_type`
into consideration for the `/token` endpoint.

In addition to the previously supported `refresh_topen`, the
implementation now supports also `client_credentials`.

This is necessary to make it possible to use the mock server in
the `koji-osbuild` CI, because the builder plugin uses
`client_credentials` to get access token.

The implementation behaves in the following way:
 - For `refresh_token` grant type, it takes the `refresh_token` value
   from the request and adds it to the `rh-org-id` field in the custom
   claim, which is part of the returned token.
 - For `client_credentials` grant type, it takes the `client_secret`
   value from the request and adds it to the `rh-org-id` field in the
   custom claim, which is part of the returned token.

Requests without the supported `grant_type` set are rejected.

Modify affected test cases to specify `grant_type` when fetching a new
access token.
2022-08-05 16:15:24 +02:00
Ygal Blum
07c1f3b2f8 worker: fix crash if no autoscale instance is defined
The worker assumes that when running on AWS an autoscale is defined.
If not defined, the worker crashes
2022-08-04 11:26:42 +02:00
Sanne Raymaekers
111feda1f5 worker: Remove ellipsis operator from clienterrors.Error
The ellipsis operator was used as a hack to not need to pass any details
as an argument, but it makes what the end object will actually look like
less obvious. It also makes it impossible to pass an array to details
without getting a nested array.

Fixes #2874
2022-08-03 13:51:52 +02:00
Ygal Blum
1847a6ae05 tests/api: add container related test
Add a new cloud API test that will build an edge-container,
upload it to the gitlab CI registry, fetch it from there,
run it and compare that the OSTree commit contained in it
is indeed the one we expect.

Co-Developed-By: Christian Kellner <christian@kellner.me>
2022-08-01 21:50:03 +01:00
Christian Kellner
c845a11881 job/osbuild: better logging for container uploads
Add some more logging to the container uploads, which is esp.
helpful in the case something goes wrong.
2022-08-01 21:50:03 +01:00
Ygal Blum
9f8df4313c job/osbuild: set AuthFilePath for container upload if provided
If a `AuthFilePath` was configured, which should contain secrets
to access container registries, we set this on the `Client` so
that the secrets can be used during registry access.
2022-08-01 21:50:03 +01:00
Ygal Blum
64a3aac895 job/osbuild: move utility the container package
Extract a helper method that parses the reference and applies
defaults, i.e. registry and path, and move it to the contaier
package.
2022-08-01 21:50:03 +01:00
Ygal Blum
3231aabbc0 cloudapi: add support for uploading to a container registry
Worker
------
Add configuration for the default container registry.
Use the default container registry if not provided as part
of the image name.
When using the default registry use the configured values
Return the image url as part of the result.

Composer Worker API
-------------------
Add `ContainerTargetResultOptions` to return the image url

Composer API
------------
Add UploadOptions to allow setting of the image name and tag
Add UploadStatus to return the url of the uploaded image

Co-Developed-By: Christian Kellner <christian@kellner.me>
2022-08-01 21:50:03 +01:00
Sanne Raymaekers
fa18206918 osbuild-service-maintenance: Rely on the db's timezone in tests
Avoid calculating the new expire date on the test host, because
differences in timezones can yield unexpected failures.
2022-08-01 10:59:05 +02:00
Sanne Raymaekers
69d4429e8f osbuild-service-maintenance: Honor dryrun in db cleanup 2022-08-01 10:59:05 +02:00
Sanne Raymaekers
2eaad3701d osbuild-service-maintenance: Reword log messages and query name
The query is deleting multiple jobs, and it's deleting the entire job,
not just the results.
2022-08-01 10:59:05 +02:00
Sanne Raymaekers
c78c69b273 osbuild-service-maintenance: Run vacuum analyze after each delete 2022-07-28 16:53:55 +02:00
Achilleas Koutsou
2afc8fd1dd gen-manifests: minor output changes
Don't print "Worker started" message.
Print "done" after submitting all jobs to the queue.
2022-07-25 21:23:02 +02:00
Achilleas Koutsou
b20605d9f1 gen-manifests: append message to failed jobs on finish
When the 'Finished' message is printed, append [failed] to the message
if the job encountered an error.
2022-07-25 21:23:02 +02:00
Achilleas Koutsou
20b6d3866a gen-manifests: support arch, distro, image type selection
Multiple values can be specified by separating with commas.
2022-07-25 21:23:02 +02:00
Achilleas Koutsou
a018c69f90 gen-manifests: simplify flag definitions
Remove the reliance on flag variable pointers and read the argument
values directly into the target variables.
2022-07-25 21:23:02 +02:00
Achilleas Koutsou
d61b553045 gen-manifests: don't print progress when nothing changed
Update the progress line only when another line was received, which in
this case means a job has started or finished.
No need to keep reprinting the progress.
2022-07-25 21:23:02 +02:00
Achilleas Koutsou
6e4a55cf9e gen-manifests: print errors on stderr 2022-07-25 21:23:02 +02:00
Christian Kellner
78a96a5414 worker: support for configuring the containers auth file
Add a new configuration section for containers and an option
to configure the authfile in it.
2022-07-25 21:21:44 +02:00
Christian Kellner
50e630a76f worker: add new container resolve job type
This is a new job that can be used to resolve containers. It uses
the existing `container.Resolver` class to do the actual work.
2022-07-25 21:21:44 +02:00
Christian Kellner
2c0594629f osbuild: add extraEnv argument to RunOSBuild
This adds the ability to supply extra environment variables to
the osbuild process.
2022-07-25 21:21:44 +02:00
Tomas Hozza
0614913010 worker/koji-finalize: fix error message 2022-07-24 08:40:58 +02:00
Tom Gundersen
5a15608c89 image: add image kind abstraction
This abstracts away the manifest instantiation. The idea is that we define one
of these image kind types to represent a group of image types that are
sufficiently similar. Each image kind will have a struct with with all the
properties that can be customised for the image and a function to turn that into
an actual manifest. This is similar to how distro/fedora/manifest.go and
cmd/osbuild-playground works today, and aspires to move these closer together
and to eventually make the distro definitions simpler.

For now cmd/osbuild-playground is moved over to using the new abstraction.
2022-07-22 16:04:07 +02:00
Tom Gundersen
5c5c63afd1 manifest/os: split out OSCustomizations
This is meant to encapsulate the tweaks we do to the OS tree
orthogonally to anything else. For now it still contains some
configuration that only sometimes applies, but this should
continue being reworked until all the fields in this struct
always apply to any artefact that is using it.

At the same time, stop instantiating with default values, as the
empty values should work. This is not a functional change as the
caller always sets these now.
2022-07-22 16:04:07 +02:00
Tomas Hozza
2ff34767cc worker/osbuild: workaround cloud upload for compressed images
The AWS and Azure RHUI images are produced as compressed archives, which
can be uploaded to Koji, but they can't be uploaded to the cloud
provider in this format. To support cloud upload for these types of
images, we need to decompress them before the upload.

Add a workaround for AWS and AzureImage targets to check if the image
has `.xz` suffix and if yes, decompress it before uploading to cloud.

This workaround is needed until image definitions will support and use
multiple exports per image to allow using different export per upload
target.
2022-07-22 11:39:49 +01:00
Tomas Hozza
77a1672b79 worker/koji-finalize: handle multiple upload targets
Enhance the `koji-finalize` job implementation to be able to cope with
multiple upload targets being specified for an `OSBuildJob`.

Implement a convenience method `OSBuildJobResult.TargetResultsByName()`
for filtering the target results attached to the job result by their
name. Cover the method with an unit test. And lastly use this method in
the `koji-finalize` job to find the appropriate Koji upload target
results.

This is a preparation for enabling cloud uploads for Koji composes.
2022-07-22 11:39:49 +01:00
Tomas Hozza
58696e849f worker/koji-finalize: always report status back to composer and Koji
Enhance the `koji-finalize` job implementation to use deferred function
to ensure that the job status is always reported back to the composer.
In addition, if the `JobError` is set, also fail the Koji job.

Previously, composer and Koji were not updated in some corner cases when
the job would fail.
2022-07-22 11:39:49 +01:00
Christian Kellner
5f8358ee46 cmd/gen-manifests: support container embedding
Add support for resolving container via `container.Resolver`.
2022-07-21 13:32:07 +02:00
Christian Kellner
a24cc16bb0 cmd/osbuild-pipeline: resolve blueprint container
Add support for resolving containers via `container.Resolver`.
2022-07-21 13:32:07 +02:00
Christian Kellner
fbd6d804f0 blueprint: add support for containers
Add a new `containers` section that can be used to request the
embedding of containers into images. The only requirement is
the source property to specify where to fetch the container from.
This suppports specifying the digest of the container or the tag.
In case none is given it defaults to the `latest` tag. The `Name`
field can be used to optionally specify a name to use inside the
image.
NB: currently no tools or apis support container resolution yet.
This follows in the next commits.
2022-07-21 13:32:07 +02:00
Christian Kellner
7f3f016ed1 distro: add containers arg to ImageType.Manifest
This is the first step to support embedding container images. Here
we add the `containers []container.Spec` argument to supply images
with resolved container specifications. For now all distros will
return an error in case a container is actually supplied since none
of them currently support embedding containers. NB: also no apis or
tools will actually resolve containers.
2022-07-21 13:32:07 +02:00
Christian Kellner
e53b9c8bb2 container/client: rework credentials storage
Instead of keeping an extra field in `Client`, we just use the
existing `sysCtx.DockerAuthConfig` structure. When the context
is later copied during the upload operation the credentials
will be copied as well. It also saves us from syncing the
credentials if we directly use said `sysCtx` for operations.
2022-07-21 13:32:07 +02:00
Christian Kellner
865a899f70 container/client: rework tls settings
Instead of having an extra field, `TlsVerify`, on the `Client` and
then later setting the corresponding `SystemContext` options, use
the existing `SystemContext` field of `Client`. The corresponding
field is a tri-state: unset, true, false, which is represented as
a pointer to boolean in the `Client`'s new getter and setter. This
also inverts the boolean logic from verify TLS to skip TLS which
aligns very well with the corresponding fields in the upload target
struct.
In addition we properly capitalize some existing variables.
2022-07-21 13:32:07 +02:00
Ondřej Budai
e779562f3c worker: remove osbuild-koji job
Koji API removed by the previous commit was the last user of osbuild-koji job.
Let's remove it since nothing uses it. This also removes all of the
compatibility code in Cloud API, see concerns below:

Compatibility concerns:
- the internal deployment was moved to a completely different composer
  instance, thus there are no old jobs
- Fedora deployment is still unused in prod, thus we don't care about keeping
  backward compatibility of the old jobs

Signed-off-by: Ondřej Budai <ondrej@budai.cz>
2022-07-19 16:00:52 +02:00
Ondřej Budai
74eb3860df internal: remove kojiapi
We no longer use it, let's remove it. If you are wondering what to use instead,
use Cloud API. It supports everything that Koji API supported and more.

Signed-off-by: Ondřej Budai <ondrej@budai.cz>
2022-07-19 16:00:52 +02:00
Achilleas Koutsou
9d4a351ca6 Rename osbuild2 package to osbuild 2022-07-14 16:54:00 +02:00
Simon de Vlieger
78ae275c61 jobqueue: store an expiry date
This introduces an expiry date (default: 14 days from insert date) and
adjust the service-maintenance script to delete jobs that are older than
the expiration date.
2022-07-13 17:26:04 +02:00
Achilleas Koutsou
2eb9833370 osbuild-image-tests: ignore LVM UUID
Unconditionally ignore the UUID of the LVM container.  We don't control
this value so it isn't stable and makes our image tests fail.
2022-07-12 13:28:36 +02:00
Tom Gundersen
e844453c85 manifest: make filename optional and generalise Tree
We have three kinds of operating system trees, until we unify them to one,
hide them behind one interface. Use this to read the architecture from the
Tree rather than pass it in as a string to parent pipelines.

Also, make the filename parameter optional in a few places, there should be no
reason to set this rather than introspect it (except for backwards
compatibility).

Lastly, add another playground example sample to build a raw image.
2022-07-12 08:19:57 +01:00
Tom Gundersen
d00b98c134 manifest: don't stutter
Replace `pipeline.OSPipeline` with `pipeline.OS`, etc.

Also rename `LiveImg` to `RawImage`.
2022-07-12 08:19:57 +01:00
Tom Gundersen
529bc803db runner: introduce runner abstraction
For now all it does is represent the name of the runner and what requirements
it has of the build pipeline.

Move some package definitions from the runner package set to where it belongs.
2022-07-12 08:19:57 +01:00