Commit graph

46 commits

Author SHA1 Message Date
Achilleas Koutsou
b3d1e4cf13 Makefile: bump GOLANGCI_LINT_VERSION to v1.61
v1.60 seems to have some issues [1] with something in our dependency
chain.  Update to v1.61 and fix all new issues.

New issues are all instances of potential integer overflow from int ->
uint conversions.  Added guards where appropriate and disabled the check
when when it's not needed.

[1] https://github.com/osbuild/osbuild-composer/actions/runs/16624417387/job/47037518471
2025-07-31 12:34:24 +02:00
Tomáš Hozza
3e3f9a0789 Many: move to koji upload implementation from osbuild/images
Delete the `internal/upload/koji` package and replace it with
`pkg/upload/koji` package provided by `osbuild/images`.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2025-07-14 17:20:02 +02:00
Tomáš Hozza
651946ae54 upload/koji: don't depend on upload target osbuild artifact structure
Modify the Koji image extra metadata to not depend on the upload target
data structure for the OSBuild Artifact. This is the last dependency on
the internal osbuild-composer package, allowing the move of the Koji
upload code to the osbuild/images repository.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2025-07-09 22:51:53 +02:00
Tomáš Hozza
2ceffb3796 upload/koji: don't depend on upload target results data structures
Modify the Koji image extra metadata to not depend on the upload target
data structures for upload results. The target results are supposed to
be specific to the uploader implementation, which will eventually
change. Moreover, the definition is internal to osbuild-composer, so
this would create a problem once the Koji upload implementation is moved
to osbuild/images.

The Koji upload implementation does not really care about the exact
structure of the upload results. It is just a list of JSON objects.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2025-07-09 22:51:53 +02:00
Tomáš Hozza
0bafc0915d upload/koji: don't depend on rpmmd.RPM for build metadata
The use of rpmmd.RPM is exclusive to the Koji upload implementation.
Consolidate the metadata structure for RPMs into the koji package
codebase, together with any required functions for converting osbuild
stage metadata. The respective code in osbuild/images will be eventually
removed.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2025-07-09 22:51:53 +02:00
Tomáš Hozza
ca1e1dce36 Many: factor out logger implementation from upload/koji
The upload/koji package functions were creating a logger and then were
using it. This is not ideal for a library implementation.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2025-07-09 22:51:53 +02:00
Brian C. Lane
0256e09031 lint: Clean up golangci-lint v1.60 complaints
This cleans up the linting results by adding checks for
integer underflow/overflow in several places, suppressing the error in
places where it has been checked, or fixing the types when possible.
2025-02-24 04:20:42 -08:00
Tomáš Hozza
1c7462b275 Worker/koji-finalize: import uploaded SBOM documents
If the Koji target result contains information about any uploaded SBOM
documents, import them to Koji as part of the finalize task.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2024-09-20 17:02:09 +02:00
Michael Vogt
573b349f16 clienterrors: rename WorkerClientError to clienterrors.New
The usual convention to create new object is to prefix `New*` so
this commit renames the `WorkerClientError`. Initially I thought
it would be `NewWorkerClientError()` but looking at the package
prefix it seems unneeded, i.e. `clienterrors.New()` already
provides enough context it seems and it's the only error we
construct.

We could consider renaming it to `clienterror` (singular) too
but that could be a followup.

I would also like to make `clienterror.Error` implement the
`error` interface but that should be a followup to make this
(mechanical) rename trivial to review.
2024-07-31 17:04:58 +02:00
Tomáš Hozza
f6e0e99391 Worker/koji-finalize: include osbuild version in image metadata
Include the osbuild version used to build the image, in the image extra
metadata attached to the Koji build and image output.

Extend `koji.sh` to verify that the version is set and of the expected
value.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2023-09-27 12:39:28 +02:00
Tomáš Hozza
dcb66db5e7 Worker/koji-finalize: set the actual osbuild version in buildroot info
Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2023-09-27 12:39:28 +02:00
Tomáš Hozza
95169111de Worker/koji-finalize: include manifest metadata in the build metadata
Expose the extra metadata attached to each manifest output, also to the
build extra metadata under `osbuild_manifest` property. The value is a
map of all manifest metadata with keys being the filename of each
manifest.

This will expose the information about osbuild-composer and
osbuild/images versions used to produce the manifest in the Koji
buildinfo, including the Web UI.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2023-09-27 12:39:28 +02:00
Tomáš Hozza
c27cf0253d Worker/koji-finalize: include composer and deps version in manifest MD
Include the osbuild-composer and its dependencies versions in the extra
metadata associated with the Manifest output when importing it to Koji.

