Commit graph

384 commits

Author SHA1 Message Date
Ondřej Budai
6902f730cb worker: upload local target image using jobqueue api
Prior this commit local target copied the image from a worker to a composer
using cp(1) command. This prevented the local target to work on remote
workers.

This commit switches the local target implementation to using the jobqueue
API introduced in the previous commit. I had some concerns about speed
of this solution (imho nothing can beat pure cp(1) implementation) but
ad hoc sanity tests showed the copying of the image using the jobqueue API
when running the worker on the same machine as the composer is still
more or less instant.
2020-02-14 11:53:38 +01:00
Ondřej Budai
98aac91083 api/jobqueue: add route to upload images 2020-02-14 11:53:38 +01:00
Ondřej Budai
08c5eaf6a6 store disk artifacts per image build instead of per compose
In #221 Compose was refactored: Now it can have multiple image builds. More
image builds result in more jobs. Each job has its own result (logs from
osbuild). Additionally, also targets are now a part of image build. With
local target this effectively means we can have multiple images per compose.

However, these artifacts (images & results) were stored only per compose
prior this commit, thus rendering the behaviour of composes with multiple
image builds undefined and racy.

This commit fixes it by storing all the artifacts per image build instead of
per compose. To achieve this feature, getComposeDirectory and
getImageBuildDirectory methods were created to centralize the path assembly.

