Commit graph

345 commits

Author SHA1 Message Date
Ondřej Budai
978e309153 worker/server: move it to the style of koji server
The previous code was smelling a bit (e.g. Server.server field) so I decided
to rewrite it in the style of the much nicer koji server.

Not a functional change.

Signed-off-by: Ondřej Budai <ondrej@budai.cz>
2020-11-19 17:39:24 +00:00
Jacob Kozol
0dd17ae3f7 distro: add rhel 84 support
cockpit-composer can now build rhel 8.4 images. Our distro name for
rhel 8.4 is rhel-84 unlike prior rhel releases which fall
under the umbrella name rhel-8. rhel 8.4 still uses the same
repos as the rest of the rhel 8 releases but points to a different
nightly repo for testing purposes. Test cases are added. The changes
between rhel 8.3 and 8.4 are as follows:

There is now a hybrid boot partition scheme for x86_64. x86_64 images
now use uefi boot and have 3 gpt partitions: a small unformated
partition for mbr compatibility, an efi boot partition of type vfat, and
a root partition of type xfs. The packages grub2-efi-x64 and shim-x64
are added as bootloader packages for all x86_64 images.

For qcow2 images ro is added as a kernel option and the following
packages are added (+) or removed (-):
+ dosfstools
+ efi-filesystem
+ efivar
+ efivar-libs
+ grub2-efi-x64
+ shim-x64
- rhn-client-tools
- rhnlib
- rhnsd
- rhn-setup
2020-11-19 10:36:49 +01:00
Ondřej Budai
117da5aa8a composer: add sanity checks
Running composer without workers or APIs enabled is pretty much a no-op.
Let's forbid that.

Signed-off-by: Ondřej Budai <ondrej@budai.cz>
2020-11-17 17:01:18 +00:00
Ondřej Budai
dc1b84fcfe composer: split out the local worker socket
Everybody hates the local workers. The first step of getting rid of them
is to split their socket out of osbuild-composer.socket - we need to keep
this one to support the Weldr API but the local worker socket can live in
its own file.

The behaviour should be the same for now: osbuild-composer.service always
starts the local worker socket.

However, this split allows the osbuild-composer executable to be run without
the Weldr API activated. The following commit explores this option more
in depth.

Note that the new socket can be used by root only because workers are always
run as root.

Signed-off-by: Ondřej Budai <ondrej@budai.cz>
2020-11-17 17:01:18 +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
Ondřej Budai
a6df2877a3 fsjobqueue: accept jobs of any type
Soon, we want to begin tagging the jobs with the name of its submitter.
The simplest way to add a tag to a job is to put it into its type string.
However, as we don't know (and don't want to know) the submitters' names when
osbuild-composer is initialized, we need to be able to push arbitrary job
types into the jobqueue.

This commit therefore lifts the restriction that a jobqueue accepts only
a predefined set of job types. Now, jobqueue clients can push jobs of
arbitrary names.

Signed-off-by: Ondřej Budai <ondrej@budai.cz>
2020-11-12 15:30:30 +00:00
Tom Gundersen
5dac422b9c cmd/composer: drop koji configuration
Now that all interaciton with the koji API happens in the workers
we can drop koji configuration from composer itself. This means
that composer no longer needs to be provisioned with kerberos
credentials, and does not need to know about which koji servers
the workers support.
2020-11-11 18:16:42 +01:00
Tom Gundersen
98fd290a08 worker: make Enqueue() specific for each job type
Most of the worker API is now untyped, but keep Enqueu() typed to
ensure the job objects match the names in the queue. This means we
must add a version of Enqueue() for each job type we support.
2020-11-11 18:16:42 +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
Lars Karlitski
6b6cd7ca9f worker: introduce JobImplementation interface
Introduce JobImplementation and turn the current RunJob() into
OSBuildJobImpl. Make main() select a job impl based on job type.

This is in preparation to add additional impls.
2020-11-09 14:17:19 +01:00
Lars Karlitski
3bc642e4aa worker: split osbuild job implementation into separate file
No code was changed.
2020-11-09 14:17:19 +01:00
Lars Karlitski
c15c17960b worker: make worker.Client job-agnostic
Move the fact that the worker is requesting jobs of type "osbuild" out
of the client library.

For one, require consumers to pass accepted job types to RequestJobs()
and allow querying for the job type with the new Type() function.

Also, make OSBuildArgs() and Update() generic, requiring to pass an
argument that matches the job type.
2020-11-09 14:17:19 +01:00
Lars Karlitski
07f21d089e worker: move job.Update() into RunJob()
Now, main() does not deal with OSBuildJobResult anymore, and RunJob()
doesn't return it. This means we can add more job types (i.e., different
RunJob()s) now.
2020-11-09 14:17:19 +01:00
Lars Karlitski
1184d78494 worker: remove race from WatchJob()
WatchJob() regularly checks if a job was canceled in a goroutine. It
does so by accessing composer's `/jobs/{token}` route. However, once the
main goroutine marks the job as done (by sending PATCH to that same
route), the `token` is no longer valid and thus the route not accessible
anymore.

