Commit graph

962 commits

Author SHA1 Message Date
Achilleas Koutsou
f4ec9d8d91 distro/rhel84: use user ref for commits
Bug fix for changes introduced in #1244.

The new image types, rhel-edge-container and rhel-edge-installer, would
ignore the user-supplied ostree ref and use the default everywhere.

The default should only be used when a ref is not specified, which the
weldr API takes care of before calling the Manifest() method.
2021-03-18 20:06:25 +00:00
Achilleas Koutsou
b843c77c8c rhel84: add a first boot stage for user SSH key
User home directories don't survive the rpm-ostree stage.  They are
converted to systemd-tmpfiles via rpm-ostree post-process, but the
contents are left behind, so any keys we add to the authorized_keys file
will be gone.

This stage sets up a first-boot service that writes the user's public
key to the file in the home directory during the first system boot.
2021-03-17 18:12:17 +00:00
Achilleas Koutsou
1aa0dc28a9 rhel84: fix ostree URL in kickstart
In the Anaconda pipeline, the kickstart stage should fetch the commit
we're embedding.  It was mistakenly trying to fetch from the URL used to
build the image instead.
2021-03-17 18:12:17 +00:00
Achilleas Koutsou
f8b3b3f7e2 rhel84,osbuild2: add system ID to ISO
New stage option added in osbuild
https://github.com/osbuild/osbuild/pull/611

System ID is used by osinfo to identify the RHEL boot ISOs, where the
system ID is "LINUX".
2021-03-17 18:12:17 +00:00
Achilleas Koutsou
bacba210b0 rhel84: new image type: rhel-edge-installer
New image type that generates a Boot ISO.  The ISO contains a RHEL Edge
commit and an installer.  On Boot, it sets up a new RHEL Edge system
with the commit.

The RHEL Edge commit (ostree commit) is downloaded during build from a
URL that should be supplied with the compose request.  The commit's hash
and URL need to be added to the Sources list in the Manifest.

Unlike other types, the new image type defines its own "build" package
set that is added to the distro and arch build package lists.
2021-03-17 18:12:17 +00:00
Achilleas Koutsou
2edb057f3b distro: add URL to OSTreeImageOptions
We need to add the URL to the manifest as an ostree source repo so that
osbuild can pull the commit to embed it in the boot ISO for the new
rhel-edge-installer image type.
2021-03-17 18:12:17 +00:00
Achilleas Koutsou
33cebcc8fc osbuild2: port tar assembler to new stage 2021-03-17 18:12:17 +00:00
Achilleas Koutsou
bec194dfff osbuild2: add support for new osbuild stages
- org.osbuild.anaconda
    Configures Anaconda.  For now, only enabling kickstart modules is
    supported.

- org.osbuild.buildstamp
    Creates a buildstamp file, which is required by Anaconda.

- org.osbuild.kickstart
    Creates a kickstart file.

- org.osbuild.lorax-script
    Uses lorax template helpers to execute a template.

- org.osbuild.bootiso
    Prepares a bootable file system tree suitable for writing on an ISO
    file system

- org.osbuild.discinfo
    Creates a .discinfo file, used by the Anaconda installer.

- org.osbuild.xorrisofs
    Uses the `xorrisofs` command line utility to an ISO.

- org.osbuild.implantisomd5
    Uses the `implantisomd5` command to implant MD5 checksums into an
    ISO.
2021-03-17 18:12:17 +00:00
Achilleas Koutsou
011559f785 osbuild2: add SavedEntry to Grub2StageOptions
Added in osbuild1 already.
2021-03-17 18:12:17 +00:00
Achilleas Koutsou
f107241ee2 obsuild2: support additional layers in oci-archive
The org.osbuild.oci-archive stage now supports an arbitrary number of
layers on top of the Base layer.  The keys for these layers follow the
pattern "layer.N" (N = 1, 2, 3, ...).

We use a custom marshaller and unmarshaller for the
OCIArchiveStageInputs to handle this.  The unmarshaller also validates
the layer keys to match the pattern in the schema.
2021-03-17 18:12:17 +00:00
Achilleas Koutsou
dc5e46139a osbuild2: new dracut stage to re-create initrd 2021-03-17 18:12:17 +00:00
Achilleas Koutsou
2e58dfa61b distro/rhel84: reuse edge package lists for new types
The payloads for these image types should be identical, so no need to
redefine them.
2021-03-17 18:12:17 +00:00
Achilleas Koutsou
164faa7503 osbuild{1,2}: new stages in unmarshal method
Recently added stages org.osbuild.sysconfig and
org.osbuild.kernel-cmdline were missing from the Manifest unmarshal
method causing it to fail when trying to unmarshal manifests that
contained them.
2021-03-17 18:12:17 +00:00
Achilleas Koutsou
0f5936e9fe osbuild1/source: minor typo fix 2021-03-17 18:12:17 +00:00
Achilleas Koutsou
007d52f171 osbuild1/result: read v2 output and convert to v1
Log output from osbuild has a very different format when using the
new schema.  The osbuild1.Result object now supports unmarshalling the
new format and adapting it to the old format.

The most important field to set is the Success field to signal whether
the build succeeded.

Secondarily, it also copies over the output from each stage in order to
provide build job log output through the weldr API.
Since the new format contains multiple pipelines with multiple stages
each, the stages are flattened to fit the old format.  A unique name for
each stage is created by prepending the name of the pipeline to its
index in the pipeline and its type.
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
541cbab0f6 distro/rhel84: new imageType implementation
imageTypeS2 implements the distro.ImageType interface buts generates a
Manifest matching the new osbuild v2 schema.

