Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build ostree images that depend on commits #37

Merged
merged 20 commits into from
Aug 1, 2023

Conversation

achilleas-k
Copy link
Member

@achilleas-k achilleas-k commented Jul 20, 2023

This PR adds image building to CI for image types that require pulling an ostree commit. The whole process of how this works is described in the update test README.

Copying the description of the relevant stage here:
The new stage of the workflow runs the ./test/generate-ostree-build-config script. It has the same purpose as the config generator for the regular builds, but it sets up ostree containers to serve commits to generate manifests for the image types that depend on them.

The config generator:

  • Generates all the manifests for build config dependencies for a given architecture using the ./cmd/gen-manifests tool.
    • Build config dependencies are image type and config pairings that appear in the depends part of a build config .
    • For example iot-ostree-pull-empty will cause a manifest to be generated for iot-container with the empty config for all distros.
  • Determines the container name and tag from the build name and manifest ID and pulls each container from the registry.
  • Runs each container with a unique port mapped to the internal web service port.
  • For each build config that defines a dependency and for each image that config applies to, creates build configs and a config map that defines the URL, port, and ref for the ostree commit source.
    • For example, the config iot-ostree-pull-empty is mapped in the config-map to the image types iot-ami, iot-installer, iot-raw-image, and iot-vsphere. This will create four configs for each distro, one for each image type, that will all have ostree options to pull an ostree commit from an iot-container of the same distro.
  • Generates all the manifests defined in the config map that was generated in the previous step.
    • Note that this manifest generation step uses the -skip-noconfig flag, which means that any image type not defined in the map is skipped.
  • Downloads the test build cache.
  • Filters out any manifest with an ID that exists in the build cache.
  • For each remaining manifest, creates a build job which runs the ostree container that was used to generate the manifest and runs ./test/cases/build-image.sh script for a given distro, image type, and config file.
    • If no builds are needed, it generates a NullConfig, which is a simple shell runner that exits successfully. This is required because the child pipeline config cannot be empty.

@achilleas-k achilleas-k force-pushed the test/build-ostree branch 11 times, most recently from ba6a833 to 2605c7d Compare July 20, 2023 22:57
@achilleas-k achilleas-k marked this pull request as draft July 24, 2023 16:59
@achilleas-k achilleas-k force-pushed the test/build-ostree branch 7 times, most recently from 256fe03 to cb1d088 Compare July 30, 2023 11:43
@achilleas-k achilleas-k added the WIP+test Work in progress but run Gitlab CI. label Jul 30, 2023
@achilleas-k achilleas-k force-pushed the test/build-ostree branch 8 times, most recently from 1079e69 to c3d945d Compare July 31, 2023 11:56
@achilleas-k achilleas-k changed the title WIP: Build ostree images that depend on commits Build ostree images that depend on commits Jul 31, 2023
@achilleas-k achilleas-k removed the WIP+test Work in progress but run Gitlab CI. label Jul 31, 2023
@achilleas-k achilleas-k marked this pull request as ready for review July 31, 2023 14:27
test/generate-build-config Show resolved Hide resolved
test/README.md Show resolved Hide resolved
test/README.md Outdated Show resolved Hide resolved
@achilleas-k
Copy link
Member Author

Found a bug that only generates one ostree build job for each distro. Fixing now.

Moved common test functions to a new (single-file) importable python
module called imgtestlib.
These will be shared between the two config generators, the current one
and the one for ostree test generation.
New dynamic pipeline generator similar to test/generate-build-config but
for image types that require pulling an ostree commit.
The script filters out configs that do not specify a dependency.

The script first collects all dependency build configurations (for
example edge-container, empty.json) and generates their manifests to
calculate the manifest ID.  The manifest ID is used to find the
corresponding container in the gitlab registry, which should have
already been built.  For each config that specifies a dependency
(for example test/configs/edge-ostree-pull-empty.json) the container for
the dependency is pulled from the gitlab registry and launched in order
to generate manifests with ostree commit resolution enabled.

Each config with a dependency is rewritten with the URL for the
corresponding container.  Once the manifest generation is done, the
builds are filtered in the same was as they are in
test/generate-build-config: for any manifest ID not found in the build
cache, a job is added to the pipeline to build it.

The script does not yet write the gitlab pipeline file for the builds.

Note that this pipeline generator can only configure builds for the
architecture that it is running on since it needs to run containers for
a given architecture when generating manifests.
Use a context manager to start containers and stop them when exiting the
context.

Maintain an internal map of container names to ports to make sure we
don't run the same container multiple times.
Instead of a hard-coded skip list, decide what to skip based on the
config itself: if an ostree URL is specified, skip the test, unless
`skip_ostree_pull=False`.
When generating manifests to set up build configs, use temporary
directories to avoid contamination from previous builds, especially when
running locally (outside CI).
Write the build configurations for the dynamic pipeline.

The $PARENT_PIPELINE_ID will need to be set in the main .gitlab-ci.yml
so that the child pipeline can access artifacts from the parent
pipeline.

The child job configs aren't complete yet.  It still needs the command
to start the container for the build job and the config needs to be
written as an artifact for the child job to read.
Read and return the full manifest data and their IDs when generating
manifests.  This moves the ID calculation outside the filter function.
The generate-ostree-build-config script writes build configs in a
directory defined by the second command line argument.  Each config is
associated with a child build job and defines the ostree remote URL and
ref to pull the ostree commit from, matching the container pull and run
command in the pipeline configuration.
Install dependencies in the test job definition and not the build script
itself.  This makes the build script distro agnostic, in case we switch
certain runners to run in the shell runner for simplicity.

The build configs for the first child pipeline were also changed so that
the script is an array of commands instead of a multiline script.
Added new stages for the ostree build test generator and the dynamic
pipeline trigger jobs.

The generator script can only generate job configs for the architecture
it is running on so we need to run a separate job for each architecture.
Set PYTHONUNBUFFERED so that script output is printed to the CI log
without buffering/batching.
Drop unneeded print flushing.
Make the linter happy.
While the first child pipeline generator can generate configs for all
architectures, split it just like we do with the ostree pipeline
generator to share the work and speed up the manifest generation a bit.
Document how dynamic pipelines are created for our image build testing
in CI.
Link to example project that demonstrates the dynamic pipeline
generation feature of GitLab CI.  This can help understand how we
generate the pipelines in this repo and can also be used to test
configuration changes quickly.
@achilleas-k
Copy link
Member Author

Found a bug that only generates one ostree build job for each distro. Fixing now.

Fixed and amended.
Diff from rebase: https://github.com/osbuild/images/compare/f03bb326e8356ecc1b3f1fcb492594131c359f0f..bc31f9312f5877e5f037300e9db45486780fa801 (in case it gets lost in other force pushes or rebases).

Copy link
Member

@thozza thozza left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM FAICT...

@achilleas-k achilleas-k added this pull request to the merge queue Aug 1, 2023
Merged via the queue into osbuild:main with commit bd96419 Aug 1, 2023
7 checks passed
@achilleas-k achilleas-k deleted the test/build-ostree branch August 1, 2023 17:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants