Commit graph

69 commits

Author SHA1 Message Date
sanne
d25ae71fef worker: Configurable timeout for RequestJob
This is backwards compatible, as long as the timeout is 0 (never
timeout), which is the default.

In case of the dbjobqueue the underlying timeout is due to
context.Canceled, context.DeadlineExceeded, or net.Error with Timeout()
true. For the fsjobqueue only the first two are considered.
2021-10-19 00:12:18 +01:00
sanne
87cc722021 cloudapi/v2: Plural path section when querying a collection 2021-10-14 16:22:24 +02:00
Ondřej Budai
7760ca1c92 cloudapi/v2: ensure only one image per a compose in the API spec
We've never had the ability to build multiple images per a compose, this
commit thus rips out support for this on the API level:

image_requests is now image_request and it accepts only one ImageRequest
object instead of an array of them.

Signed-off-by: Ondřej Budai <ondrej@budai.cz>
2021-10-14 00:14:34 +02:00
Ondřej Budai
b2dc90e404 cloudapi/v2: clean up targets
tbh, I don't fully understand why we wrote the code in this way.

Not a functional change.

Signed-off-by: Ondřej Budai <ondrej@budai.cz>
2021-10-14 00:14:34 +02:00
Ondřej Budai
6b8f758c54 cloudapi/v2: move multi-image compose check to the beginning
Signed-off-by: Ondřej Budai <ondrej@budai.cz>
2021-10-14 00:14:34 +02:00
Sanne Raymaekers
c65b1e9b26 Revert "cloudapi/v1: Move depsolving to workers"
This reverts commit 0f44250237.
2021-10-13 12:01:51 +02:00
sanne
0f44250237 cloudapi/v1: Move depsolving to workers
We can't enqueue a job without a worker doing the depsolve step now, so
adapt the tests as well.
2021-10-12 14:21:03 +01:00
Achilleas Koutsou
395a22aa21 cloudapi/v2: fix newV2Server() call in test
Bug caused by two consecutive PR merge rebases, one that added a
function call and another that changed the signature of the same
function.
2021-10-11 23:48:26 +02:00
Ondřej Budai
e904397fdb cloudapi/v2: Use worker to depsolve
Signed-off-by: Ondřej Budai <ondrej@budai.cz>
2021-10-11 13:16:51 +02:00
sanne
ce7ac9a756 worker: Make BasePath configurable 2021-10-11 09:52:21 +02:00
sanne
6ce20a9ef6 cloudapi/v2: Listen on /api/image-builder-composer/v2 2021-10-11 09:52:21 +02:00
sanne
4eca54b6ed cloudapi/v2: Configurable aws bucket
Fixes #1855
2021-10-09 00:55:09 +01:00
sanne
b6c08f3056 cloudapi/v2: Replace upload types with image types
Because there's only a few combinations of upload types and image types
that make sense, enforce correct combinations by eliminating upload
types.

Fixes #1775
2021-10-09 00:55:09 +01:00
sanne
cda54ef926 cloudapi/v1: Return status created in compose handler 2021-10-07 10:54:12 +02:00
Diaa Sami
27ca55372a cloudapi: Add extra logging & improve existing
Use different logging levels depending on situation
Log HTTP 5xx errors to stdout with internal error details when possible
2021-09-30 18:34:05 +02:00
Diaa Sami
179009fec4 cloudapi: use Logrus as default logger in Echo
And remove log.Logger references
2021-09-30 18:34:05 +02:00
Diaa Sami
60e403e53e cloudapi: use Recover middleware to handle panics
recover from panics such as out-of-bounds array access & nil
pointer access, print a stack trace and return 5xx error
instead of the service crashing and relying on Execution
framework to handle crashes
2021-09-24 12:11:04 +01:00
sanne
5a9d8c792b cloudapi: V2
V2 is compliant with api.openshift.com design guidelines.

Errors are predefined, have codes, and are queryable.

All requests have an operationId set: a unique identifier which is
sortable by time. This is added to the response in case of an error.

All returned objects have the href, id, and kind field set.
2021-09-14 15:32:21 +02:00
Chloe Kaubisch
11023cb8a8 cloudapi: change Organization customization to a string
Internally change Organization in the SubscriptionImageOptions
to a string instead of an int.
2021-09-08 17:38:05 +02:00
sanne
5e72636331 Revert "cloudapi: Add x-rh-identity header filter"
This reverts commit 19db3ff1d4.
2021-09-04 02:48:52 +02:00
sanne
7a0ea5b244 worker: Remove identity filter
Partially reverts "0ea31c39d5"
2021-09-04 02:48:52 +02:00
Diaa Sami
c35097fd52 Support for temporary credentials
Handle session token so that temporary credentials are supported
2021-09-02 15:13:42 +02:00
Chloe Kaubisch
86082c884d cloudapi: fix compose return value
Correct compose successful return status from http.StatusOK to
http.StatusCreated. Mistakenly set to http.StatusOK in previous
commit.
2021-09-01 22:15:35 +02:00
Thomas Lavocat
8a6e0e2b75 cloudapi: correct format of error strings
Fixes bad formats for the error in the cloudapi.
2021-09-01 20:02:07 +02:00
Chloe Kaubisch
8c26614049 cloudapi: rework return values
Change instances of panic on error to return StatusInternalServerError
instead. Additionally change return code 200s to http.StatusOK.

