Commit graph

696 commits

Author SHA1 Message Date
Ondřej Budai
a504fc8801 spec: add weldr provide
Since the recent commit (04db4fa) we are no longer provider
of lorax-composer. This was needed because when installing cockpit-composer,
which depends on lorax-composer, dnf chose us as the lorax-composer provider
instead of the original lorax-composer package. As we are not yet ready to
fully replace lorax-composer, this broke the cockpit-composer tests.

This commit is the first part of long term fix. Osbuild-composer is now
a provider of weldr. Soon, lorax-composer will also be a provider of
weldr. After that, cockpit-composer will be switched to be depending
on weldr. Also, it will suggest lorax-composer, which will force dnf
to use lorax-composer as the default weldr backend. If someone wants
to experiment with osbuild-composer, it will be possible, because
it will also be a provider of weldr and there will be no need to
install lorax-composer to satisfy cockpit-composer dependencies.
2020-03-05 15:39:08 +01:00
Lars Karlitski
04db4fa3f5 spec: remove lorax-composer provide
We're not fully compatible with lorax-composer's API yet, and we don't
provide lorax-composer's systemd unit files.

As a result, cockpit-composer's integration tests fail, because `dnf
install lorax-composer` on Fedora can result in installing
osbuild-composer in some cases.
2020-03-05 11:04:30 +01:00
Lars Karlitski
132554d015 Makefile: simplify make rpm
Prior to this patch, `make rpm` would produce rpms that have the latest
tag as their versions. This was confusing, because one could never know
which contents are in a locally built rpm.

Change this so that the is version always based on the commit hash of
HEAD. This is easy: the golang macros read a `%commit` macro when it
exists and do this for us.

To simplify more, only define `%_topdir` to ./rpmbuild and use
rpmbuild's known directory structure (SPEC, SOURCES, RPMS, ...)
otherwise, to make it easier to find build results.

Build the specfile, tarball, source rpms, and rpms with `make rpm`,
without separate sub-targets. We can reintroduce them if they're needed
somewhere.

Also remove the `check-working-directory` target. It should be clear
from the output that only the currently-committed files are included,
because the resulting tarball and rpms contain the commit hash. Without
the check, one can work on the Makefile without having to commit all the
time, for example ;)
2020-03-04 23:06:37 +01:00
Alexander Todorov
44889842bd Add instructions how to install build-deps in test/README
serves as a reference and will also help less experienced folks
2020-03-04 19:56:25 +01:00
Jacob Kozol
4690320503 blueprint: add default version
If the user creates a new blueprint with no version specified, the
blueprint struct uses "0.0.0" as the default version. Blueprint tests
for a blueprint with an empty version now expect no error.
2020-03-04 19:20:58 +01:00
Tom Gundersen
571932db37 job: pass manifest instead of pipeline to osbuild
This is not a behavioral change, as all distros currently use
empty source objects. But when we move over to rpm-based pipelines,
this will change.

Make the same change to osbuild-pipeline, so these stay in sync.

Signed-off-by: Tom Gundersen <teg@jklm.no>
2020-03-03 22:25:49 +01:00
Tom Gundersen
919c484c79 distro: add Manifest method to interface
For now, this simply wraps Pipeline and Sources, and retruns the
resulting manifest object. In the future, Pipeline and Sources
may be dropped from the interface.

Signed-off-by: Tom Gundersen <teg@jklm.no>
2020-03-03 22:25:49 +01:00
Tom Gundersen
4da1ab03b3 osbuild: introduce manifest concept
A manifest is simply a struct containing a sources and a pipeline
object. We want to store and transfer pielines always with their
sources, and will use the manifest for this.

When serialized, a manifest can be the input to `osbuild`, just
like a bare pipeline can be. This means there will be no need
to pass in sources separately on the commandline.

Signed-off-by: Tom Gundersen <teg@jklm.no>
2020-03-03 22:25:49 +01:00
Major Hayden
7af12f6ce6 📦 Add RPM builds via github actions
Unify the github actions workflows under `tests.yml` and add an RPM build
job to match the one for osbuild.

Signed-off-by: Major Hayden <major@redhat.com>
2020-03-03 21:06:04 +01:00
Brian C. Lane
b9eb01c9d3 Add osbuild-weldr-tests command 2020-03-03 18:30:21 +01:00
Lars Karlitski
17ca73ab14 osbuild-pipeline: validate distro when fetching it
We were verifying two things: if the passed distroArg exists in the
distribution mapping in common/types.go and if the it is an actually
registered distro. Since you cannot have distros registered that don't
correspond to a type, the first test is unnecessary.

Merge the two tests by moving the (much better) error message down into
the second test. This makes DistributionExists redundant, because
Registry.GetDistro() checks this implicitly.

Also, move ListDistributions() to the Registry object, because we want
to show distributions that are actually registered.

Add a test which checks that Registry.List() works and that all included
distributions register correctly.
2020-03-03 16:21:13 +01:00
Lars Karlitski
db95328ab6 osbuild-pipeline: remove stray comment 2020-03-03 16:21:13 +01:00
Ondřej Budai
284e9b9e53 fix linter errors
#261 was created before the introduction of the linter, therefore it wasn't
approved by it. This commit fixes all the introduced linter violations.
2020-03-03 14:26:13 +01:00
Lars Karlitski
cdcb6c2f84 distribution: set CACHE_DIRECTORY in the .service file
systemd >= 240 sets this variable to `/var/cache/` + the value of
CacheDirectory. osbuild-composer must run on earlier versions though
(specifically RHEL 8.2).
2020-03-03 14:25:26 +01:00
Brian C. Lane
9dafb3337b Refactor error handling in the client code
client errors are now returned as an 'error', API errors as APIResponse.
2020-03-03 12:21:40 +01:00
Brian C. Lane
57f0892d93 weldr: Return blueprint changes in descending timestamp order 2020-03-03 12:21:40 +01:00
Brian C. Lane
cce9a2712c Fix Blueprint Revision, it is an integer not a string
This changes it to an int pointer so that the JSON will output null.
This means it needs to be checked for nil or for 0 in go.

0 is not a valid revision in the WELDR response, they always start at 1
and increment for each new revision tag so either way is a valid way
to indicate it isn't set.
2020-03-03 12:21:40 +01:00
Brian C. Lane
2d4e4d14d0 Add osbuild-weldr-tests to run the weldr integration tests
This runs tests against a running API server, either lorax-composer or
osbuild-composer, and reports the results to stdout. It uses the
/run/weldr/api.socket to communicate with the server.
2020-03-03 12:21:40 +01:00
Brian C. Lane
f298fed16d Add weldrcheck package to hold the integration tests
These tests build on the client functions to run integration tests on a
running API server.

It uses the reflect module to examine the methods attached to the
checkBlueprintsV0 struct and run the ones with names that start with
'Check', also checking the type signature of the functions and failing
the test if any of them don't match.

This will make it easier to add more checks without needing to add
boilerplate call/registration of the functions in the top level runner.
Just add the new function with the right name and signature and it will
be run when checkBlueprintsV0.Run() is called.

Checks for other API routes should be added to their own modules. There
will be some duplication of the Run function in each, but I think that
it will help keep things more manageable by separating them instead of
putting them all into a single giant Run() call.
2020-03-03 12:21:40 +01:00
Brian C. Lane
ea1b633d3a Add exported response structures for API results
Currently the responses are all embedded in the weldr API functions.
They need to be usable by the client helper functions so I'm copying
them here and giving them names.

A later commit will go through the API can refactor it to use these
instead of the embedded ones.
2020-03-03 12:21:40 +01:00
Brian C. Lane
f0ddb3d866 client: Add tests for the core client functions 2020-03-03 12:21:40 +01:00
Brian C. Lane
cfa4233db5 client: Add client helper functions for API testing and future cli tools
This package will contain functions for communicating with the API that
can be used in both the integration tests as well as in a future cmdline
tool similar to composer-cli

When possible the client functions will return the same structures used
by weldr/api.go which have been exported in weldr/json.go
2020-03-03 12:21:40 +01:00
Lars Karlitski
87e9c39532 distro: panic less often
Return errors from all distro's New() functions instead of logging and
returning nil. Also, return errors instead of panicking from
NewRegistry() and NewDefaultRegistry().
2020-03-03 11:53:06 +01:00
Lars Karlitski
d1965d6268 distro/*: don't go via Registry object in tests
These packages (and their tests) shouldn't access the distro package,
because that's cyclic.

Also, these packages should only test the objects they expose.
2020-03-03 11:53:06 +01:00
Lars Karlitski
ee3ef81714 distro: implement NewDefaultRegistry in terms of NewRegistry()
This makes it more apparent that NewDefaultRegistry() is a convenience
function and gets rid of a helper.
2020-03-03 11:53:06 +01:00
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