Skip to content

Commit e9b53a9

Browse files
authored
Add documentation for pipeline.py (#130)
# Summary - Add documentation for pipeline.py - Add env variables documentation used by `pipeline.py` for easier references. - Some docs were in wrong locations, likely merging errors. I've looked into the history and moved the to their original locations.
1 parent cabd7d0 commit e9b53a9

File tree

2 files changed

+110
-37
lines changed

2 files changed

+110
-37
lines changed

PIPELINE.md

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# Pipeline
2+
3+
## Environment Variables (env vars)
4+
5+
This listing contains all environment variables used in `pipeline.py`.
6+
Default evergreen-ci expansions can be looked up [here](https://docs.devprod.prod.corp.mongodb.com/evergreen/Project-Configuration/Project-Configuration-Files#expansions).
7+
8+
| Environment Variable | Usage / Description |
9+
|-------------------------------|------------------------------------------------------------------------------------|
10+
| `otel_trace_id` | OpenTelemetry tracing: trace ID. Default evergreen-ci expansion. |
11+
| `otel_parent_id` | OpenTelemetry tracing: parent span ID. Default evergreen-ci expansion. |
12+
| `otel_collector_endpoint` | OpenTelemetry tracing: collector endpoint. Default evergreen-ci expansion. |
13+
| `distro` | Image type (defaults to `ubi`) |
14+
| `BASE_REPO_URL` | Base repository URL for images |
15+
| `namespace` | Kubernetes namespace (defaults to `default`) |
16+
| `skip_tags` | Tags to skip during build |
17+
| `include_tags` | Tags to include during build |
18+
| `all_agents` | Whether to build all agent images |
19+
| `RUNNING_IN_EVG` | Whether running in Evergreen pipeline |
20+
| `is_patch` | Whether running as a patch build. Default evergreen-ci expansion. |
21+
| `pin_tag_at` | Time to pin image tag (format: `HH:MM`) |
22+
| `created_at` | Build creation time (format: `%y_%m_%d_%H_%M_%S`). Default evergreen-ci expansion. |
23+
| `triggered_by_git_tag` | Git tag that triggered the build. Default evergreen-ci expansion. Default evergreen-ci expansion. |
24+
| `version_id` | Patch ID or version for non-release builds. Default evergreen-ci expansion. |
25+
| `test_suffix` | Suffix for test images |
26+
| `LOG_AUTOMATION_CONFIG_DIFF` | Whether to log automation config diff |
27+
| `PYTHON_VERSION` | Python version for test images |
28+
| `GOLANG_VERSION` | Go version for community images and tests |
29+
| `QUAY_REGISTRY` | Quay registry URL (defaults to `quay.io/mongodb`) |
30+
| `REGISTRY` | ECR registry URL (defaults to `268558157000.dkr.ecr.us-east-1.amazonaws.com/dev`) |
31+
| `om_version` | Ops Manager version for OM image builds |
32+
| `om_download_url` | Download URL for Ops Manager (optional, can be auto-detected) |
33+
34+
## Context Image Build Process
35+
36+
```
37+
┌─────────────────────────────┐
38+
│ Release Pipeline │
39+
└────────────┬────────────────┘
40+
41+
42+
┌─────────────────────────────────┐
43+
│ Build context image │
44+
│ Tag: opsmanager-context:1.33.0 │
45+
└────────────┬────────────────────┘
46+
47+
48+
┌───────────────────────────────┐
49+
│ Daily Build │
50+
│ Base: opsmanager-context │
51+
│ Input tag: 1.33.0 │
52+
└────────────┬──────────────────┘
53+
54+
55+
┌────────────────────────────────────┐
56+
│ Push Two Image Tags │
57+
└────────────┬───────────────┬───────┘
58+
▼ ▼
59+
┌────────────────────────┐ ┌──────────────────────────────┐
60+
│ Rolling Tag (latest) │ │ Immutable Tag (daily stamp) │
61+
│ opsmanager:1.33.0 │ │ opsmanager:1.33.0-2025-01-01 │
62+
└────────────────────────┘ └──────────────────────────────┘
63+
64+
▼ (next day build)
65+
┌────────────────────────┐ ┌──────────────────────────────┐
66+
│ opsmanager:1.33.0 │ │ opsmanager:1.33.0-2025-01-02 │
67+
└────────────────────────┘ └──────────────────────────────┘
68+
↑ now updated to point ↑ new image pushed
69+
to the 2025-01-02 build
70+
```

pipeline.py

Lines changed: 40 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@ def get_release() -> Dict:
264264

265265

266266
def get_git_release_tag() -> tuple[str, bool]:
267+
"""Returns the git tag of the current run on releases, on non-release returns the patch id."""
267268
release_env_var = os.getenv("triggered_by_git_tag")
268269

269270
# that means we are in a release and only return the git_tag; otherwise we want to return the patch_id
@@ -290,22 +291,19 @@ def copy_into_container(client, src, dst):
290291
container.put_archive(os.path.dirname(dst), fd.read())
291292

292293

293-
"""
294-
Generates docker manifests by running the following commands:
295-
1. Clear existing manifests
296-
docker manifest rm config.repo_url/image:tag
297-
2. Create the manifest
298-
docker manifest create config.repo_url/image:tag --amend config.repo_url/image:tag-amd64 --amend config.repo_url/image:tag-arm64
299-
3. Push the manifest
300-
docker manifest push config.repo_url/image:tag
301-
"""
302-
303-
304-
# This method calls docker directly on the command line, this is different from the rest of the code which uses
305-
# Sonar as an interface to docker. We decided to keep this asymmetry for now, as Sonar will be removed soon.
306-
307-
308294
def create_and_push_manifest(image: str, tag: str, architectures: list[str]) -> None:
295+
"""
296+
Generates docker manifests by running the following commands:
297+
1. Clear existing manifests
298+
docker manifest rm config.repo_url/image:tag
299+
2. Create the manifest
300+
docker manifest create config.repo_url/image:tag --amend config.repo_url/image:tag-amd64 --amend config.repo_url/image:tag-arm64
301+
3. Push the manifest
302+
docker manifest push config.repo_url/image:tag
303+
304+
This method calls docker directly on the command line, this is different from the rest of the code which uses
305+
Sonar as an interface to docker. We decided to keep this asymmetry for now, as Sonar will be removed soon.
306+
"""
309307
final_manifest = image + ":" + tag
310308

311309
args = [
@@ -343,14 +341,12 @@ def try_get_platform_data(client, image):
343341
return None
344342

345343

346-
"""
347-
Checks if a docker image supports AMD and ARM platforms by inspecting the registry data.
348-
349-
:param str image: The image name and tag
350-
"""
351-
352-
353344
def check_multi_arch(image: str, suffix: str) -> bool:
345+
"""
346+
Checks if a docker image supports AMD and ARM platforms by inspecting the registry data.
347+
348+
:param str image: The image name and tag
349+
"""
354350
client = docker.from_env()
355351
platforms = ["linux/amd64", "linux/arm64"]
356352

@@ -741,17 +737,6 @@ def submit(self, fn, *args, **kwargs):
741737
return super().submit(lambda: fn(*args, **kwargs))
742738

743739

744-
"""
745-
Starts the daily build process for an image. This function works for all images we support, for community and
746-
enterprise operator. The list of supported image_name is defined in get_builder_function_for_image_name.
747-
Builds an image for each version listed in ./release.json
748-
The registry used to pull base image and output the daily build is configured in the image_config function, it is passed
749-
as an argument to the inventories/daily.yaml file.
750-
751-
If the context image supports both ARM and AMD architectures, both will be built.
752-
"""
753-
754-
755740
def should_skip_arm64():
756741
"""
757742
Determines if arm64 builds should be skipped based on environment.
@@ -766,7 +751,15 @@ def build_image_daily(
766751
max_version: str = None,
767752
operator_version: str = None,
768753
):
769-
"""Builds a daily image."""
754+
"""
755+
Starts the daily build process for an image. This function works for all images we support, for community and
756+
enterprise operator. The list of supported image_name is defined in get_builder_function_for_image_name.
757+
Builds an image for each version listed in ./release.json
758+
The registry used to pull base image and output the daily build is configured in the image_config function, it is passed
759+
as an argument to the inventories/daily.yaml file.
760+
761+
If the context image supports both ARM and AMD architectures, both will be built.
762+
"""
770763

771764
def get_architectures_set(build_configuration, args):
772765
"""Determine the set of architectures to build for"""
@@ -992,6 +985,11 @@ def build_image_generic(
992985
multi_arch_args_list: list = None,
993986
is_run_in_parallel: bool = False,
994987
):
988+
"""Build image generic builds context images and is used for triggering release. During releases
989+
it signs and verifies the context image.
990+
The release process uses the daily images build process.
991+
"""
992+
995993
if not multi_arch_args_list:
996994
multi_arch_args_list = [extra_args or {}]
997995

@@ -1011,8 +1009,12 @@ def build_image_generic(
10111009
# But since we don't run daily rebuilds on ecr image builds, we can do that step instead here.
10121010
# We only need to push manifests for multi-arch images.
10131011
create_and_push_manifest(registry_address, version, architectures=architectures)
1012+
1013+
# Sign and verify the context image if on releases if requied.
10141014
if config.sign and config.is_release_step_executed():
10151015
sign_and_verify_context_image(registry, version)
1016+
1017+
# Release step. Release images via the daily image process.
10161018
if config.is_release_step_executed() and version and QUAY_REGISTRY_URL in registry:
10171019
logger.info(
10181020
f"finished building context images, releasing them now via daily builds process for"
@@ -1546,11 +1548,12 @@ def calculate_images_to_build(
15461548

15471549
def main():
15481550
_setup_tracing()
1551+
_setup_tracing()
15491552

15501553
parser = argparse.ArgumentParser()
1551-
parser.add_argument("--include", action="append")
1552-
parser.add_argument("--exclude", action="append")
1553-
parser.add_argument("--builder", default="docker", type=str)
1554+
parser.add_argument("--include", action="append", help="list of images to include")
1555+
parser.add_argument("--exclude", action="append", help="list of images to exclude")
1556+
parser.add_argument("--builder", default="docker", type=str, help="docker or podman")
15541557
parser.add_argument("--list-images", action="store_true")
15551558
parser.add_argument("--parallel", action="store_true", default=False)
15561559
parser.add_argument("--debug", action="store_true", default=False)

0 commit comments

Comments
 (0)