This will make it possible to pin-point the exact version combination
which was used to generate the osbuild manifest used to built the image
imported to Koji.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2023-09-27 12:39:28 +02:00
Tomáš Hozza
e63472ef44 Koji: expose osbuild artifact information in image metadata
Expose the osbuild information used to produce the image, in the image
extra metadata under the `osbuild_artifact` property.

This information will get included in the image / build extra metadata
and make it explicit how to reproduce the image build using osbuild and
the attached manifest.

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
e0ec3a2a1c Worker/koji-finalize: import osbuild manifest and log to Koji build
Import osbuild manifest and build log to the Koji build as outputs. Also
note the respective filenames in the image output extra metadata.

Note that the osbuild manifest is imported as a log file for now. Koji
has very limited set of output types defined and I still need to
determine the best way to use a custom output type in Koji instances (as
other content generators do).

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2023-09-27 12:39:28 +02:00
Tomáš Hozza
70e125bd5e Worker/koji-finalize: rename buildArgs -> buildResult
Rename the variable to make it easily tell what it does at the first
glance. Previous name made it look as if it held build (job?) arguments,
which was not the case.

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
Tomáš Hozza
27f98ec313 Target/koji: mark optional fields in BuildOutput as omitempty
Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2023-09-27 12:39:28 +02:00
Tomáš Hozza
4ac6a7a11d Koji: expose boot mode in image extra metadata
Also extend the Koji test case to verify that the boot mode information
is in the build extra metadata and that it contains valid value.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2023-08-08 15:53:07 +02:00
Tomáš Hozza
af1c373407 Koji: expose image output metadata in build extra metadata
Expose the extra metadata information for each image output stored in
`ImageExtraInfo` also in the build extra metadata. The extra metadata
for each image is nested under key corresponding to the image filename.

Extend the Koji test case to check information in the buildinfo output
and specifically check for all expected metadata in the build Extra
metadata field.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2023-08-08 15:53:07 +02:00
Tomáš Hozza
350762497f Koji: refactor and consolidate structures
The original Koji implementation expected that the output of a content
generator is only an image. While in reality, we will eventually upload
other types of files as outputs to Koji, such as logs and osbuild
manifest.

Rename Koji structures and their members to better map to the upstream
Koji documentation and their JSON representation. Add comments to
structures. Define type aliases and constants for string values which
are more like enums, than a free-form values.

These changes have no effect on the actual JSON representation of any of
the structures

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
Ondřej Budai
972da81a91 worker: fix reporting the import error to composer
The result variable wasn't used at all, kojiFinalizeJobResult is what actually
reports the error.

Signed-off-by: Ondřej Budai <ondrej@budai.cz>
2022-12-01 20:59:30 +01: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
Tomas Hozza
0614913010 worker/koji-finalize: fix error message 2022-07-24 08:40:58 +02: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
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
Achilleas Koutsou
9d4a351ca6 Rename osbuild2 package to osbuild 2022-07-14 16:54:00 +02:00
Ondřej Budai
3fcb737243 worker/koji-finalize: fix result options casting
It's actually a pointer, this caused a panic before, let's fix it.

Signed-off-by: Ondřej Budai <ondrej@budai.cz>
2022-06-29 16:44:10 +02:00
Ondřej Budai
e4a66b0373 worker: clean up the RelaxTimeoutFactor
This commit moves the field to the koji struct where it actually belongs.
Also, it renames it to relax_timeout_factor for the sake of consistency.

Signed-off-by: Ondřej Budai <ondrej@budai.cz>
2022-06-28 15:55:31 +01:00
Ondřej Budai
3b32480d45 worker: factor out kojiServer struct
In order to match the config structure.

Signed-off-by: Ondřej Budai <ondrej@budai.cz>
2022-06-28 15:55:31 +01:00
Tomas Hozza
cc1ff1ee1b worker/koji-finalize: handle both osbuild and osbuild-koji results
Adjust the `koji-finalize` job implementation to be able to handle
results from both the `osbuild` and `osbuild-koji` jobs.

In case of `osbuild` job, the result is of type
`worker.OSBuildJobResult` and the important values are stored in the
Koji upload target options. For now assume that there may be only a
single upload target results.

In case of `osbuild-koji` job, the result is of type
`worker.OSBuildKojiJobResult` and the important values are already part
of the structure. Add "Old" suffix to all functions handling this case.
2022-06-10 14:48:18 +01:00
Tomas Hozza
8e6826e743 Move OSBuildMetadataToRPMs and PackageMetadataToSignature to osbuild2
Move `OSBuildMetadataToRPMs()` and `PackageMetadataToSignature()`
functions from the `rpmmd` package to `osbuild2` package to prevent
import cycles while de-duplicating `rpmStageInputs()` function from
`stage_inputs.go` of distro definitions.

