Commit graph

471 commits

Author SHA1 Message Date
Lars Karlitski
e5eb673be6 distro: rename awkwardly named function
WithSingleDistro() doesn't follow go's naming convention for creating
objects (New*). Rename it to NewRegistry() and rename the old
NewRegistry() to NewDefaultRegistry().

The idea is that NewRegistry() can be used to create full Registry
objects from outside the package. NewDefaultRegistry() is a convenience
function that creates a Registry with all known distros.
2020-03-03 11:53:06 +01:00
Lars Karlitski
60301df8f7 rpmmd: pass in cache directory explicitly
rpmmd looked at the CACHE_DIRECTORY environment variable to set a path
for the dnf repository cache.  Aside from being a smelly thing to do
from a library, this breaks osbuild-pipeline and osbuild-dnf-json-tests,
which don't run as systemd services and thus don't have CACHE_DIRECTORY
set.

Explicitly pass the cache directory to rpmmd. Keep using a path based on
CACHE_DIRECTORY for osbuild-composer. Use the user's `.cache` directory
for osbuild-pipeline and a temporary directory for the tests.
2020-03-02 20:58:39 +01:00
Ondřej Budai
5e6103f4a8 fix composer immediately exiting
I broke it in d7cbc22d, there shouldn't be a goroutine.
2020-03-02 19:40:13 +01:00
Tom Gundersen
0b3d2be698 dnf-json: avoid randomizing package order
We want depsolving via dnf-json, followed by rpm installation to be
the same as installing directly with dnf. However, the `install_set()`
helper we used inserts the list of packgaes into a set internally
before returning it to us to iterate. Set order iteration is not
a FIFO in python, and because the order of package installation
in rpm is only a partial order, we ended up with different images
depending on whether we installed through dnf or dircetly via rpm.

To avoid the indirection via a set, open-code `install_set()` without
the intermediate allocation.

Signed-off-by: Tom Gundersen <teg@jklm.no>
2020-03-02 17:44:36 +01:00
Tom Gundersen
1ce84a5eff dnf-json: mark as executable
Allow this helper to be used easily in other scripts.

Signed-off-by: Tom Gundersen <teg@jklm.no>
2020-03-02 17:44:36 +01:00
Ondřej Budai
6a37883c1e spec: move worker-related service units to worker sub-package
Prior this commit installing the worker sub-packages shows the following
warning:

Failed to preset unit: Unit file osbuild-worker@.service does not exist.

Moving the unit file to the sub-package fixes it.
2020-03-02 14:29:38 +01:00
Ondřej Budai
d7cbc22da4 lint: fix unhandled errors 2020-03-02 14:28:55 +01:00
Ondřej Budai
9bef739621 lint: remove dead code 2020-03-02 14:28:55 +01:00
Ondřej Budai
8dfe5ec25c ci/lint: disable govet/composites 2020-03-02 14:28:55 +01:00
Ondřej Budai
3032abfdbe lint: fix gosimple/S1028 errors 2020-03-02 14:28:55 +01:00
Ondřej Budai
b7875db046 lint: fix gosimple/S1011 errors 2020-03-02 14:28:55 +01:00
Ondřej Budai
efb100fbca lint: fix gosimple/S1005 errors 2020-03-02 14:28:55 +01:00
Ondřej Budai
1676cf58da lint: fix gosimple/S1004 errors 2020-03-02 14:28:55 +01:00
Ondřej Budai
1937fc07af lint: fix gosimple/S1002 errors 2020-03-02 14:28:55 +01:00
Ondřej Budai
6fb44e140f ci/lint: show all errors
golangci-lint hides errors if there are a lot of them. I think it's more
convenient for the CI to show them all, so we can fix them all at once.
2020-03-02 14:28:55 +01:00
Ondřej Budai
7de9b88a3e ci: add golangci-lint 2020-03-02 14:28:55 +01:00
Jacob Kozol
2a3a5b318b distro: add rhel-8.1 support
Images can be built for rhel 8.1. The pipeline generation and distro
tests are based off of the rhel 8.2 ones. Repository information as been
added for rhel 8.1. The repo urls are internal ones and will only work
if the user is on the Red Hat vpn.
2020-02-29 01:17:50 +01:00
Ondřej Budai
0dcd16aa36 tests: begin rewriting of ./test/run test suite to Go
./test/run test suite has served us well over the last months. However,
there is currently a major effort to run the better defined integration
test suite on a CI. Nonetheless, two very important parts are still missing
from the integration test suite: inspecting the image with image-info
and booting the image. This commit begins the work on this matter by porting
a part of ./test/run suite to Go. Currently, only image-info tests work, the
rest will come in the following commits.
2020-02-26 16:58:39 +01:00
Ondřej Budai
9e505b6659 distro: add public method for getting the host distro name
It will be useful in integration testing.
2020-02-26 16:58:39 +01:00
Ondřej Budai
80f0888896 cmd/composer: move currentArch helper to common package
The helper function might be useful also in different parts of the project.
2020-02-26 16:58:39 +01:00
Lars Karlitski
740fb77d64 weldr: ensure passing valid package-specs to dnf-json
If no packages are included in a blueprint, the slice remains `nil`,
which translates to `null` in json. Always initialize the slice by
pointing it to an empty array.
2020-02-26 16:19:35 +01:00
Lars Karlitski
75fa08d383 rpmmd: panic when CACHE_DIRECTORY is not set
This can happen when CacheDirectory= is missing from the service file.
That's unlikely to happen, but it's hard to figure out what caused the
failure when it does. Be explicit and panic.
2020-02-26 15:53:48 +01:00
Brian C. Lane
58839cf927 Use semver to enforce blueprint version numbers
This changes osbuild-composer's behavior to match lorax-composer when
encountering invalid versions. Instead of leaving them as-is it will
return a BlueprintError explaining the problem. eg.

"errors": [
    {
        "id": "BlueprintsError",
        "msg": "Invalid 'version', must use Semantic Versioning:  is not in dotted-tri format"
    }
]

This is enforced on new blueprints (including the workspace). If a
previously stored blueprint has an invalid version and a new one is
pushed it will use the new version number instead of trying to bump the
invalid one.

This also moves the version bump logic into blueprint instead of store,
and adds an Initialize function that will make sure that the blueprint
has sane default values for any missing fields.

This includes tests for the Initialize and BumpVersion functions.
2020-02-25 09:00:35 +01:00
Brian C. Lane
8e1bc2b644 Return Blueprint push errors via the API
This adds returning errors from the store PushBlueprint* functions, and
adds handling of the errors to the API code in preparation for new code
to check the blueprint before saving it.
2020-02-25 09:00:35 +01:00
Ondřej Budai
b2f360da46 update osbuild submodule
Due to the change in commit b3ae34b07 in osbuild repository, the tests
had to be slightly modified.
2020-02-24 20:17:50 +01:00
Alexander Todorov
841885c1b4 tests: Build all available image types during integration test
comparing to lorax-composer test suite only ext4-filesystem and
partitioned-disk are built without asserting anything other than
the build succeeds. For the rest of the images we usually try to
boot them and verify the resulting VM works somehow.
2020-02-24 16:40:42 +01:00
Tom Gundersen
ca599a8f6f 6
Signed-off-by: Tom Gundersen <teg@jklm.no>
2020-02-24 16:25:13 +01:00
Martin Sehnoutka
5b67a5947c cmd/osbuild-composer: run RCM socket from a separate unit
Right now the implementation expects the RCM socket to live in the same
unit file as other osbuild-composer sockets. This would require a
solution where we ship the osbuild-composer.socket in two different
versions: one for regular usage, one for rcm. But that is very
inconvenient and it would probably require some weird scriptlets (and
scriptlets are bad!).

