Commit graph

412 commits

Author SHA1 Message Date
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
aa6665ad01 Use RepoRegistry in composer and Weldr API
Modify composer to use RepoRegistry, instead of loading the host
repositories, when initializing WeldrAPI.

Modify WeldrAPI to use RepoRegistry, instead of a map of repository
definitions. Make sure that the RepoRegistry method specific to image
type is used in Welder where appropriate. Specifically when depsolving a
Blueprint, which is used to build a specific image type. Update Weldr
API unit tests to reflect the change.

Add a new method to RepoRegistry, allowing to get list of repositories,
which should be used for building an image for a given architecture,
without specifying the exact image type. Add relevant unit tests.

Signed-off-by: Tomas Hozza <thozza@redhat.com>
2021-05-14 15:43:00 +02:00
Tomas Hozza
fba9fe1072 Make the Distroregistry FromHost() return distro with correct name
Composer does not have 1:1 mapping of what can be the Host Distro name
and the names of supported distributions held in the Distroregistry.

The fact that the host distro `Name()` method as passed to the Weldr API
does not return the same name as what is used as distro name for
repository definitions. This makes it hard to use `distro.Distro` and
`distro.Arch` directly and rely on the values returned by them as their
name.

Add `New*HostDistro()` to all distro definitions, accepting the name
that should be returned by the distro's `Name()` method. This is useful
mainly if the host distro is Beta or Stream variant of the distro.

Change the distroregistry.Registry to contain host distro as a separate
value set when creating it using `New()` function. This value is
returned by `Registry.FromHost()` method. Determining the host distro is
handled by the `NewDefault()` function. Move the distro name mangling to
distroregistry package. Add relevant unit tests.

Signed-off-by: Tomas Hozza <thozza@redhat.com>
2021-05-14 15:43:00 +02:00
Achilleas Koutsou
34b5c5b3f1 weldr: use rhel-8 repos for all RHEL 8.x distros 2021-05-11 12:10:09 +02: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
e799f752be GCP: clean up resources after canceled image import
Add method to fetch Cloudbuild job log.

Add method to parse Cloudbuild job log for created resources. Parsing is
specific to the Image import Cloudbuild job and its logs format. Add
unit tests for the parsing function.

Add method to clean up all resources (instances, disks, storage objects)
after a Cloudbuild job.

Modify the worker osbuild job implementation and also the GCP upload CLI
tool to use the new cleanup method CloudbuildBuildCleanup().

Keep the StorageImageImportCleanup() method, because it is still used by
the cloud-cleaner tool. There is no way for the cloud-cleaner to figure
out the Cloudbuild job ID to be able to call CloudbuildBuildCleanup()
instead.

Add methods to delete Compute instance and disk.

Add method to get Compute instance information. This is useful for
checking if the instance has been already deleted, or whether it still
exists.

Signed-off-by: Tomas Hozza <thozza@redhat.com>
2021-04-01 20:12:39 +02:00
Tomas Hozza
6d51d285cf GCP: accept context from the caller in all methods
Modify all relevant methods in the internal GCP library to accept
context from the caller.

Modify all places which call the internal GCP library methods to pass
the context.

Signed-off-by: Tomas Hozza <thozza@redhat.com>
2021-04-01 20:12:39 +02:00
Brian C. Lane
ca9bb52f7e osbuild-store-dump: Use bp1 with iot image type
Previously it was not using the correct blueprint with the iot image
type. Switch to using bp1 which is the correct blueprint.
2021-03-30 00:19:30 +01:00
Brian C. Lane
ad3e43dc90 osbuild-store-dump: Add Packages support
The compose now saves the list of packages used to create the manifest.
2021-03-30 00:19:30 +01:00
Ondřej Budai
334f421927 test/cli: add a sanity check for Weldr logs
To prevent the issue fixed by the previous commit.

Signed-off-by: Ondřej Budai <ondrej@budai.cz>
2021-03-19 18:50:31 +01:00
Martin Sehnoutka
9ba6dcec4e osbuild-worker: log unknown upload type
Make the target error a bit more useful by sending the name of unknown
upload target.
2021-03-19 15:59:57 +01:00
Martin Sehnoutka
dfa227e82f osbuild-worker: s|errored|failed| because error is a noun
Fix grammar issue.
2021-03-19 15:59:57 +01:00
Martin Sehnoutka
34d165be6c osbuild-worker: unify logging statements
The code previously used both fmt.Printf and log.Printf. Simplify this
by using log.Printf everywhere.
2021-03-19 15:59:57 +01:00
Martin Sehnoutka
a3d80cc924 osbuild-worker: simplify jobimpl osbuild code
The previous version constructed multiple temporary variables and then
create job result from them. This was needed because we had multiple
upload targets but now that we have only one, this is only fragile
version of what can be done in a simplified way.