main() does cancel the goroutine running WatchJob, but it's not
guaranteed that it gets scheduled in time to actually stop watching the
job.

Thus, don't cancel the job when fetching the `/jobs/{token}` fails. This
means that it won't cancel the job anymore when the connection to
composer goes down.

Also, we will be able to move job.Update() into RunJob().
2020-11-09 14:17:19 +01:00
Lars Karlitski
299a5e52ab worker: use OSBuildJobResult consistently
Workers reported status via an `osbuild.Result`, which only includes
osbuild output. Make it report OSBuildJobResult instead, which was meant
to be used for this purpose and is already used as the result type in
the jobqueue.

While at it, add any errors produced by targets into this struct, as
well as an overall success flag.

Note that this breaks older workers returning the result of an osbuild
job to a new composer. I think this is fine in this case, for two
reasons:

1. We don't support running different versions of the worker and
composer in the weldr API, and remote workers aren't widely used yet.

2. Both osbuild.Result and worker.OSBuildJobResult have a top-level
`Success` boolean. Thus, logs are lost in such cases, but the overall
status of the compose is not.
2020-11-09 14:17:19 +01:00
Lars Karlitski
a0f080c497 worker: remove FailJob()
This function is almost the same as the koji uploader, except that it
calls `CGFailBuild` instead of `CGImport` at the end.

Don't exit early from RunJob() when the job failed. Instead, go through
all the uploaders anyway. All the others don't do anything when the job
fails, but now we have the chance to do the necessary `CGFailBuild` call
for koji.

This moves more logic from main() into RunJob(), so that we can support
different job kinds in the future.
2020-11-09 14:17:19 +01:00
Lars Karlitski
f6f4f1fd9b worker: add missing continue 2020-11-09 14:17:19 +01:00
Lars Karlitski
0cd7174598 worker: deprecate the local target
Add "image_name" and "stream_optimized" fields to the osbuild job as
replacement for the local target options. The former signifies the name
of the uploaded artifact and whether an artifact should be uploaded at
all (only weldr API). The latter will be deprecated at some point, when
osbuild itself can make streamoptimized vmdk images.

This change separates what have always been two distinct concepts:
artifacts that are reported back to the composer node (in practice
always running on the same machine), and upload targets to clouds and
such. Separating them makes it easier to add job types that only allow
one upload target while keeping artifacts.

Keep the local target around, so that jobs that are scheduled can still
be run after an upgrade.
2020-11-09 14:17:19 +01:00
Lars Karlitski
d1f322ec6f worker: always send status "FINISHED"
The server hasn't used common.ImageBuildState to mark a job as
successful or failed for a long time. Instead, it's using the job's
return argument for that. (Jobs don't have a high-level concept of
failing).

Drop the check in the server, and always send "FINISHED" from the client
for backwards compatibility.
2020-11-09 14:17:19 +01:00
Lars Karlitski
b7cb2cff62 worker: only remove temp output directory once
We already do this in a defer.
2020-11-09 14:17:19 +01:00
Lars Karlitski
4e46eacd64 worker: handle error when closing osbuild's stdin
This will only happen rarely, but it will be good to know it happened
when it does.
2020-11-09 14:17:19 +01:00
Lars Karlitski
89814c3107 worker: mark builds as failed based on osbuild's output
osbuild reports failing builds in two ways: it sets the "success" field
in its output to `false` and it returns with a non-zero exit status. The
worker used both, returning an `OSBuildError` when osbuild return
non-zero, but also forwarding the resulting object with the "success"
field.

Change this to only use the "success" field and ignore the return value.
The latter is useful for people running osbuild in a terminal or script,
but is redundant for this use-case.

This makes error reporting more consistent: `RunOSBuild` only returns an
error when *running* osbuild failed, not when the build fails.
2020-11-09 14:17:19 +01:00
Ondřej Budai
19271a542b test/auth: rework the test to use the new openssl setup
Previous commits introduces a new way to generate all X.509 certificates
needed for testing. This commit reuses the same method for auth tests.

This has two benefits:

1) The new code generates certificates with Subject Alternative Name which
   means we can use it on systems with Go 1.15 (Fedora 33, RHEL 8.4).

2) The new code generates much saner certificates.
2020-11-05 13:48:48 +01:00
Ondřej Budai
90aabfa8c8 test/auth: extract certificate code
Not a functional change, just cleaning up
2020-11-05 13:48:48 +01:00
Ondřej Budai
073f9dc79a test/koji: move the koji test to schutzbot
The Koji test in Github actions was always a bit quick and dirty solution.
I think it's much nicer solution to run it on Schutzbot.

Therefore, this commit moves the koji_test.go to a new osbuild-koji-tests
executable. This new test isn't run in the base test suite as one would
anticipate but inside the koji.sh test. This is needed because
osbuild-koji-tests requires a running koji instance. This might change
in the future but I think it works for now.
2020-11-02 19:59:28 +01:00
Ondřej Budai
2dc0ecec73 koji: mark the osbuild version CGImport metadata as TODO
So we don't forget. Also, the version is changed to 0 so it's clear that
it is just a placeholder because osbuild 0 was never released.
2020-10-27 19:01:30 +00:00
Ondřej Budai
353a65356c koji: add signature to the CGImport metadata components
As suggested by Brew maintainers Tomáš Kopeček and Lubomír Sedlář.
2020-10-27 19:01:30 +00:00
Ondřej Budai
befeef34a5 koji: use nvra as the filename for images
We have the same thing for AWS. The AWS target also specifies under what name
should be the image available in EC2.

As requested by Brew maintainers Tomáš Kopeček and Lubomír Sedlář.
2020-10-27 19:01:30 +00:00
Ondřej Budai
b2ed59c385 koji: use none container arch in CGImport metadata
osbuild runs directly on the host, there's no intermediate container,
therefore we should set the container type to none.

As suggested by Brew maintainers Tomáš Kopeček and Lubomír Sedlář.
2020-10-27 19:01:30 +00:00
Ondřej Budai
a0832d22e0 koji: use the host arch as the buildroot and image arch in CGImport metadata
As suggested by brew maintainers Tomáš Kopeček and Lubomír Sedlář.
2020-10-27 19:01:30 +00:00
Ondřej Budai
c64d46416e koji: use the host name from /etc/redhat-release in CGImport metadata
As suggested by Brew maintainers Tomáš Kopeček and Lubomír Sedlář.
2020-10-27 19:01:30 +00:00
Ondřej Budai
b91a63c0ad koji: fix converting rpm stage metadata to koji components
This commit adds a missing pointer and a test to verify that the conversion
is indeed fixed.
2020-10-21 11:40:01 +02:00
Tom Gundersen
3c7f61c322 test: restructure dir layout
Attempt to clarify the structure of our tests. Each test case is now
encapsulated in a script in `test/cases`. Each of these scripts should
be runnable on a pristine machine and be independent of each other. It
is up to the test-orchestractor to decide if they should be run
consequtively instance, or in parallel on separate instances. Each
script can execute several tests and call whatever helper binaries
is desired. However, each case should be assumed to always run as one.
2020-10-21 09:04:13 +02:00
Tom Gundersen
25abccf66d tree-wide: drop f31 support
We no longer release into F31, and the right specfile was anyway not
being tested.

This allows us to remove a workaround that updates the VMs during
deploy, and other fedora-31 specific hacks.
2020-10-21 09:04:13 +02:00
Lars Karlitski
0f70edb48e osbuild-auth-tests: print output from openssl
This helps debugging certificate errors, because it prints
configuration on success and what went wrong on errors.
2020-10-16 09:37:04 +02:00
Lars Karlitski
0aef7ff5d5 test/cmd: add api.sh
Add an additional integration test, which builds a fedora-32 image via
the newly moved composer API.

This adds a new certificate for clients to authenticate, with
CN=client.osbuild.org.

Also stop allowing certificates with `CN=worker.osbuild.org` in the
`osbuild-composer.toml` used in tests and amend `osbuild-auth-tests` to
use `CN=client.osbuild.org` for accessing the koji API.

Heavily based on an earlier version of this test in `test/cmd/aws.sh` by
Sanne Raymaekers.
2020-10-16 09:37:04 +02:00
Lars Karlitski
b25a350502 osbuild-composer: merge cloud API into main binary
This removes the osbuild-composer-cloud package, binary, systemd units,
the (unused) test binary, and the (only-run-on-RHEL) test in aws.sh.

Instead, move the cloud API into the main package, using the same
socket as the koji API, osbuild-composer-api.socket. Expose it next to
the koji API on route `/api/composer/v1`.

This is a backwards incompatible change, but only of the -cloud parts,
which have been marked as subject to change.
2020-10-16 09:37:04 +02:00
Lars Karlitski
835b556db7 distribution: deprecate osbuild-composer-koji.socket
Instead, call it osbuild-composer-api.socket, but provide a symlink for
backwards compatibility. Change `schutzbot/provision.sh` to only enable
osbuild-composer-api.socket.

In the future, this new socket is the only API socket, which provides
both the "cloud" API and the one for koji.