Fixes #1606
2021-08-25 17:48:29 +02:00
Martin Sehnoutka
1ada606ed8 internal/rhsm: introduce package that handles subscriptions
The problem: osbuild-composer used to have a rather uncomplete logic for
selecting client certificates and keys while fetching data from
repositories that use the "subscription model". In this scenario, every
repo requires the user to use a client-side TLS certificate. The problem
is that every repo can use its own CA and require a different pair of
a certificate and a key. This case wasn't handled at all in composer.

Furthermore, osbuild-composer can use remote workers which complicates
things even more.

Assumptions: The problem outlined above is hard to solve in the general
case, but Red Hat Subscription Manager places certain limitations on how
subscriptions might be used. For example, a subscription must be tight to
a host system, so there is no way to use such a repository in osbuild-composer
without it being available on the host system as well.

Also, if a user wishes to use a certain repository in osbuild-composer it
must be available on both hosts: the composer and the worker. It will come
with different pair of a client certificate and a key but otherwise, its
configuration remains the same.

The solution: Expect all the subscriptions to be registered in the
/etc/yum.repos.d/redhat.repo file. Read the mapping of URLs to certificates
and keys from there and use it. Don't change the manifest format and let
osbuild guess the appropriate subscription to use.
2021-08-09 12:40:23 +02:00
Chloe Kaubisch
53109945ef cloudapi: create binder
Add an echo.Binder() to simplify parsing the compose request body.
2021-08-04 11:49:50 +02:00
Chloe Kaubisch
29af662bf8 cloudapi: replace chi with echo
standardize middleware by replacing chi with echo
2021-08-03 13:09:13 +02:00
Thomas Lavocat
4729990ac0
cloudapi: Add User customization
Cloud api now exposes user customization that let a customer able to add
a new user with a set of groups and a ssh key.

Testing:
* adds 2 users to the AWS image, accessible with a temp ssh key.
* the first one is in the group wheel, the other is not

Fixes #1574
2021-07-28 10:40:25 +02:00
Chloe Kaubisch
4c800f29a7 worker: add metrics
use prometheus to gather metrics
2021-07-23 21:54:28 +02:00
Thomas Lavocat
cfc91a3eb6 CloudAPI: Invalid package set returns 400
Previously a bad error code was returned, fixes #1477.

Testing:

I have two test cases to test the solution. The first is a request that
makes depsolve crash by changing the dnf-json script by an almost empty
one that only throws an exception. The second one fails because it
requests a non existing package. The former ends with a 500 error and
the later with a 400.

----8<-----

HTTP/1.1 500 Internal Server Error

Failed to depsolve base packages for ami/x86_64/centos-8: ailed to
depsolve base packages for ami/x86_64/centos-8: unexpected end of JSON
input

----8<-----

HTTP/1.1 400 Bad Request

Content-Length: 226Failed to depsolve base packages for
ami/x86_64/centos-8: DNF error occured: MarkingErrors: Error occurred
when marking packages for installation: Problems in request:
missing packages: jesuisunpaquetquinexistepas_idonotexist
2021-07-21 16:21:15 +02:00
Achilleas Koutsou
cfb244ab34 cloudapi: check if metadata is nil before converting 2021-06-29 09:33:05 +01:00
Achilleas Koutsou
51503cc000 cloudapi: collect RPMs from v2 result stages
Fix for v1 results: collect RPMs for main stages, not build.
Support for v2 results: filter out build stages from stage results,
which include stages from all pipelines (flattened).
2021-06-29 09:33:05 +01:00
Achilleas Koutsou
39e646ae68 cloudapi: return ostree commit ID with metadata
When the assembler (v1) or any stage (v2) has type ostree.commit,
retrieve the commit ID (hash) from the osbuild stage metadata and return
it with the rest of the metadata (package NEVRAs).
2021-06-29 09:33:05 +01:00
Achilleas Koutsou
df5921403d cloudapi: add compose/id/metadata endpoint
Returns NEVRAs, compiled from the job manifest.
Will also return the ostree commit ID for edge commit types.
2021-06-29 09:33:05 +01:00
Achilleas Koutsou
e5b28c0bb3 New upload target: AWS S3
Uploads an artifact to an S£ bucket and returns a presigned URL to allow
the user to download the file.

Although it uses a lot of common code with the AWS AMI upload target,
it's treated as a completely separate target.
2021-06-18 14:02:09 +01:00
Achilleas Koutsou
b2f5e1cd72 cloudapi: support ostree options
Move OSTree option handling outside of the weldr API to make it usable
by other packages. New subpackage at internal/ostree.

Add support for ostree options ("Ref" and "URL") in the Cloud API.
Validate OSTree options and resolve the parent reference the same way as
in the Weldr API.

Unlike the Weldr API, the Cloud API doesn't support specifying the
Parent reference directly.