This PR removes the temporary variables and assigns errors and success
states right after the upload or build has finished.
2021-03-19 15:59:57 +01:00
Martin Sehnoutka
3f9f8c7487 osbuild-worker: drop support for multiple upload targets
Multiple upload targets are not supported by osbuild-composer any more.
Dropping support for this in worker therefore doesn't change anything
from the user's perspective, but it allows us to simplify the code a
bit.

Replace calls to "continue" with "return nil" because the job finished
correctly even though it failed to perform the task. But the failure was
reported to osbuild-composer for further processing so there is no need
to duplicate and report the same error in worker process
2021-03-19 15:59:57 +01:00
Martin Sehnoutka
086a9270b4 osbuild-worker: drop support for local and koji target
Drop support for LocalTarget, this has not been used in a long time,
and we don't really need to stay compatible across many releases
(just as long as we don't get problems with having to deploy in
lock-step), at least not yet.

Also drop support for KojiTarget, this has been replaced by the
osbuild-koji job type.
2021-03-19 15:59:57 +01:00
Martin Sehnoutka
87942865ba osbuild-worker: refactor reporting the job status to deref
The previous implementation exited before reporting back to the worker
API in few branches. This left the compose status in RUNNING state even
though the worker did not work of the job any more. Refactoring the
API call into the `deref` part makes sure it gets called every time.

This commit only moves bits of the code around so that the status gets
back to osbuild-composer, but it still doesn't contain any useful
information in case osbuild fails etc. This will be introduced in
subsequent commits.
2021-03-19 15:59:57 +01:00
Achilleas Koutsou
7b02d43139 osbuild-image-tests: call osbuild with export option
Call osbuild with the export option.  For now the only valid export
value is "assembler".

Run all exported images through testImage.
2021-03-17 18:12:17 +00:00
Achilleas Koutsou
12d4f82428 osbuild-worker: handle 0 and > 1 exports in job
If exports is undefined in request, add the default "assembler" for the
old image types.

If more than 1 export is requested, fail with an error.
2021-03-17 18:12:17 +00:00
Achilleas Koutsou
bc8ac681b6 osbuild-pipeline: add ostree.ref image option
Use default ostree ref for each image type when generating pipelines.
2021-03-17 18:12:17 +00:00
Achilleas Koutsou
e5abd5e5a6 cli-tests: print stderr when cli test fails
When shelling out for a CLI test the error returned from the Start()
command prints the exit code which is not very informative.  Capturing
and printing stderr is a lot more useful.
2021-03-17 18:12:17 +00:00
Achilleas Koutsou
2cce81093f osbuld-worker: call osbuild with --export flag
osbuild now supports using the `--export` flag (can be invoked multiple
times) to request the exporting of one or more artefacts.  Omitting it
causes the build job to export nothing.

The Koji API doesn't support the new image types (yet) so it simply uses
the "assembler" name, which is the final stage of the old (v1)
Manifests.
2021-03-17 18:12:17 +00:00
Achilleas Koutsou
8090621300 osbuild: rename package to osbuild1
Preparing for version 2 of the manifest schema, which will be
implemented in a separate package (osbuild2) alongside the original.
2021-03-17 18:12:17 +00:00
Tomas Hozza
fb089cf00d GCP: Report the right error when image import fails
Fix a bug in the worker job implementation and GCP CLI upload tool,
which causes the code to report wrong error instance in case the image
import failed for some reason.

Signed-off-by: Tomas Hozza <thozza@redhat.com>
2021-03-16 15:26:17 +01:00
Tomas Hozza
e04b75f3df cloud-cleaner: clean up GCP Storage objects based on metadata
Add StorageListObjectsByMetadata() to internal GCP library. The method
allows one to search specific Storage bucket for objects based on
provided metadata.

Extend cloud-cleaner to search for any Storage objects related to the
image import, using custom metadata set on the object. Delete all found
objects.

Signed-off-by: Tomas Hozza <thozza@redhat.com>
2021-03-15 16:48:40 +00:00
Tomas Hozza
e698080bc7 GCP: Set image name as custom metadata on uploaded image object
Extend StorageObjectUpload() to allow setting custom metadata on the
uploaded object.

Modify worker's osbuild job implementation and GCP CLI upload tool to
set the chosen image name as a custom metadata on the uploaded object.
This will make it possible to connect Storage objects to specific
images.

Add News entry about image name being added as metadata to uploaded GCP
Storage object as part of worker job.