This means that the koji API is always enabled.
2020-10-16 09:37:04 +02:00
Martin Sehnoutka
174e3f2037 ci: fix artifact name generation in cloud cleaner
The issue comes from the fact that the PR introducing it was very old
and meanwhile the variable used for image name creation has changed.
This patch makes sure both functions are the same.
2020-10-14 13:00:48 +02:00
Martin Sehnoutka
6b137d0ac5 cloud-cleaner: introduce script to wipe all CI artifacts
In case the job fails completely, resources might leak. This patch
together with the one introducing predictable names for CI artifacts
will make sure we wipe all resources after each CI run.
2020-10-13 14:41:32 +02:00
Tom Gundersen
b86b18c4fb test/integration: move azure configuration into azure
This is not an integration test, but configuration.

Signed-off-by: Tom Gundersen <teg@jklm.no>
2020-10-06 13:08:26 +02:00
Tom Gundersen
9d18c3bfa2 tests: rename composer-cli tests
These had the generic name osbulid-tests, rename the binary to more
closely describe what is under test: weldr API as composed by
composer-cli.

Signed-off-by: Tom Gundersen <teg@jklm.no>
2020-10-06 13:08:26 +02:00
Jacob Kozol
678de9d1ef distro: add fedora 33 support
Fedora 33 images can now be built and test cases are added for the new
images. The fedora 33 qcow2 and vmdk images are based off of the
official images and their kickstarters found here:
https://pagure.io/fedora-kickstarts. The fedora 33 iot image is based
off of the the config found here: https://pagure.io/fedora-iot/ostree.
The openstack, azure, and amazon image types have changes made to them
based off of the changes made to the qcow2. The changes between fedora
32 and fedora 33 are as follows:

Grub now loads its kernel command line options from
etc/kernel/cmdline, /usr/lib/kernel/cmdline, and /proc/cmdline instead
of from grub env. This is addressed by adding kernelCmdlineStageOptions
to use osbuild's kernel-cmdline stage to set these options. Alongside
`ro biosdevname=0 net.ifnames=0`, we also set `no_timer_check
console=tty1 console=ttyS0,115200n8` per what is set in the official
qcow2. For azure and amazon, the kernelOptions are still set as they
were in fedora 32.

The timezone is now set to UTC if a user does not set a timezone in the
blueprint customizations. Also, the hostname is set to
localhost.localdomain if the hostname isn't set in the blueprint.

Finally, the following packages have been removed:

polkit
geolite2-city
geolite2-country
zram-generator-defaults
2020-10-01 10:11:03 +02:00
Lars Karlitski
7aca756156 osbuild-composer: split out the actual service
Split the actual service into its own type `Composer` in composer.go.
main.go now (more or less) contains only collecting configuration from
the environment and the file system, as well as activation file
descriptors.

Aside from making the code easier to grok, this is a first step towards
running composer in a different environment than the one set up by
systemd.
2020-09-29 21:52:58 +01:00
Lars Karlitski
13d5129b56 osbuild-composer: use less pointers in config
The default values of fields in both ComposerConfig.Koji and
ComposerConfig.Worker are well-suited for how they're used.

The nil-checks in main.go only checked that the sections exist. This is
quite a weak check for validity, because the sections could be empty. If
anything is required for composer to function, we could add proper
validation in the future.

Do the same for the CA fields, which contain file names. Go has lots of
precedent for using empty strings to denote "no value" in the standard
library. Use it for CA files, too, instead of pointers.
2020-09-29 21:52:58 +01:00
Lars Karlitski
db9bf1c659 osbuild-composer: move config parsing into separate file
The configuration file is API. Let's give it a bit more prominence to
help people treat it as such, and a chance to test it. A basic test is
included in this commit.

Also, this cuts down on the noise in main.go a bit.
2020-09-29 21:52:58 +01:00
Lars Karlitski
af9471e4a2 osbuild-composer: socket always has two listeners
A third listener used to exist for the RCM API, but was removed a while
ago.
2020-09-29 21:52:58 +01:00
Lars Karlitski
6dce21cdc8 osbuild-composer: enforce one listener for worker API
There's no use case for many of those.
2020-09-29 21:52:58 +01:00
Lars Karlitski
40d8440660 kojiapi: prefix all routes with /api/composer-koji/v1
The cloud API will be moved to `/api/composer/v1` in the future.

Mention this in the `servers` section of the openapi.yml (relative URLs
are allowed) too, even though our generator does not consider it.
2020-09-24 21:08:56 +01:00
Lars Karlitski
a8ba969f6e worker: prefix all routes with /api/worker/v1
Mention this in the `servers` section of the openapi.yml (relative URLs
are allowed) too, even though our generator does not consider it.
2020-09-24 21:08:56 +01:00