-
Notifications
You must be signed in to change notification settings - Fork 15
feat: add per-weblog metadata to control CI build requirement #7130
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
Merged
Merged
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
75a8140
feat: add per-weblog metadata to control CI build requirement
rochdev db0cc5b
fix: use general binaries_artifact when weblog requires no build
rochdev e6643c7
fix: decouple pre-build flag from local build flag in Weblog
rochdev 37ef339
refactor: replace needs_local_build with require_prebuild on Weblog
rochdev 2cc3e61
style: fix ruff formatting in workflow_data.py
rochdev f9cac90
Build metadata (#7137)
nccatoni dc55d06
removing json files
nccatoni 7d3047a
Run separate build job when building base images
nccatoni 3991e95
Merge branch 'main' into rochdev/weblog-build-metadata
nccatoni 338eae6
Merge branch 'main' into rochdev/weblog-build-metadata
nccatoni 55698db
Small revamp
cbeauchesne 4e49c43
Merge branch 'main' into rochdev/weblog-build-metadata
cbeauchesne b682fa6
format
cbeauchesne 0fe43e7
cleanups
cbeauchesne bc48412
revamp how base images are built
cbeauchesne f485c37
fix, and lint
cbeauchesne ad42976
Docstring
cbeauchesne c13a7f6
simplify
cbeauchesne 0d26755
cleam build base image in weblog job
cbeauchesne 4e72db5
generic logic
cbeauchesne 14987e8
Fix otel_collector
cbeauchesne 7d2709f
Merge branch 'main' into rochdev/weblog-build-metadata
cbeauchesne 9c6cf09
split weblog metadata file
cbeauchesne fda451c
Move doc into weblog folder
cbeauchesne File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| # Weblog metadata | ||
|
|
||
| Each library folder under `utils/build/docker/<library>/` may contain a `weblog_metadata.yml` file | ||
| that declares metadata for weblogs that cannot be inferred from the Dockerfile alone. | ||
|
|
||
| ## When to add an entry | ||
|
|
||
| A weblog discovered via a `<name>.Dockerfile` file defaults to `build_mode: prebuild` and no | ||
| `framework_versions`. Add an entry only when you need to override those defaults. | ||
|
|
||
| ## Format | ||
|
|
||
| ```yaml | ||
| <weblog-name>: | ||
| build_mode: none | local | prebuild # default: prebuild | ||
| framework_versions: ["1.0.0", ...] # optional; omit for non-integration-framework weblogs | ||
| ``` | ||
|
|
||
| The `library` field is intentionally absent — it is inferred from the folder the file lives in. | ||
|
|
||
| ## `build_mode` values | ||
|
|
||
| | Value | Meaning | | ||
| |-------|---------| | ||
| | `none` | No Docker build. The shared `binaries_artifact` is used as-is (integration frameworks, proxies). | | ||
| | `local` | The weblog has a fully baked base image. The build step inside the test job is trivial (only `COPY` instructions). No dedicated CI build job. | | ||
| | `prebuild` | Built ahead of time by a dedicated `build_end_to_end` CI job that uploads a per-weblog artifact; still built locally when the test job runs. | | ||
|
|
||
| Both `local` and `prebuild` set `weblog_build_required = true`. | ||
|
|
||
| ## Integration-framework weblogs | ||
|
|
||
| When `framework_versions` is set, a single entry fans out into one weblog per version at load time: | ||
|
|
||
| ```yaml | ||
| openai-js: | ||
| build_mode: none | ||
| framework_versions: ["6.0.0", "7.0.0"] | ||
| ``` | ||
|
|
||
| produces `openai-js@6.0.0` and `openai-js@7.0.0`. | ||
|
|
||
| ## Loader | ||
|
|
||
| `WeblogMetaData.load(library)` in `utils/_context/weblog_metadata.py` merges: | ||
| 1. Weblogs discovered from `*.Dockerfile` files in the library folder (default metadata). | ||
| 2. Explicit overrides from `weblog_metadata.yml`. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| from enum import StrEnum | ||
| from dataclasses import dataclass, replace | ||
| from pathlib import Path | ||
| import yaml | ||
|
|
||
|
|
||
| class BuildMode(StrEnum): | ||
| none = "none" | ||
| """ The weblog does not require any build step""" | ||
|
|
||
| local = "local" | ||
| """ The weblog has a fully baked base image, so the build step is extra light, | ||
| and does not requires a full job in the CI""" | ||
|
|
||
| prebuild = "prebuild" | ||
| """ The weblog will be built in a dedicated job in the CI """ | ||
|
|
||
|
|
||
| @dataclass | ||
| class WeblogMetaData: | ||
| name: str | ||
| library: str | ||
| build_mode: BuildMode = BuildMode.prebuild | ||
| framework_versions: list[str] | None = None | ||
| artifact_name: str = "" | ||
| """ not declared in the yml file, but populated later """ | ||
|
|
||
| def __post_init__(self): | ||
| self.build_mode = BuildMode(self.build_mode) | ||
|
|
||
| @property | ||
| def require_build(self) -> bool: | ||
| """The run_end_to_end job builds the weblog locally (weblog_build_required).""" | ||
| return self.build_mode != BuildMode.none | ||
|
|
||
| @property | ||
| def base_dockerfile(self) -> Path | None: | ||
| """Returns the path of the base image docker file if exists, else None""" | ||
| image_name = self.base_image_tag | ||
|
|
||
| if image_name is None: | ||
| return None | ||
|
|
||
| file_prefix = image_name.replace("datadog/system-tests:", "").rsplit("-", 1)[0] | ||
| assert file_prefix.endswith(".base") | ||
|
|
||
| path = Path(f"utils/build/docker/{self.library}/{file_prefix}.Dockerfile") | ||
| return path if path.exists() else None | ||
|
|
||
| @property | ||
| def base_image_tag(self) -> str | None: | ||
| """system-tests base image tag read from the first FROM in the weblog Dockerfile.""" | ||
| dockerfile = Path(f"utils/build/docker/{self.library}/{self.name}.Dockerfile") | ||
| if not dockerfile.exists(): | ||
| return None | ||
| for line in dockerfile.read_text().splitlines(): | ||
| if line.startswith("FROM "): | ||
| image_name = line.split()[1] | ||
| return image_name if image_name.startswith("datadog/system-tests:") else None | ||
| return None | ||
|
|
||
| @staticmethod | ||
| def _load_explicit_metadata(library: str) -> dict[str, "WeblogMetaData"]: | ||
| path = Path(f"utils/build/docker/{library}/weblog_metadata.yml") | ||
| if not path.exists(): | ||
| return {} | ||
|
|
||
| with path.open() as f: | ||
| data: dict = yaml.safe_load(f) or {} | ||
|
|
||
| return {name: WeblogMetaData(name=name, library=library, **kwargs) for name, kwargs in data.items()} | ||
|
|
||
| @staticmethod | ||
| def load(library: str) -> list["WeblogMetaData"]: | ||
| metadata = WeblogMetaData._load_explicit_metadata(library) | ||
| result: list[WeblogMetaData] = [] | ||
|
|
||
| folder = Path(f"utils/build/docker/{library}") | ||
| if folder.exists(): # some lib does not have any weblog | ||
| names = [ | ||
| f.name.replace(".Dockerfile", "") | ||
| for f in folder.iterdir() | ||
| if f.suffix == ".Dockerfile" and ".base." not in f.name and f.is_file() | ||
| ] | ||
| else: | ||
| names = [] | ||
|
|
||
| for name in set(names + [w.name for w in metadata.values() if w.library == library]): | ||
| item = WeblogMetaData(name=name, library=library) if name not in metadata else metadata[name] | ||
|
|
||
| # integration-framework weblogs fan out into one weblog per version; | ||
| # all other weblogs map to a single weblog. | ||
| if item.framework_versions: | ||
| for version in item.framework_versions: | ||
| sub_item = replace(item, name=f"{name}@{version}") | ||
| result.append(sub_item) | ||
| else: | ||
| result.append(item) | ||
|
|
||
| return result | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| x = WeblogMetaData.load("python") | ||
| from pprint import pprint | ||
|
|
||
| pprint(x) # noqa: T203 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| # docs/understand/weblogs/weblog-metadata.md | ||
|
|
||
| envoy: | ||
| build_mode: none |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| # docs/understand/weblogs/weblog-metadata.md | ||
|
|
||
| haproxy-spoa: | ||
| build_mode: none |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.