Rename `PackageMetadataToSignature()` to
`RPMPackageMetadataToSignature()`, since it takes specifically
`RPMPackageMetadata` type as an argument.

Adjust affected parts of code (unit tests, cloudapi, worker).

Signed-off-by: Tomas Hozza <thozza@redhat.com>
2022-02-18 09:26:35 +01:00
Diaa Sami
c1ae5b0881 Relax TCP timeouts for koji connections
See COMPOSER-1354 and linked tickets
2022-02-10 14:58:10 +01:00
Christian Kellner
da1537dee6 worker: check field exists before accessing it
Before accessing a field of the `OSBuildOutput`, which itself is a
field of the `osbuildKojiResults` struct, check if it is actually
is set (non-nill), otherwise dereferencing it will crash the
worker.
The field will be null if osbuild has not been invoked at all or
if osbuild crashed or refused to accept the input.
2022-02-01 20:28:40 +00:00
Gianluca Zuccarelli
cc981b887a osbuild-worker: implement structured errors
Implement the structured errors as defined by the worker client.
Every error for each of the job types now returns a structured
error with a reason and a specific error code.  This will make
it possible to differentiate between 4xx errors and 5xx errors.

This commit refactors the way errors are implemented in the workers,
but maintains backwards compatability in composer by checking for
both kinds of errors.
2022-01-27 16:45:14 +01:00
Diaa Sami
b599245284 internal/worker: Use logrus for logging 2021-12-16 11:58:41 +00:00
Juan Abia
ceb72975c4 gosec: G402 - TLS MinVersion
stablish minumim TLS version, so G402 from gosec doesn't get triggered
2021-12-13 12:17:30 +02:00
Achilleas Koutsou
9aef7bfc47 osbuild-worker: attach pipeline names to jobs
Pipeline names are added to each job before adding to the queue. When a
job is finished, the names are copied to the Result object as well. This
is done for both OSBuild and Koji jobs.

The pipeline names in the result are primarily used to separate package
lists into build and payload/image packages in two cases:
1. Koji builds: for reporting the build root and image package lists to
   Koji (in Koji finalize).
2. Cloud API (v1 and v2): for reporting the payload packages in the
   metadata request.

The pipeline names are also used to print the system log output in the
order in which pipelines are executed. This still isn't used when
printing the OSBuild Result (osbuild2.Result.Write()) and we still rely
on sorting by pipeline name
(see https://github.com/osbuild/osbuild-composer/pull/1330).
2021-11-16 09:49:37 +01:00
Achilleas Koutsou
8dce5aa688 osbuild-worker: use v2 Result struct
- koji-finalize:
Use v2 result type to collect RPM metadata.

The separation between the "build" pipeline and the rest is based on the
pipeline name, which isn't completely reliable since pipeline names can
be arbitrary.

Koji will fail a build if it specifies duplicate packages, so the RPM
lists are deduplicated. The "build" pipeline package list is also
deduplicated in case there are multiple build stages in the same
pipeline.

- osbuild:
Use v2 result type for printing build result to log.

Signed-off-by: Achilleas Koutsou <achilleas@koutsou.net>
2021-11-16 09:49:37 +01:00
Achilleas Koutsou
6b3920783f rpmmd: move RPM metadata tooling to internal pkg
Move the OSBuildStagesToRPMs function, associated test, and RPM type
from the worker into the rpmmd subpackge. We will use this function in
the cloud API to compile the NEVRAs for the new metadata endpoint.
2021-06-29 09:33:05 +01:00
Ondřej Budai
69e7883421 worker/koji-finalize: check the dependencies early
Previously, the checks that dependencies were successful were all over the
Run() method. This led to a issue #1101 (lovely binary number btw).

This commit rewrites the Run() method to:

1) Extract dynamic args. Return an error if they cannot be unmarshalled.
2) Check if dependencies were successful. If not, call kojiFail, update the
   job and return.
3) Create the CGImport metadata and call kojiImport.

Fixes #1101

Signed-off-by: Ondřej Budai <ondrej@budai.cz>
2020-11-25 22:24:22 +00:00
Tom Gundersen
bf86e8ad79 workerapi: serialize koji errors as strings
Serializing an interface does not work, let us simply use the string
representation and treat the empty string as no error. This is
compatible with the current API in the success case, and fixes the
error case, which is currently broken.

Also extend the test matrix for the kojiapi to ensure that all the
different kinds of errors can be serialized correctly and leads to
the correct status being returned.

Fixes #1079 and #1080.
2020-11-13 09:39:55 +01:00
Tom Gundersen
0e382e9cf4 worker: implement koji job types
The three new job types osbuild-koji, koji-init, and koji-finalize
allows the different tasks to be split appart and in particular for
there to be several builds on different architectures as part of a
given compose.
2020-11-11 18:16:42 +01:00