Commit graph

220 commits

Author SHA1 Message Date
Tomáš Hozza
43e87632fb Drop common.CurrentArch() in favor of osbuild/images
Drop `common.CurrentArch()` implementation and use
`arch.Current().String()` from the osbuild/images instead.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2024-01-26 11:32:34 +01:00
Tomáš Hozza
625b1578fa Port osbuild/images v0.33.0 with dot-notation to composer
Update the osbuild/images to the version which introduces "dot notation"
for distro release versions.

 - Replace all uses of distroregistry by distrofactory.
 - Delete local version of reporegistry and use the one from the
   osbuild/images.
 - Weldr: unify `createWeldrAPI()` and `createWeldrAPI2()` into a single
   `createTestWeldrAPI()` function`.
 - store/fixture: rework fixtures to allow overriding the host distro
   name and host architecture name. A cleanup function to restore the
   host distro and arch names is always part of the fixture struct.
 - Delete `distro_mock` package, since it is no longer used.
 - Bump the required version of osbuild to 98, because the OSCAP
   customization is using the 'compress_results' stage option, which is
   not available in older versions of osbuild.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2024-01-26 11:32:34 +01:00
Sanne Raymaekers
e24772dc57 worker/server: check if worker is available for architecture 2023-12-14 21:25:32 +01:00
Sanne Raymaekers
850e44589b worker/server: split out jobqueue call from PostWorker handler 2023-12-14 21:25:32 +01:00
Sanne Raymaekers
ac854b7cc8 pkg/jobqueue: add arch to worker 2023-12-14 21:25:32 +01:00
Tomáš Hozza
1afe7d20c8 Adjust code to new version of osbuild/images
Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2023-12-06 17:32:18 +01:00
Sanne Raymaekers
fd4a3a941a worker: let client register itself with the worker server
Sends a status update to the worker server every 5 minutes.

Also fixes a bug where the body the worker client sent would be empty if
it had to refresh the JWT token. Instead of io.Reader use io.ReadSeeker
so the body can be reread to create the second request (after the token
refresh).
2023-12-06 17:22:36 +01:00
Sanne Raymaekers
794acd8e34 worker: add ability to track workers serverside
Unresponsive workers (>=1 hour of no status update) are cleaned up.

Several things are enabled by keeping track of workers, in future the
worker server could:
- keep track of how many workers are active
- see if a worker for a specific architecture is available
2023-12-06 17:22:36 +01:00
Tomáš Hozza
b41705adfb Delete unused internal/platform package
This is a leftover from the `osbuild/images` split`.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2023-10-20 18:59:00 +02:00
Sanne Raymaekers
64e9f1a2c7 worker: don't log job not pending dequeue errors
This happens a lot when requesting a job by ID, which happens for the
manifest jobs.
2023-10-02 23:37:26 +01:00
Tomáš Hozza
cca362678b Worker/osbuild: include osbuild version in OSBuildJobResult
This will make it easier to reproduce image builds using the same
tooling which was used by the worker.

This change will enable to include the osbuild version in Koji build
metadata.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2023-09-27 12:39:28 +02:00
Tomáš Hozza
3c95ba8476 Include osbuild/images version in Manifest job result
Include the osbuild/images module version in the Manifest job result.
The module has direct impact on image definitions and the content of
produced manifest, therefore including this information in the Manifest
job result is very helpful for various purposes (debugging,
traceability).

This will enable to embed this information in the Koji build metadata.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2023-09-27 12:39:28 +02:00
Tomáš Hozza
8866391d88 Include osbuild-composer version in Manifest job result
Extend the Manifest job result structure to hold information about
osbuild-composer version, which produced the manifest. This will be
useful for other job types which depend on it and can then push this
information further as needed.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2023-09-27 12:39:28 +02:00
Tomáš Hozza
4f51d44762 Worker/koji-finalize: add cloud target results to image/build metadata
Add any non-Koji upload target results attached to an OSBuild result, to
the image extra metadata. This will make it easy to locate any image
from Koji uploaded to cloud, in the target cloud environment.

The rationale behind including only non-Koji target results is that one
can find it only in Koji, so there is no added value in including the
Koji target results at all.

Extend the `koji.sh` to check the target results in image metadata when
testing Koji scenario with cloud upload.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2023-09-27 12:39:28 +02:00
Tomáš Hozza
efbaa93eef Target/Koji: rework result options to contain more than just image info
The `KojiTargetResultOptions` previously contained information only
about the uploaded image file. And even then, some information, such as
the filename, were scattered in other structures such as
`KojiFinalizeJob` struct.

Since the plan is to start uploading also osbuild manifest and osbuild
build log to Koji, we need to extend the result options structure to
hold more information and also make it specific to which file is the
information related.

Rework the `KojiTargetResultOptions` to contain information about:
 - the built image
 - build log
 - osbuild manifest

Information about each file contains:
 - filename
 - checksum type
 - file checksum
 - file size

For now, only the built image information is set and consumed by the
worker.