After this change, the RCM API socket lives in a separate file and only
if the socket unit is activated, the API runs. The unit file itself was
introduced in previous commits.
2020-02-24 12:03:25 +01:00
Martin Sehnoutka
6f5a2d9dcb gitignore: ignore directories used for RPM build 2020-02-24 12:03:25 +01:00
Martin Sehnoutka
28a1230105 spec: create rcm subpackage
We don't want to ship the RCM API socket unit in the main
osbuild-composer package. This way it will be only available in the -rcm
subpackage.
2020-02-24 12:03:25 +01:00
Martin Sehnoutka
c8ea14e561 distribution: socket unit for RCM API 2020-02-24 12:03:25 +01:00
Martin Sehnoutka
1e2ef9ada1 rpmmd: fix LoadRepositories in case no valid path is provided
The LoadRepositories function interates over a list of paths and expects
to find a distro configuration in one of them. The case when no path
with valid configuration is found was not handled. This patch introduces
the check.
2020-02-24 11:59:24 +01:00
Jakub Rusz
0a4ce9dc68 spec: fix osbuild version dependency 2020-02-20 18:14:24 +01:00
Tom Gundersen
44c03cf61e dnf-json: make cachedir mandatory
Without passing in a cachedir, dnf would create a random one for every
invocation. This meant that caches were never reused, nor cleaned up
properly.

Let systemd create a cache directory for us in /var/cache/ and use
that via the environment variable systemd sets for us.

Signed-off-by: Tom Gundersen <teg@jklm.no>
2020-02-20 15:26:54 +01:00
Tom Gundersen
8b7b592bd2 disbtribution/worker: drop cache directory
This is not currently used. Drop it for now, until we use it, and
when we do, it should be reintroduced with the right name, to avoid
clashing with osbuild-composer (they are owned by different users,
so cannot be shared).

Signed-off-by: Tom Gundersen <teg@jklm.no>
2020-02-20 15:26:54 +01:00
Ondřej Budai
04c0becd67 spec: Split the worker into its own rpm subpackage
As the worker can now be running on a different machine than the composer
it makes sense to install only worker binary on some machines. This commit
does exactly that - worker is now its own subpackage with the beautiful name
of golang-github-osbuild-composer-worker.

The main osbuild-composer package requires the worker subpackage, therefore
there will always be worker installed with composer. When composer is started
one local worker process will be spawned. If you don't want the default
worker process you need to mask its unit file:

systemctl mask osbuild-worker@1.service
2020-02-20 13:47:59 +01:00
Ondřej Budai
820d23fd9d Add tcp and tls support for worker and job API
There's a usecase for running workers at a different machine than
the composer. For example when there's need for making images for
architecture different then the composer is running at. Although osbuild has
some kind of support for cross-architecture builds, we still consider it
as experimental, not-yet-production-ready feature.

This commit adds a support to composer and worker to communicate using TCP.
To ensure safe communication through the wild worlds of Internet, TLS is not
only supported but even required when using TCP. Both server and client
TLS authentication are required. This means both sides must have their own
private key/certificate pair and both certificates must be signed using one
certificate authority. Examples how to generate all this fancy crypto stuff
can be found in Makefile.

Changes on the composer side:
When osbuild-remote-worker.socket is started before osbuild-composer.service,
osbuild-composer also serves jobqueue API on this socket. The unix domain
socket is not affected by this changes - it is enabled at all times
independently on the remote one. The osbuild-remote-worker.socket listens
by default on TCP port 8700.

When running the composer with remote worker socket enabled, the following
files are required:
- /etc/osbuild-composer/ca-crt.pem     (CA certificate)
- /etc/osbuild-composer/composer-key.pem (composer private key)
- /etc/osbuild-composer/composer-crt.pem (composer certificate)