The exports list is included in the job information on the queue.
2021-06-18 14:02:09 +01:00
sanne
0ea31c39d5 worker: Add identity filter and client oauth support 2021-06-17 10:08:35 +02:00
sanne
19db3ff1d4 cloudapi: Add x-rh-identity header filter 2021-06-05 14:47:38 +01:00
Tomas Hozza
c91f3b11f6 Rename all occurrences of "Compute Node" to "Compute Engine"
This is an error, there is no such thing as "Compute Node" in GCP.

Signed-off-by: Tomas Hozza <thozza@redhat.com>
2021-04-01 20:12:39 +02:00
Tomas Hozza
4a47ad36af Cloud API: fix image_status.status value for running compose
Previously, the Cloud API endpoint `/v1/compose/{id}` return value's
`image_status.status` for a running worker job was "running", which didn't
comply with the Cloud API specification. Equivalents allowed by the API
specification are "building", "uploading" or "registering".

As a result, the Image Builder API also does not comply in this regard
to its specification, because it currently just copies the status value
string returned by osbuild-composer.

Define the `image_status.status` as a reusable type in the Cloud API
specification. This forces openapi to generate an explicit type for it,
which can be then explicitly used in the code, instead of plain strings.

Return "building", instead of "running"  for running compose.

Modify api integration test to check for all valid `image_status.status`
values for a compose.

Add News entry explaining this change.

Signed-off-by: Tomas Hozza <thozza@redhat.com>
2021-03-26 11:59:07 +01:00
Ondřej Budai
dd4db353e2 distro: move Registry to its own distroregistry package
My goal is to add a method to distroregistry to return Registry with
all supported distributions. This way, all supported distributions
would be defined only on one place.

To achieve this, the Registry must live outside the distro package
because the distro implementation depends on it and this would create
a circular dependency unsupported by Go.

Signed-off-by: Ondřej Budai <ondrej@budai.cz>
2021-03-12 08:29:30 +01:00
Tom Gundersen
9e2e009ac8 distro: introduce PackageSets
This replaces Packages() and BuildPackages() by returning a map of
package sets, the semantics of which is up to the distro to define.

They are meant to be depsolved and the result returned back as a
map to Manifest(), with the same keys.

No functional change.

Signed-off-by: Tom Gundersen <teg@jklm.no>
2021-03-10 11:52:05 +00:00
Chloe Kaubisch
500533116a cloudapi: single uploadrequest
Change imageRequest to accept a single uploadRequest instead of
an array of uploadRequests.
2021-03-09 16:42:33 +01:00
Ondřej Budai
9ca1b0a8b6 api/cloud: add support for azure
This commit adds support for uploading images directly to Azure using the
cloud API.

The UploadStatus part is currently not implemented and will be added in a
follow-up PR.

Signed-off-by: Ondřej Budai <ondrej@budai.cz>
2021-03-06 15:40:48 +00:00
Ondřej Budai
61e97372df api/cloud: remove magic constants
UploadTypes_* constants are auto-generated from the openapi spec.

Signed-off-by: Ondřej Budai <ondrej@budai.cz>
2021-03-06 15:40:48 +00:00
Tomas Hozza
319400c280 cloudapi: implement GCP target results and include UploadOptions
Return GCP-specific target results form the worker, similar as it is
done for AWS.

Extend Cloud API to allow GCP-specific upload Options.

Modify Cloud API to return UploadOptions as part of the UploadStatus.

Modify Cloud API integration test to check returned upload Options and
upload Type.

Signed-off-by: Tomas Hozza <thozza@redhat.com>
2021-03-04 15:44:04 +01:00
Chloe Kaubisch
f091af55d8 cloudapi: add targetresults
Add the TargetResult struct to OSBuildJobResult. Include the 'options'
interface on TargetResult to contain target-specific information,
for example amiID and region from AWS. Expose 'options' on a status
call as an UploadStatus field. Add logic to support AWS within this
format, which can be used as a template for other targets.
2021-03-02 13:22:11 +01:00
Tomas Hozza
080b64c12c cloudapi: Don't return upload type in UploadStatus for now
Upload target type is currently not returned form the worker, but
hardcoded in the cloudapi code to always return "aws". This make testing
of the cloudapi for other cloud providers quite complicated.

Since extending the target status information returned from the
worker is currently in progress, work around the situation for now
by returning an empty string as the upload type.

This will allows other types of upload targets to be tested as part of
cloudapi test case.

Signed-off-by: Tomas Hozza <thozza@redhat.com>
2021-02-25 18:44:21 +00:00
Tomas Hozza
94d399f010 cloudapi: Add support for GCP as upload target
Add support for GCP as an upload target to the internal API.

Extend the cloudapi to allow GCP as an upload target in the compose
request. Regenerate the cloudapi go code. Added GCP-specific upload
result component in the API definition, similar to AWS. It is not yet
used, but it will be once returning a target-specific result from
worker is supported.

Add support for GCP upload target to the worker job implementation.

Signed-off-by: Tomas Hozza <thozza@redhat.com>
2021-02-25 18:44:21 +00:00