Add custom JSON (un)marshaler for `KojiTargetResultOptions` to handle
backward compatibility when old version of worker or composer server
interact with each other. Cover them with unit tests.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2023-09-27 12:39:28 +02:00
Sanne Raymaekers
067366ed6a internal/target: add OCI object storage target
Uploads an OCI image to OCI object storage, and generates a
pre-authenticated request for the object, which can be used to import it
into custom images.
2023-09-19 22:57:06 +02:00
Ondřej Budai
d6eacad494 jobimpl-osbuild: report a failed job on panic
Previously, the worker would happily report success if osbuild succeeded,
there was no JobError, but the job actually panicked in the meantime.
Let's fix this by adding a recovery mechanism.

Signed-off-by: Ondřej Budai <ondrej@budai.cz>
2023-09-01 13:23:25 +02:00
Tomáš Hozza
5fd5cedd08 OSBuildJob: add image boot mode to options and result
Add the information about the image boot mode to the OSBuildJob options
as well as to the OSBuildJobResult options. The intention is that the
worker will simply copy the value from the job options to job result,
so that the `KojiFinalize` job can then access this information and
upload it to Koji as extra metadata.

This information is required in Koji in order for Red Hat's SP tooling
to know how to import image to the cloud environment in case the boot
mode affects the import parameters.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2023-08-08 15:53:07 +02:00
Achilleas Koutsou
0e4a9e586f split: replace internal packages with images library
Remove all the internal package that are now in the
github.com/osbuild/images package and vendor it.

A new function in internal/blueprint/ converts from an osbuild-composer
blueprint to an images blueprint.  This is necessary for keeping the
blueprint implementation in both packages.  In the future, the images
package will change the blueprint (and most likely rename it) and it
will only be part of the osbuild-composer internals and interface.  The
Convert() function will be responsible for converting the blueprint into
the new configuration object.
2023-07-10 21:11:19 +02:00
Sanne Raymaekers
6040c10e10 worker/v1: rearrange middlewares
The duration middleware should come after the tenant channel middleware,
otherwise the tenant in the context will be empty. The status middleware
can come beforehand because it queries the request context right before
sending a response.
2023-06-29 16:41:36 +02:00
Sanne Raymaekers
2837b2a3ad prometheus: split off request timing information into separate mw
Tracks the worker api in addition to the composer api.
2023-06-28 15:08:37 +02:00
Sanne Raymaekers
9594156baf internal/worker: use TenantChannelMiddleware 2023-06-28 15:08:37 +02:00
Achilleas Koutsou
8e5ac9790e worker: update ostree job structs
Change the OSTreeResolveSpec to match the ostree SourceSpec by removing
the Parent field.

Change OSTreeResolveResultSpec to match the CommitSpec by adding the
Secrets field.  The RHSM field is kept for backwards compatibility with
older workers.
2023-06-14 11:19:29 +02:00
Achilleas Koutsou
68ccc58706 Adapt tests to new test_distro
The new test_distro's manifest produces a slightly different empty
manifest when serialized even without content.  Cloud API and Koji tests
have been adapted to match.

Weldr tests have been updated in several ways:
- The test_distro content resolver is used to resolve manifest content
  before serializing.
- The test scenarios in TestCompose have been named for easier
  troubleshooting (easier to identify a failing test by name).
- Manifests that work with the secondary ostree repo (the "other") use
  the appropriate URL and ref and create a secondary "other" serialized
  manifest.

The weldr API's test flag for resolving ostree commits does not produce
the same, fixed hash every time but instead computes a sha256 from the
URL + ref, like we do in the test manifests.
2023-06-14 11:19:29 +02:00
Achilleas Koutsou
89a398371d manifest: add resolved commit specs to Serialize()
Same as with package specs and container specs, the commit specs are
added to the manifest serialization after being resolved.
2023-06-14 11:19:29 +02:00
Achilleas Koutsou
3b1d48ec99 distro: remove packageSpecSets and containers from Manifest() args
The arguments aren't used in the function anymore.
2023-05-31 16:40:07 +02:00
Achilleas Koutsou
267a27a1a8 manifest: container specs added during serialization
Add a second argument, map[string][]container.Spec, during
serialization, which serves the same purpose as the depsolved package
sets.
2023-05-31 16:40:07 +02:00
Achilleas Koutsou
12e8ab3ac6 Make Manifest() return manifest.Manifest
Return manifest.Manifest from the Manifest() function without
serializing.  The caller then has to call the manifest.Serialize()
function using the depsolved packages.

This moves towards changing the order of actions required to generate a
manifest.  With this change, the manifest creation and depsolving can be
done independently, but this still requires instantiating the manifest
object twice (InstantiateManifest() is called in PackageSets() and
Manifest()), which we don't want to have to do.
2023-05-31 16:40:07 +02:00
Achilleas Koutsou
c7aecdf31c distro: delete distro.Manifest type
Delete the distro.Manifest type and its tests.
Change all occurrences of distro.Manifest to manifest.OSBuildManifest.
2023-05-31 16:40:07 +02:00
Achilleas Koutsou
8f69088af1 distro: remove architecture names and use platform enum
Removing the dependence of the manifest package on the distro package to
import manifest into distro.
Wherever arch names are needed, we use the enums from the platform
package instead.
2023-05-31 16:40:07 +02:00
Gianluca Zuccarelli
4d42808b6a internal/rpmmd: RepoConfig baseurl change
Update the internal RepoConfig object to
accept a slice of baseurls rather than a
single field. This change was needed to
align RepoConfig with the dnf spec [1].