Changes on the worker side:
osbuild-worker has now --remote argument taking the address to a composer
instance. When present, the worker will try to establish TLS secured TCP
connection with the composer. When not present, the worker will use
the unix domain socket method. The unit template file osbuild-remote-worker
was added to simplify the spawning of workers. For example

systemctl start osbuild-remote-worker@example.com

starts a worker which will attempt to connect to the composer instance
running on the address example.com.

When running the worker with --remote argument, the following files are
required:
- /etc/osbuild-composer/ca-crt.pem     (CA certificate)
- /etc/osbuild-composer/worker-key.pem (worker private key)
- /etc/osbuild-composer/worker-crt.pem (worker certificate)

By default osbuild-composer.service will always spawn one local worker.
If you don't want it you need to mask the default worker unit by:
systemctl mask osbuild-worker@1.service

Closing remarks:
Remember that both composer and worker certificate must be signed by
the same CA!
2020-02-20 13:47:59 +01:00
Ondřej Budai
412ce45667 worker: Remove unused -C argument
It isn't defined anywhere in the code, therefore it had no effect in the
unit file.
2020-02-20 13:47:59 +01:00
Ondřej Budai
2d09f7c27f Add missing PHONY targets to Makefile 2020-02-20 13:47:59 +01:00
Martin Sehnoutka
923a0b0b97 rcm: introduce rpmmd member of the api structure
This is needed for unit tests, because it wasn't possible to mock the
rpmmd module before. This also requires that the checksum is moved to
the compose request and evaluated in the endpoint handler instead of
push compose. I think it makes sense to have the checksum in the compose
request directly.

Also a "module platform ID" is required now, but we don't have the
"global" distribution any more, so this patch introduces mapping from a
distribution to the module platform ID.
2020-02-20 13:04:28 +01:00
Martin Sehnoutka
d1c766abe7 Makefile: include tests in make build
When I run make build I expect to build all the code we have to make
sure it still compiles just fine.
2020-02-20 13:04:28 +01:00
Martin Sehnoutka
f1b5ee8859 rpmmd: rename fetchpackagelist to fetchmetadata
the name was misleading because the function could do more than just
download package list. In PushComposeRequest it is also used to fetch
checksums for the repositories, therefore I decided to rename it to
reflect this usage.
2020-02-20 13:04:28 +01:00
Martin Sehnoutka
18ad83d43d cmd/dnf-json-tests: use defer 2020-02-20 13:04:28 +01:00
Martin Sehnoutka
2f0eed14c6 store: fetch checksums for requested repositories
previously these were provided, but in case of RCM API they are not,
therefore we fetch them automatically
2020-02-20 13:04:28 +01:00
Martin Sehnoutka
e791f51e2e rcm: use pushcomposerequest instead of pushcompose
the new version is better suited for the need of this API
2020-02-20 13:04:28 +01:00
Martin Sehnoutka
d758a7ba1b rcm: use custom types in the RCM compose request
The change also requires customizations in the error handling, as some
errors are now handled automatically by the custom unmarshaler.

Include a note about HTTP return types.
2020-02-20 13:04:28 +01:00
Martin Sehnoutka
5b0611983a common: fix bug in architecture ToString implementation
it used a wrong mapping, replace it with the right one
2020-02-20 13:04:28 +01:00
Martin Sehnoutka
6b957f01a0 common: fix method signature for UnmarshalJSON
There was a bug in the previous implementation which used to pass the
argument as a value but that does not work because we need to change the
value of it. The new implementation uses pass by reference.

Create a test to cover this scenario.
2020-02-20 13:04:28 +01:00
Martin Sehnoutka
251d63c06a osbuild-tests: create repository test
this test will create a temporary directory, create repo inside, then
fetch the checksum, and finally clean up the directory
2020-02-20 13:04:28 +01:00
Martin Sehnoutka
4c7b52ce2f rpmmd: create fetchchecksum method for repoconfig
this is needed for RCM API because the user will provide only the URL
and we need to fetch the checksum ourselves
2020-02-20 13:04:28 +01:00