Commit graph

225 commits

Author SHA1 Message Date
Sanne Raymaekers
bff6403b37 cloudapi/v2: pass rhsm requirement to ostree resolve job 2022-11-18 13:07:36 +01:00
Sanne Raymaekers
acc1575cf6 cloudapi/v2: expose ostree contenturl and rhsm options 2022-11-04 11:41:31 +01:00
Tomáš Hozza
1af01ad135 cloudapi: make location optional in Azure Upload Options
Providing the `location` is no longer required for Azure Upload Options.
If it is not provided, the implementation determines the location from
the provided Resource Group. This will make the API nicer for any
client, since they won't need to provide redundant information.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2022-10-27 19:33:43 +02:00
Ondřej Budai
6291eddbf2 koji: put artifacts uploaded to koji under a second level directory
Koji clean-up doesn't delete the top-level directories. As we named every
top-level directory different, they were just cumulating on kojihub, which
is obviously wrong.

This commit changes that behaviour to put all the temporary directories under
a new osbuild-cg top-level one. This way, osbuild-cg won't ve ever cleaned,
whereas osbuild-cg/osbuild-composer-koji-{UUID} will be, which is exactly
what we want.

Closes: https://github.com/osbuild/osbuild-composer/issues/3064
Signed-off-by: Ondřej Budai <ondrej@budai.cz>
2022-10-25 14:48:13 +02:00
Sanne Raymaekers
620536fd61 internal/cloudapi: add ostree options for all otree image types
b01792d9dd broke this behaviour. All
ostree image types should have an ostree resolve job.
2022-10-21 22:32:24 +02:00
Sanne Raymaekers
8fdd158799 cloudapi/v2: use the ostree resolve job to resolve ostree refs 2022-10-19 18:14:10 +02:00
Sanne Raymaekers
b01792d9dd internal/ostree: offload using default ostree ref to caller
If params.Ref is an empty string, it's set to the distro's default
ref. The only difference here is that the default ref also gets
verified.

It makes splitting out resolving ostree refs to a new job easier.

In the weldr and cloud apis, ostree.ResolveParams always got executed,
also for non-ostree image types. Make it more explicit by only resolving
if the image type is actually an ostree image.
2022-10-19 18:14:10 +02:00
Tomáš Hozza
809107cd45 cloudapi: make Bucket optional in GCPUploadOptions
GCP Bucket to use can be now configured in the worker configuration.
Make the `Bucket` optional in the Cloud API when uploading image to GCP.

Adjust the Cloud API test case to configure GCP Bucket on the worker and
not provide it in the API request.
2022-10-11 13:23:18 +02:00
Achilleas Koutsou
390ae15eaa distro: replace ostree.RequestParams with new OSTreeImageOptions
Instead of using the ostree.RequestParams in the OSTReeImageOptions,
define a new struct specific to ImageOptions for the ostree parameters.
This is almost identical to the new ostree.CommitSpec but the meaning of
the parameters changes based on image type and it would not be clear if
the CommitSpec was used in all cases.  For example, the parameters of
the new OSTreeImageOptions do not always refer to the same commit.  The
URL and Checksum may point to a parent commit to be pulled in to base
the new commit on, while the Ref refers to the new commit that will be
built (which may have a different ref from the parent).

The ostree.ResolveParams() function now returns two strings, the
resolved ref, which is replaced by the defaultRef if it's not specified
in the request, and the resolved parent checksum if a URL is specified.
The URL does not need to be returned since it's always the same as the
one specified in the request.
The function has been rewritten to make the logic more clear.
The docstring for the function has been rewritten to cover all use cases
and error conditions.
2022-10-11 10:00:22 +02:00
Ondřej Budai
5bda62fff9 cloudapi: add iot-installer
This was forgotten in previous commits that fixed this image type.