Signed-off-by: Tomas Hozza <thozza@redhat.com>
2021-03-15 16:48:40 +00:00
Tomas Hozza
aa1d038b59 cloud-cleaner: clean up image and vm after GCP integration test
Extend internal GCP library to allow deleting Compute Node image and
instance. In addition provide function to load service account
credentials file content from the environment.

Change names used for GCP image and instance in `api.sh` integration
test to make them predictable. This is important, so that cloud-cleaner
can identify potentially left over resources and clean them up. Use the
same approach for generating predictable, but run-specific, test ID as
in GenerateCIArtifactName() from internal/test/helpers.go. Use SHA224
to generate a hash from the string, because it can contain characters
not allowed by GCP for resource name (specifically "_" e.g. in "x86_64").
SHA-224 was picked because it generates short enough output and it is
future proof for use in RHEL (unlike MD5 or SHA-1).

Refactor cloud-cleaner to clean up GCP resources and also to run cleanup
for each cloud in a separate goroutine.

Modify run_cloud_cleaner.sh to be able to run in environment in which
AZURE_CREDS is not defined.

Always run cloud-cleaner after integration tests for rhel8, rhel84 and
cs8, which test GCP.

Define DISTRO_CODE for each integration testing stage in Jenkinsfile.

Signed-off-by: Tomas Hozza <thozza@redhat.com>
2021-03-15 16:48:40 +00:00
Tomas Hozza
075373a51e internal: Move GCP library to internal/cloud
The internal GCP library was originally placed into `internal/upload`
directory, since its purpose was mainly to upload and import built
images to GCP.

Functionality for other cloud-provider-specific libraries is broader,
however scattered around the `internal/` directory based on purpose (e.g. in
`internal/boot` and `internal/upload`). Since all parts of provider-specific
library usually share some common pieces (e.g. authentication), it makes
sense to consolidate them into a single package (e.g. in
`internal/cloud/<provider>`).

Create `internal/cloud` directory, where all cloud-provider-specific
internal libraries should be consolidated. Start with GCP.

Signed-off-by: Tomas Hozza <thozza@redhat.com>
2021-03-15 16:48:40 +00:00
Tom Gundersen
b0805377ea image-tests: checkpoint build root
Most images share a build root, checkpoint the build root to speed up tests
at the potential cost of some disk space (in the cases the build roots are not the same).
2021-03-15 16:40:48 +00:00
Tomas Hozza
7e6adec695 worker: refactor handling of GCP credentials
Make the handling of GCP credentials more consistent with what is being
done e.g. for Azure. Make the GCP section in worker's configuration a
pointer so that it does not show up in the printed worker's
configuration during start up if it was not specified in the actual
configuration file.

Load the GCP credentials file, if provided, during the worker start up to
prevent failure later on while processing a job with GCP upload target.
Pass the loaded GCP credentials as []byte to the OSBuildJobImpl.

Signed-off-by: Tomas Hozza <thozza@redhat.com>
2021-03-12 12:17:02 +01:00
Tomas Hozza
bbae190e99 worker: share GCP image only if the accounts list is not empty
Modify worker's job implementation to try to share GCP image only if the
provided list of accounts is not empty.

Signed-off-by: Tomas Hozza <thozza@redhat.com>
2021-03-12 12:17:02 +01:00
Tomas Hozza
7de2011beb GCP: refactor logging and storage cleanup
Originally, the internal GCP library in `internal/upload/gcp` was
logging various information and errors. Refactor the code to move all
logging to callers of the library. As a result, some methods now return
additional information to preserve the same amount of information being
logged for GCP.

Refactor methods to have only single purpose and not do any extra work,
such as storage cleanup. Methods which create new resources now don't do
any cleanup at all. The caller is responsible to check for any errors
and perform any cleanup necessary. Necessary methods to perform cleanup
are provided.

Modify worker's job implementation and GCP CLI tool to explicitly do all
necessary cleanup, including in case of errors.