Additionally, this change adds custom json
marshal and unmarshal functions to ensure
backwards compatibility with older workers.
Add json tags to the internal rpmmd config
since this is serialized in dnfjson.
Add unit tests to check the serialization
is okay.

[1] See dnf.config
2023-04-21 17:40:00 +02:00
Achilleas Koutsou
a7dd8ff94f container: add ListDigest to the spec
Add the ListDigest to the container Spec struct and all its copies so we
can store list digests when they are available and pass them on to the
appropriate osbuild stages, sources, and inputs.

Copy the value whenever a spec is moved to a different representation.
2023-04-17 18:30:41 +02:00
Sanne Raymaekers
9dc0881247 internal/worker: log dequeue failures 2023-04-14 12:12:41 +02:00
Irene Diez
8022c227ba distro: allow to return warnings in the Manifest function
This changes the `Manifest` function of the `ImageType`
interface so that any warnings detected during the
`checkOptions` step of the manifest initialization can
be propagated back to the Weldr-API (see next commit).

Signed-off-by: Irene Diez <idiez@redhat.com>
2023-03-31 14:14:57 +02:00
Gianluca Zuccarelli
c056db4811 worker/server: add file resolver job
Add a file resolver job to the worker server in
order for us to resolve the contents of a remote
file.
2023-03-16 09:55:39 +00:00
Gianluca Zuccarelli
98d611d34f worker/server: fix container resolver job error
The container job resolve job error message was printing
the wrong error type to the error string.
2023-03-16 09:55:39 +00:00
Gianluca Zuccarelli
b493da1878 internal/clienterrors: add file resolution error
Add a client error type for an error in the remote
file resolution job.
2023-03-16 09:55:39 +00:00
Sanne Raymaekers
a25e0f4adb prometheus:: add arch label to dequeue metrics
Only add the arch label for osbuild job types, as the finish metrics
behave similarly. Having arch labels on dequeue metrics for any other
job type (but not on the finish metrics) would produce weird results.
2023-03-09 18:47:57 +01:00
Sanne Raymaekers
96b42b5791 internal/worker: add String to clienterrors.Error struct
This should make the logging better when errors have another error
struct.

Fixes #3272
2023-02-16 00:55:34 +01:00
Gianluca Zuccarelli
08aa1e99a1 worker/server: log unresponsive job removal
Re-add the logging for when unresponsive heartbeats
are being removed so we can verify that they
are correctly being logged as 5xx errors.
2023-01-10 09:29:33 +01:00
Gianluca Zuccarelli
113cda7d39 internal/worker: register status middleware
Register the custom middleware function to the worker
server. This function is responsible for recording all
the status codes of all the server's endpoints.

Due to a bug with echo/v4, a request to an endpoint using
the incorrect method should return a `405` error but returns
a `404` error instead when a middleware function is registered.
The worker `server_test` has been updated to reflect this.
2022-11-30 11:14:29 +01:00
Tom Gundersen
626530818d worker/server: requeue unresponsive jobs
If a job is unresponsive the worker has most likely crashed or been shut
down and the in-progress job been lost.

Instead of failing these jobs, requeue them up to two times. Once a job is lost
a third time it fails. This avoids infinite loops.

This is implemented by extending FinishJob to RequeuOrFinish job. It takes a
max number of requeues as an argument, and if that is 0, it has the same
behavior as FinishJob used to have.

If the maximum number of requeues has not yet been reached, then the running
job is returned to pending state to be picked up again.
2022-11-02 15:26:00 +01:00
Sanne Raymaekers
e94ea7c995 internal/worker: add rhsm to ostree resolve job 2022-10-28 16:14:30 +02:00
Sanne Raymaekers
ebeb339f96 osbuild-worker: add ostree resolve job
This job resolves an ostree ref. Similar to the depsolve and container
resolve jobs, this should be a dependency of a manifest job.
2022-10-19 18:14:10 +02:00
Sanne Raymaekers
599829a3b8 worker: Return dependent jobs in OsbuildJobStatus 2022-08-30 16:14:52 +02: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
Christian Kellner
388154d7f6 cloudapi: support container embedding
Add support for embedding container images via the cloud API. For
this the container resolve job was plumbed into the cloud api's
handler and the API specification updated with a new `containers`
section that mimics the blueprint section with the same name.
2022-08-04 14:37:12 +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
Gianluca Zuccarelli
e5d9d2d045 worker/server: rename JobStatus() to JobInfo()
Since the `jobStatus` functions return a `JobInfo`
struct that contains the `JobStatus`, it makes sense
to rename the function names for the sake of consistency.
2022-07-27 13:37:14 +02:00