Two new image types are added to the rhel84 distro (x84_64 and aarch64)
for generating OCI containers contain an Edge (ostree) commit and, when
run, start a web serer to serve the commit.

The image type uses the new PackageSets map to define packages (and
excludes) for the image.  The old methods (Packages() and
BuildPackages()) are implemented for compatibility with the old
workflow.
The image also defines an extra package set for the container that will
serve the package: "httpd" (and its dependencies).

The distro.ImageType interface has a new method: Exports()
It should return a list of names or IDs of artefacts that should be
exported from osbuild when the job is complete.
For the old image types, this is simply set to "assembler".
2021-03-17 18:12:17 +00:00
Achilleas Koutsou
756d5b063f osbuild2: new schema types: stages, inputs, sources
Adding new types and adapting copies of all the old types to match the
new Manifest schema:

New types:
- Stages
    - org.osbuild.ostree.init
    - org.osbuild.ostree.pull
    - org.osbuild.ostree.preptree (replaces org.osbuild.rpm-ostree)
    - org.osbuild.curl
- Converted from assemblers
    The concept of a Build and Assembler stage in gone now. Instead they
    are regular Stages like any other.
    - org.osbuild.oci-archive
    - org.osbuild.ostree.commit
- Sources
    - org.osbuild.curl
    - org.osbuild.ostree
- Inputs
    - org.osbuild.files
    - org.osbuild.ostree

Types with changes:
- Stages
    - org.osbuild.rpm:
        - New input structure for defining packages
        - New options

Basically copies:
- The rest simply rename the `Name` field to `Type`

Decoding types with interface fields:
Types that contain interfaces with multiple implementations implement
their own UnmarshalJSON method.  In these cases, we use a JSON decoder
with the `DisallowUnknownFields` option to catch errors during the
deserialization while trying to determine which implementation matches
the data.

Copied tests for copied types are adapted accordingly.
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
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
f9fe699564 GCP: split internal library based on functionality
Split the GCP library into multiple files:
- compute.go - code interacting mainly with the Compute Node resources
- storage.go - code interacting mainly with the Cloud Storage resources
- gcp.go - common code (e.g. authentication with GCP)

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
b159a281b9 distro/rhel84/qcow2: add net-tools
cloud-init not longer depends on net-tools, so we need to add in the dependency explicitly.

We aimed for the qcow2 to be equivalent to the RHEL8.4 qcow2 produced by imagefactory. However, we missed this unintended change from RHEL8.3.
2021-03-14 15:03:58 +00:00
Tomas Hozza
53cde684d3 GCP: simplify calls to Compute Node API
Reduce the code related to Compute Node v1 API calls in a similar way as
it is done in the API usage examples.

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
d7b0323a2d distroregistry/test: add test for GetDistro
Adding the sweet coverage.

Signed-off-by: Ondřej Budai <ondrej@budai.cz>
2021-03-12 08:29:30 +01:00
Ondřej Budai
9bc35d5e98 distroregistry/test: make the List test generic
So we don't need to update the list when we changed the supported distros.

Signed-off-by: Ondřej Budai <ondrej@budai.cz>
2021-03-12 08:29:30 +01:00
Ondřej Budai
e4295dc49c distroregistry/test: do not depend on the order in the List test
order of distributions doesn't matter.

Signed-off-by: Ondřej Budai <ondrej@budai.cz>
2021-03-12 08:29:30 +01:00
Ondřej Budai
1b63a69245 distro/test: use the new default distroregistry
This way, we don't need to add here a new distro when it's added.

Signed-off-by: Ondřej Budai <ondrej@budai.cz>
2021-03-12 08:29:30 +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
Christian Kellner
8da813ecd2 rhel84: use en_US.UTF-8 as default for LANG
Use en_US.UTF-8 as default for LANG, which is what previously was
used and is also needed to properly work on non-us/latin setups[1].

In the customization tests, use a different value than the default
one to check that the customization does in fact work.

[1] http://git.app.eng.bos.redhat.com/git/spin-kickstarts.git/tree/rhel8/rhel-8.2-kvm-x86_64.ks#n4

Co-authored-by: Achilleas Koutsou <achilleas@koutsou.net>
2021-03-09 21:45:27 +00:00
Brian C. Lane
aa3e26cc10 weldr: Add tests for ostree parent and url usage
Note that this doesn't actually test for the ostree fields, I'm not sure
if that's possible with this test framework. But it does make sure that
a test compose won't try to fetch the url.
2021-03-09 16:19:44 +00:00
Brian C. Lane
aadb62f31e weldr: Add support for compose test with ostree url request 2021-03-09 16:19:44 +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
Tom Gundersen
271960585b internal/boot/azure: set storage account
This was lost in a refactor.
2021-03-06 15:40:48 +00:00
Ondřej Budai
7ae557ea22 target/azure: document what it does
Signed-off-by: Ondřej Budai <ondrej@budai.cz>
2021-03-06 15:40:48 +00: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
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
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
Ondřej Budai
4b031a4692 upload/azure: rename azure.go to azurestorage.go
This file contains a client for Azure Storage API. As we soon introduce the
client for Azure API, we need a distinction here.

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
Ondřej Budai
f67ca8b616 azure: return an early error if unaligned
If the image size isn't aligned to 512 bytes, the Azure API returns very hard
to understand error message. Let's do this check ourselves early so we can
return a sane error.

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