Signed-off-by: Tomas Hozza <thozza@redhat.com>
2021-03-12 12:17:02 +01:00
Ondřej Budai
a7dee8b604 distro/*: remove redundant manifest tests
The same test is run in distro/distro_test.go. The redundancy was probably
caused by a bitrot in several commits.

I decided to remove the test from distro implementations to reduce the amount
of duplicated code.

Signed-off-by: Ondřej Budai <ondrej@budai.cz>
2021-03-12 08:29:30 +01:00
Ondřej Budai
3c715c7cf8 distroregistry: add a default distroregistry
This commit adds NewDefault() method to distroregistry that returns a slice
with all distributions supported by osbuild-composer. This way, there's only
one place where a distribution needs to be defined while its support
is being added to composer.

Signed-off-by: Ondřej Budai <ondrej@budai.cz>
2021-03-12 08:29:30 +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
Tom Gundersen
4805eeedf8 test/data/manifests: drop .rpmmd.checksums
These are no longer used.

Signed-off-by: Tom Gundersen <teg@jklm.no>
2021-03-10 11:52:05 +00:00
Ondřej Budai
d9cd9f228f worker: log target errors
This should make debugging of target uploads so much easier.

Signed-off-by: Ondřej Budai <ondrej@budai.cz>
2021-03-08 18:22:27 +01:00
Tom Gundersen
b062d1070d worker/jobimpl-osbuild/azure: set storage account
This was lost in a refactor.
2021-03-06 15:40:48 +00:00
Tom Gundersen
ba40d8a1fc cmd/upload-azure: set storage account
This was lost in a refactor.
2021-03-06 15:40:48 +00:00
Ondřej Budai
2e39d629a9 worker: add azure image upload target
This commit adds and implements org.osbuild.azure.image target.

Let's talk about the already implemented org.osbuild.azure target firstly:
The purpose of this target is to authenticate using the Azure Storage
credentials and upload the image file as a Page Blob. Page Blob is basically
an object in storage and it cannot be directly used to launch a VM. To achieve
that, you need to define an actual Azure Image with the Page Blob attached.

For the cloud API, we would like to create an actual Azure Image that is
immediately available for new VMs. The new target accomplishes it.
To achieve this, it must use a different authentication method: Azure OAuth.
The other important difference is that currently, the credentials are stored
on the worker and not in target options. This should lead to better security
because we don't send the credentials over network. In the future, we would
like to have credential-less setup using workers in Azure with the right
IAM policies applied but this requires more investigation and is not
implemented in this commit.

Signed-off-by: Ondřej Budai <ondrej@budai.cz>
2021-03-06 15:40:48 +00:00
Ondřej Budai
4f66ab5d7c upload/azure: rename Image to PageBlob
The UploadImage method doesn't actually create an image. It creates a Page
Blob. Blob is something like S3 object but in the Azure terminology. Page
Blob means that's optimized for random access and it's the only blob type
that can be used to create images.

This commit cleans up the terminology so it's less confusing.

Signed-off-by: Ondřej Budai <ondrej@budai.cz>
2021-03-06 15:40:48 +00:00
Ondřej Budai
478f69e092 upload/azure: move UploadImage under a new StorageClient struct
We will soon introduce new methods to the storage client.

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
Ondřej Budai
b28f32312d test/image: improve logging of failed osbuild execution
Previously, the test merged stderr and stderr and treated it as json. This was
obviously wrong. osbuild's stderr only returns python exception that are
of course not json.

The behaviour is now different:

1) stderr and stdout are treated separately
2) json from stdout is indented to prevent long lines. If it fails the test
   just prints the stdout as returned from osbuild.
3) stderr is printed as returned from osbuild

Signed-off-by: Ondřej Budai <ondrej@budai.cz>
2021-03-04 12:29:16 +02: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
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
Tomas Hozza
ff95059748 internal/upload: Add support for upload to GCP and CLI tool using it
Add new internal upload target for Google Cloud Platform and
osbuild-upload-gcp CLI tool which uses the API.

Supported features are:
- Authenticate with GCP using explicitly provided JSON credentials
  file or let the authentication be handled automatically by the
  Google cloud client library. The later is useful e.g. when the worker
  is running in GCP VM instance, which has associated permissions with
  it.
- Upload an existing image file into existing Storage bucket.
- Verify MD5 checksum of the uploaded image file against the local
  file's checksum.
- Import the uploaded image file into Compute Node as an Image.
- Delete the uploaded image file after a successful image import.
- Delete all cache files from storage created as part of the image
  import build job.
- Share the imported image with a list of specified accounts.

GCP-specific image type is not yet added, since GCP supports importing
VMDK and VHD images, which the osbuild-composer already supports.

Update go.mod, vendor/ content and SPEC file with new dependencies.

Signed-off-by: Tomas Hozza <thozza@redhat.com>
2021-02-25 18:44:21 +00:00
Tom Gundersen
f0b7cc0973 worker: keep output directory in /var/cache
Let's keep this on the same filesystem as the osbuild store, and
in particular stay away from /var/tmp and its scary semantics.

We are not aware of any issues caused by /var/tmp, but getting
rid of it means we don't have to think about that when debugging,
if nothing else.

Signed-off-by: Tom Gundersen <teg@jklm.no>
2021-02-20 14:53:49 +01:00