Signed-off-by: Ondřej Budai <ondrej@budai.cz>
2022-10-05 10:29:05 +02:00
Brian C. Lane
f164bfb272 cloudapi: blueprint must have a name 2022-09-30 17:42:07 +02:00
Achilleas Koutsou
fc4450cfbf cloudapi: add fedora iot image types
All except installer, which needs to be fixed.
2022-09-20 18:29:28 +02:00
Ondřej Budai
d78f1e6229 cloudapi: add option to upload S3 artifacts publicly
A small test is added to cover this new option. Also, a check for AWS region
in the URL was removed. The public URL doesn't actually contain it and it's
imho useless - S3 buckets are always tied to a certain region.

The elaborate grep command parsing a path from a URI was switched to being
a small python script. The python script can actually handle an URI without
a query (which was always present in the pre-signed URI, but it's not in the
ordinary one)

Signed-off-by: Ondřej Budai <ondrej@budai.cz>
2022-09-19 22:56:36 +02:00
Sanne Raymaekers
d13347e1ca cloudapi: Add endpoints to clone aws images across regions
Support for creating multiple amis from a single compose. It uses the
AWSEC2* jobs to push images to new regions, and share them with new
accounts.

The compose it depends upon has to have succeeded.
2022-08-30 16:14:52 +02:00
Sanne Raymaekers
d7b8bb122c cloudapi/v2: Add rhsm facts for non-koji cloudapi composes 2022-08-30 15:32:50 +02:00
Sanne Raymaekers
774cc9e638 cloudapi/v2: Don't add rhsm facts
There are workers everywhere which can't deal with this change just
yet. Let's wait until workers can deal with this before adding facts via
the api.
2022-08-26 18:29:26 +01:00
Simon de Vlieger
c5f335bceb Add the rhsm.facts stage.
We initially provide a Facts file that stores the `ApiType`. This is the
API that was used to request the compose.
2022-08-25 18:56:35 +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
1ab3138afe cloudapi: Add test for osbuild job failure due to target errors
The target errors are attached to the details of the osbuild job error.
2022-08-03 13:51:52 +02:00
Sanne Raymaekers
24fab1d5b9 cloudapi: Omit details in compose status job error if nil 2022-08-03 13:51:52 +02:00
Sanne Raymaekers
7b73cf395f cloudapi: Correctly test dependency errors
Dependency errors are not set by the workers, they're not set directly
in the job result. They are added by the worker server in case the job
error indicates it's a dependency error.
2022-08-03 13:51:52 +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
ca32d7b729 cloudapi: Make container name and tag optional
If the user does not pass a name, use the distribution as a name
A provided tag is used only if name is provided. It
The tag's default is a generated using UUID to avoid collisions
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
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
Gianluca Zuccarelli
967ac1c35e worker/server: job status struct
The number of return values from the `jobStatus`
function was growing and getting out of hand. Not
all return values were being used in all cases
and so returning a single struct with the information
and status of a job makes more sense. Then in each case
the resulting fields can be used as needed.
2022-07-27 13:37:14 +02:00
Tomas Hozza
31072c1189 Cloud API: extend a code comment with more information 2022-07-24 08:40:58 +02:00
Tomas Hozza
85f9f07a1f Cloud API: support cloud upload for Koji composes
Add support to handle upload options in image requests for Koji
composes. The image is always uploaded to Koji, but now it can be
uploaded to the cloud environment in addition to Koji as part of the
build.

The image name used for Koji image can't be used as is for uploading to
the cloud, because each cloud provider has its own requirements for the
valid characters. For now, let the Cloud API implementation generate a
random image name. The name is always returned in the compose status's
upload status, so it should be possible to attach it to the Koji build
to allow users to find the image.
2022-07-22 11:39:49 +01:00
Tomas Hozza
1fec2c476d Cloud API: add support for gce-rhui image type
Signed-off-by: Tomas Hozza <thozza@redhat.com>
2022-07-22 11:39:49 +01: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
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
Ondřej Budai
058edd3d76 cloudapi: remove a confusing test
This test tested two things:

