Commit graph

457 commits

Author SHA1 Message Date
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
Brian C. Lane
b89475506e Add Epoch to blueprints/freeze version string
If the Epoch is > 0 the it should be added to the front of the version,
separated by a colon.

Also include a depsolve package with a non-zero Epoch and adjust the
tests accordingly.
2020-02-19 23:44:17 +01:00
Brian C. Lane
8ccc95a473 Use Blueprint.DeepCopy for blueprints/freeze
Without making a deep copy of the blueprint the changes made to the
package and module versions will persist in memory, causing it to lose
the package and module version globs.

This can be seen by executing a freeze request and then a depsolve. The
blueprint included in the depsolve had the version globs replaced by the
frozen EVRA values.
2020-02-19 23:44:17 +01:00
Brian C. Lane
3ce066a91a Add DeepCopy function to Blueprint struct
The Blueprint struct is complex, deep, and full of references. This
means that any changes to it in memory will persist. Sometimes you need
an actual copy of it, so this adds DeepCopy which uses the json.Marshal
and Unmarshal functions to create a deep copy with no references to the
original.

This is not very efficient, but the alternative is adding Copy functions
to all the member structs and then calling them to build the copy.
2020-02-19 23:44:17 +01:00
Brian C. Lane
a84593645b Fix module support in blueprints/depsolve
This adds the modules to the list of package specs to be depsolved. It
includes a new function to build the version glob package string, as
well as tests for the new function and for depsolving with modules in
the blueprint.
2020-02-19 23:44:17 +01:00
Brian C. Lane
248f0a6d55 Fix module support in blueprints/freeze
This adds support for the modules field. It moves the version
replacement into a separate function, setPkgEVRA, and adds tests for the
new function as well as for blueprints with packages in both the
packages and modules lists.
2020-02-19 23:44:17 +01:00
Brian C. Lane
56e764a11d Fix /blueprints/freeze results
The dependencies are not sorted, so depending on what order they were
returned in the freeze route would or would not return the correct
results (exhibited by the version being the original glob instead of the
EVRA).

This also fixes the tests so that the depsolve results are slightly
unsorted by adding a dep-package3 to the start of the list.
2020-02-19 23:44:17 +01:00
Alexander Todorov
defc34b7f0 Add quick README about testing 2020-02-19 23:41:58 +01:00
Alexander Todorov
90bf26cc4b Requires osbuild>=7 because of the --build-env argument 2020-02-19 23:39:00 +01:00
Jacob Kozol
e9c2534eb3 osbuild-pipeline: pass default image size into pipeline
When creating a pipeline with the default image size, the size should no
longer be set to 0. Instead, the size is fetched using the distro
function GetSizeForOutputType which can return the default image size
for a given image type. This size can then be passed into the pipeline.
2020-02-19 23:38:31 +01:00
Brian C. Lane
422a25edad Use distro_mock in rcm API test 2020-02-19 23:37:45 +01:00
Brian C. Lane
cace702e9f Register Fedora 32 distro 2020-02-19 23:37:45 +01:00
Martin Sehnoutka
8e77e03284 distro: make it impossible to initialize registry with nil values
The current `NewRegistry` implementation allows for nil values in the
map, but this leads to subtle bugs when using the registry. This patch
enforces non-nil values by introducing additional checks before we
insert the value into the map.

The change unfortunately breaks a lot of tests and therefore it is
necessary to create additional mock: distro.

The new mock is used instead of the previous "real" implementation,
which used to contain nil values.
2020-02-19 23:37:45 +01:00
Jacob Kozol
fae51095d2 distro: add fedora 32 support
Images can be built for fedora 32. The pipeline generation and distro
 tests are based off of the fedora 30 ones. Repository information has
 also been added for the fedora 32 repos.
2020-02-19 14:18:58 +01:00
Jacob Kozol
bbbd9b9193 distro: add fedora 31 support
Images can be built for fedora 31. The pipeline generation and distro
tests are based off of the fedora 30 ones. Repository information has
also been added for the fedora 31 repos.
2020-02-18 12:34:17 +01:00