Paths to artifacts prior this commit:
${COMPOSER_STATE_DIR}/outputs/${COMPOSE_ID}/*

Paths to artifacts after this commit:
${COMPOSER_STATE_DIR}/outputs/${COMPOSE_ID}/${IMAGE_BUILD_ID}/*
2020-02-14 11:53:38 +01:00
Ondřej Budai
b64bbaa0bb api/jobqueue: move build id to url
Imho it makes more sense from REST perspective. Also, in the future there
will be ROUTE for uploading image to image build. As it's not a good idea
transport file inside JSON, all the parameters (compose id and image
build id) need to be inside the URL. Therefore for the sake of consistency,
all these routes should have compose id and image build id in the URL.

There is another solution to embedding multiple values inside http body
which allows file transport - multipart/form-data. I think using form-data
is worth when doing more complex stuff, for our usecase transporting all
the metadata in the URL is more appropriate solution.
2020-02-14 11:53:38 +01:00
Ondřej Budai
188b24e26e api/jobqueue: actually write errors to response body if any occur 2020-02-14 11:53:38 +01:00
Ondřej Budai
cc00e0cdc9 drop the Compose.Image field
Everything that this field contained can be computed in another way:

- path: just lookup the local target and read the path from there
- mime: can be derived from distribution and compose output type
- size: can be derived from the path

Therefore it imho doesn't make much sense to store these information multiple
times.
2020-02-14 11:53:38 +01:00
Ondřej Budai
a9633d29e9 weldr: clean up the image size code
There's no connection between user-specified image size and actual image
size (which might differ du to a compression). Therefore, it's not needed
to check if the actual image exists if we want to return just the
user-specified size.
2020-02-14 11:53:38 +01:00
Jacob Kozol
238d2b562e weldr: add filtering to compose route
When requesting the compose status, a user may want to filter the list
of composes by blueprint name, compose status, and/or compose type. These
filters can now be set in the /compose/status route's url as the queries
blueprint, status, and type.
2020-02-12 19:23:40 +01:00
Jacob Kozol
c312f40d27 weldr/tests: fix indentation of expected aws compose
The Blueprint struct is misaligned, increase its indentation by 4.
2020-02-12 19:23:40 +01:00
Ondřej Budai
3e7a96e5ea api/jobqueue: return 500 error when updating job unexpectedly failed
Prior this commit these errors would just disappear.
2020-02-12 11:18:02 +01:00
Martin Sehnoutka
05b1093170 osbuild-pipeline: use the new types 2020-02-12 11:17:26 +01:00
Martin Sehnoutka
f4f8603db5 osbuild-compose: store now takes a distro registry
previously it took only a single distro, but now it requires the whole
registry
2020-02-12 11:17:26 +01:00
Martin Sehnoutka
edf081153a distro: remove previous implementation of testing distro
See internal/distro/fedoratest for a replacement
2020-02-12 11:17:26 +01:00
Martin Sehnoutka
83afb1f821 target: use the new types from common package 2020-02-12 11:17:26 +01:00
Martin Sehnoutka
ab6b6da76c Weldr API: use the new compose/store API
The compose now contains multiple image builds, but Weldr API does not
support this feature. Use the first image build every time.

Also start using the new types instead of plain strings.
2020-02-12 11:17:26 +01:00
Martin Sehnoutka
962365251d store: refactor compose handling
All the preceding changes in jobqueue, compose package, common types
etc. were a base for refactoring the store so that a compose can handle
multiple image builds. This commit introduces the change in a backwards
compatible way, so that the weldr api don't change.
2020-02-12 11:17:26 +01:00
Martin Sehnoutka
d02bac15fe distro: use the new types in distro packages
Each distro is now represented by a strongly typed value but it can also
provide its name as a string.
2020-02-12 11:17:26 +01:00
Martin Sehnoutka
80e01bb397 jobqueue: include image build id
The compose will soon move to a concept of including multiple image
builds per one compose, we need to accommodate extra identifier to
handle this scenario.
2020-02-12 11:17:26 +01:00
Martin Sehnoutka
73994eb06d distro/fedoratest: create new testing distribution
The problem with the previous one was that we used artifical image
types, architectures, and distribution but that is not possible any more
because we don't want to use plain strings any more. This commit
introduces a new testing distro which uses proper, existing types.
2020-02-12 11:17:26 +01:00
Martin Sehnoutka
eb6c0f6fce compose: refactor compose related structure into its own package
The store package is getting too big and convoluted, this new package
will help with separation of the compose logic from our current
implementation of the store.

The current implementation will be removed in following commits.
2020-02-12 11:17:26 +01:00
Martin Sehnoutka
62d186cd1b common: refactor build states into a separate file
These states will be used for tracking the image builds and compose
states in the rest of our codebase. There should be no change in the
behavior. It is a 1 to 1 replacement with the only difference of using
type alias instead of plain string.
2020-02-12 11:17:26 +01:00
Martin Sehnoutka
9c91b12076 common: compose request should include full bp and repositories
we want to move to a state where composer is a stateless service,
therefore we cannot take blueprints by name (and fetch them from a
storage) or assume repositories by the distribution. This commit
introduces both of these parameters as part of the structure.
2020-02-12 11:17:26 +01:00
Martin Sehnoutka
cffa74f0a1 common: extend common types with helper functions
It is very common that a string is required in the rest of our code and
also for user input/output. These helper functions will make this easy.
2020-02-12 11:17:26 +01:00
Martin Sehnoutka
7f66147888 RCM API: return bad request instead of internal server error
push compose returns nil in case of any error, until we can
differentiate between internal server error and bad request, just return
bad request
2020-02-12 11:17:26 +01:00
Martin Sehnoutka
76947da8d5 RCM API: drop the checksum requirement for submit
The repositories used by RCM never change, there is no need for them to
include checksum of the repository.

Also rework the tests as the store will change in following commits
(store now needs to include a registry of all distros because we can do
cross-distro builds)
2020-02-12 11:17:26 +01:00
Jacob Kozol
abb5469b30 distro: get proper image size from distro
When a user does not define the image size for a compose the default
image size of that image type is used. In order to properly store the
compose's image size even if the default is used the store calls the
distro function GetSizeForOutputType. This function accepts an output
format and image size. If the image size is 0 then the default
value for the output format will be returned. Also, for vhd images the
size must be rounded. This is now handled in the distro function instead
of the api.
2020-02-07 14:49:15 +01:00
Jacob Kozol
e30f40873d store: add image size to compose
When a use defines the image size for a compose this size is stored in
the compose struct so that the virtual image size can be returned by the
api instead of the file size of the image.
2020-02-07 14:49:15 +01:00
Brian C. Lane
8c19364b65 api: Add TOML support for workspace POST
composer-cli pushes blueprints to the workspace using TOML not JSON.
This also adds a test.
2020-02-07 00:16:16 +01:00
Ondřej Budai
8781d41da6 worker: normalize Job.Run() return types 2020-02-05 01:35:50 +01:00
Ondřej Budai
0d4479bbcd worker: save result.json in the composer instead of the worker
In the future remote workers will be introduced. Obviously, the remote worker
cannot support the local target. Unfortunately, the current implementation of
storing the osbuild result is dependant on it.

This commit moves the responsibility of storing osbuild result to the
composer process instead of the worker process. The result is transferred from
a worker to a composer using extended HTTP API.
2020-02-05 01:35:50 +01:00
Ondřej Budai
a43dd00459 move ComposeResult type into common package to allow its reusing 2020-02-05 01:35:50 +01:00
Brian C. Lane
642b90c977 Switch blueprint commit to use a random SHA-1
Generating a SHA-1 based on time is not safe. A collision can easily be
generated, and if parallel operations are used they will eventually
collide. This reads random bytes and uses them for the SHA-1 hash. It
will return an error if the rand.Read() fails.
2020-02-04 09:10:38 +01:00
Brian C. Lane
c054015440 Change ownership of the output directory immediately
Otherwise if there is an error creating result.json or if the Run
command failed it will remain owned by root.root and cannot be deleted
via the API.

Closes #204
2020-01-31 20:34:48 +01:00
Ondřej Budai
679c8c40cd osbuild-pipeline: Search the current dir for repository configs
We treat the osbuild-pipeline as a tool run only within the source, therefore
we should search for the repository configs only in the current directory.
2020-01-31 12:44:59 +01:00
Martin Sehnoutka
b0ddbc744a osbuild-pipeline: improve CLI interface
In the current state, osbuild-pipeline exits with random golang error,
such as goroutine failed, which is not at all helpful. This PR
introduces CLI arguments validation and helful error messages that use
the newly introduced types so that we don't waste time guessing what
was the right way to invoke this tool.
2020-01-30 15:17:05 +01:00
Martin Sehnoutka
8dac72f4fd internal: propose custom types for image types, arches, etc.
We currently use strings for passing arches and image types around,
which is not ideal. We should have a finite set of supported image types
and architectures as well as upload targets. This PR introduces custom
types to make the code base more readable and possibly also more
correct.

I considered some alternatives like a struct with private fields, but struct cannot
be const, so that does not help either. Eventually I think this is the "get s**t done"
solution.

The package also includes unit-tests which try to convert string to
structure and the other way around to make sure it all works properly.
2020-01-30 14:42:25 +01:00
Martin Sehnoutka
aab8a4d305 crypt: make it possible to compile and test on macOS
Our current crypt implmentation requires glibc to be available on the
developer's system. But it is not strictly necessary, because I'd like
to run at least unit tests on mac. This PR makes it possible to compile
and run unit-tests on mac, but it will panic if someone tries to run
osbuild-composer on mac.
2020-01-30 14:42:25 +01:00
Martin Sehnoutka
7bdd51cd23 README: Define terminology as a base for internal refactoring 2020-01-30 14:42:25 +01:00
Jacob Kozol
b81dc53442 api: add custom image size for composes
When creating a compose the desired image size can be set. If the image
type is a VHD the image size is rounded up to the nearest MB since all
VHDs on Azure must have a virtual size aligned to 1 MB.
2020-01-23 00:57:31 +01:00
Jacob Kozol
e3d64ea1eb store: custom image size
When pushing a compose to the store an image size can be included in the
parameters.
2020-01-23 00:57:31 +01:00
Jacob Kozol
a86e697171 distro: add custom image size
When creating a pipeline the assembler includes an image size. This
image size can be set when creating the pipeline but if it is 0 then a
default image size will be used. The default is 2 GB except for ami
images which are 6 GB.
2020-01-23 00:57:31 +01:00
Jacob Kozol
481c1dd048 osbuild-composer: fix number of listeners check
Osbuild-composer expects two or three listeners and fails if there is
an unexpected number of listening sockets. Checking if there are not two
or if there are not three listeners always returns true even if there are
the desired number of listeners. Therefore, osbuild-composer always
crashes. The check now only crashes if there are a number of listeners
other than 2 or 3.
2020-01-16 18:21:28 +01:00
Ondřej Budai
6b662663f3 upload/aws: Add basic S3 upload test
The test is very simple, it just uploads object to S3, downloads it back and
compares them.
2020-01-16 13:14:15 +01:00
Martin Sehnoutka
4f63b54a16 Introduce RCM API
It contains two basic endpoints:
 * POST /v1/compose
 * GET /v1/compose/<uuid>
It passes all the tests, but cannot be used for the intended use case
because the store API does not (yet) support distributions and
architectures as a parameters.
2020-01-15 15:46:52 +01:00
Tom Gundersen
02a194f612 tests: add basic integration tests
Introduce a new osbuild-tests command and ship it in the -tests
sub-package.

The intended usecase is to install the -tests subpackage into an
otherwise pristine VM, and call the osbuild-tests binary over ssh
from the outside of the booted VM. If the binary exits with a return
code of 0, the tests passed, otherwise they failed. The VM should
not be reused after running the tests.

Signed-off-by: Tom Gundersen <teg@jklm.no>
2020-01-03 22:35:52 +01:00
Tom Gundersen
fb7fb0156d store: keep our state to ourselves
Our state directory can contain credentials, so do not allow access
to anyone else.

Signed-off-by: Tom Gundersen <teg@jklm.no>
2020-01-03 22:35:52 +01:00
Tom Gundersen
4919ef1271 repositories: install the base repositories in the filesystem
During development of a new distro, we need to test composer against
nightly or beta repositories, but we cannot ship composer itself
with the nightly repository information hardcoded in. At the same
time, we want to distinguish between the system repositories of the
host and the repositories we use to generate images (the host may not
use the same distro/version/architecture as the target, and it may
include custom repositories that the target should not).

We therefore ship per distro repository information that can be
overriden (typically in testing) by dropping files in /etc.

For now use the latest nightlies for RHEL-8.2, we may want to
replace these with the official mirrors for GA eventually.

Signed-off-by: Tom Gundersen <teg@jklm.no>
2020-01-03 22:35:52 +01:00
Tom Gundersen
2059f9500b distro/test: flesh out the test distro abit and use it for testing
We were using fedora-30 as a test-distro and tar as test-output, but
that causes lots of churn in the tests when we refactor things. Use
the test distro instead, when generic functionality is being tested
and restrict testing of the individual distros to the distro-specific
tests.

Signed-off-by: Tom Gundersen <teg@jklm.no>
2020-01-03 22:35:52 +01:00
Tom Gundersen
5fcdd4bea5 distro: don't use a global variable to store the distro register
Introduce a DistroRegister object. For now this does not introduce
any functional changes, as the object is always instantited to be
the same. However, in follow-up patches it will get options.

Signed-off-by: Tom Gundersen <teg@jklm.no>
2020-01-03 22:35:52 +01:00
Martin Sehnoutka
6c49560479 update readme to contain slightly more information 2020-01-03 12:49:55 +01:00