1) Invalid route - this is already covered by TestUnknownRoute
2) Invalid UUID in the compose status route - this is now covered by
   TestComposeStatusInvalidUUID

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
Achilleas Koutsou
c1956ba6e1 Use osbuild2 Manifest in all tests
The test_distro Manifest, which is used in tests across multiple
packages, was using the old structure.  Updated to the v2 structure and
adapted all tests.
2022-07-14 16:54:00 +02:00
Tom Gundersen
be5ea6a9b8 distro/ImageType: let PackageSets depend on ImageOptions
The package sets for an image can depend on the blueprint, and
by the same logic there is no reason it should not be able to
depend on the image options.

This is so far a non-functional change, but makes a follow-up
commit simpler (though still without actually depending on
the image options to compute the package sets).
2022-07-04 23:04:29 +01:00
Sanne Raymaekers
03b57f002c jobqueue: Move jobqueue out of internal 2022-07-04 15:37:28 +02:00
Tomas Hozza
776a54135f worker: move osbuild exports from OSBuildJob to target
The osbuild export is specific to the upload target and different
targets may require using a different export. While osbuild-composer
still does not support multiple exports for osbuild jobs, this prepares
the ground for such support in the future.

The backward compatibility with older implementations of the composer
and workers is kept on the JSON (Un)mashaling level, where the JSON
message is always a super-set of the old and new way of providing the
exports to osbuild job.
2022-07-01 18:55:01 +01:00
Tomas Hozza
a61b8af261 cloudapi: fix issue in koji api test forgotten in #2758
The `TestKojiJobTypeValidation` unit test used the `OSBuildJob` and
Koji Target fields in the wrong way, however without any impact on the
testing itself. The reason is that no actual images were built as part
of the test nor the created jobs were ever picked up by a worker.

This change was forgotten in PR#2758.

[1] https://github.com/osbuild/osbuild-composer/pull/2758
2022-07-01 18:55:01 +01:00
Tomas Hozza
6f464949f5 target: move Filename from target options to Target
The filename of the image as produced by osbuild for a given export is
currently set in each target options type in the `Filename` struct
member. However, the value is not really specific to any target type,
but to the specific export used for the target. For this reason move the
value form target type options to the `Target` struct inside a new
struct `OsbuildArtifact` under the name`ExportFilename`.

The backward compatibility with older implementations of the composer
and workers is kept on the JSON (Un)mashaling level, where the JSON
object is always a super-set of the old and new way of providing the
export filename in the Target.
2022-07-01 18:55:01 +01:00
Tomas Hozza
59ded68457 worker: delete TargetErrors from OSBuildJobResult
The `TargetErrors` is not used any more since PR#2192 [1] and there is
no need to keep the backward compatibility any more, because there are
no composer / worker instances in production, which are not running the
modified code.

In addition, delete unit tests covering this legacy error handling.

[1] https://github.com/osbuild/osbuild-composer/pull/2192
2022-07-01 18:55:01 +01:00
Tomas Hozza
c63bfe6d83 target: use constants for target names, instead of string literals 2022-07-01 18:55:01 +01:00
Ygal Blum
08811dd632 Composer API - add support for services enable/disable
Add service sections to the customization unittests
2022-06-30 13:32:12 +02:00
Chloe Kaubisch
765e93bfc8 cloudapi: get specific error from openapi
Error handling is structured in such a way that typically, a ServiceCodeError is passed
through the echo HTTP error, in reference to internally defined errors. We want to be able
to obtain and return specific external errors, for example during validation from openapi3.
Add a 'details' field to the serviceError struct, to contain extra / externally defined
information. Modify HTTPErrorHandler to anticipate either a string or a ServiceErrorCode
from echo, and respond accordingly. Edit the affected tests to expect the appropriate response.
2022-06-28 10:02:55 +02:00
Tomas Hozza
fd82174469 worker/osbuild: consolidate Koji target options values meaning
When the Koji target support was added to the osbuild job, based on the
osbuild-koji job, the meaning of target option values got messed up.

The side effect of the issue is that when Koji composes are
submitted via Cloud API the resulting image is currently always uploaded
back to the worker server.

`OsBuildKoji` job
-----------------
- `OSBuildKojiJob.ImageName` is set to the filename of the image as
  exported by osbuild.
- `OSBuildKojiJob.KojiFilename` is set to the desired filename which
  should be used when uploading the image to Koji.

`OsBuild` job + `KojiTargetOptions` before
------------------------------------------
- `OSBuildJob.ImageName` is set to the filename of the image as exported
  by osbuild. This is done only by the Cloud API code for Koji composes.
  Cloud API does not set this for regular composes and any other target.
  The variable is set in common case only by Weldr API code with the
  same meaning and it is used by the `OsBuild` job implementation as an
  indication that the image should be uploaded back to the worker server.
- `Target.ImageName` is not set at all. Other targets use it for the
  desired filename which should be used when uploading the image to the
  target environment.
- `KojiTargetOptions.Filename` is set to the desired filename which
  should be used when uploading the image to Koji. All other target
  types use `Filename` variable in their options for the filename of the
  image as exported by osbuild.

`OsBuild` job + `KojiTargetOptions` after
-----------------------------------------
- `OSBuildJob.ImageName` is still set to the filename of the image as
  exported by osbuild. This is kept for a backward compatibility of new
  composer with older workers.
- `Target.ImageName` is set to the desired filename which should be used
  when uploading the image to Koji.
- `KojiTargetOptions.Filename` is set to the filename of the image as
  exported by osbuild.

This change is backward incompatible, meaning that old worker won't be
able to handle Koji compose requests submitted via Cloud API using a new
composer and also a new worker won't be able to handle Koji compose
requests submitted by a new composer. This is intentional, because after
discussion with Ondrej Budai, the Cloud API Koji integration is
currently not used anywhere in production.
2022-06-17 17:37:15 +02:00
Chloe Kaubisch
9e6ade2eff cloudapi: standardize format of url strings
Small fix, add format: uri to base_url for the sake of consistency
across url strings.
2022-06-13 13:06:30 +02:00
Tomas Hozza
4a94b46f33 cloudapi: handle multi-tenancy in all compose/<id> endpoints
Use the `EnsureJobChannel()` middleware in all `compose/<id>` endpoints.
Specifically in the:
 - status
 - metadata
 - manifests
 - logs

As a result, these endpoints now return `404` in case the server has JWT
enabled and the channel associated with the request does not match the
channel associated with the requested compose (job).

Extend the multi-tenancy unit test to ensure that these endpoints behave
as expected in case of match and mismatch between the request and
compose channels.
2022-06-10 14:48:18 +01:00
Tomas Hozza
fc7d090498 cloudapi: add EnsureJobChannel() middleware to verify job channel
Add `EnsureJobChannel()` middleware method, intended for `compose/<id>`
endpoints. Its purpose is to ensure that the tenant channel set in
the request `echo.Context` matches the tenant channel associated with
the compose. In case of mismatch, `404` is returned.

Add `JobChannel()` method to the worker server implementation for
requesting channel associated with the job.
2022-06-10 14:48:18 +01:00
Tomas Hozza
c5e1c15cca cloudapi: move ValidateRequest() to middleware.go
Consolidate middleware functions to a single file.
2022-06-10 14:48:18 +01:00
Tomas Hozza
6fa2aa7b4a cloudapi: add helper method to extract tenant channel from echo.Context
Extract the determination of tenant channel into a helper function.
This will simplify handler and middleware  methods, which won't have
to implement the same logic by themselves.

Fix the multi-tenancy unit test to pass the appropriate context when
querying compose statuses, because the server that is being use has JWT
enabled and expects the tenant to be set in it.
2022-06-10 14:48:18 +01:00