-
Notifications
You must be signed in to change notification settings - Fork 5
Add helper for local dev workflow #203
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
Draft
modulo11
wants to merge
4
commits into
main
Choose a base branch
from
dev-workflow
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| import subprocess | ||
| import json | ||
| import sys | ||
| import questionary | ||
|
|
||
| from ruamel.yaml import YAML | ||
|
|
||
| from pathlib import Path | ||
|
|
||
|
|
||
| def get_bake_config() -> dict: | ||
| result = subprocess.run(["docker", "buildx", "bake", "--print"], capture_output=True, text=True, check=True) | ||
| return json.loads(result.stdout) | ||
|
|
||
|
|
||
| def find_matches(values: dict, image_name: str) -> list: | ||
| image_key_paths = [] | ||
| for component, component_values in values.items(): | ||
| if isinstance(component_values, dict): | ||
| repo = component_values.get("image", {}).get("repository", "") | ||
| if repo.endswith(image_name): | ||
| image_key_paths.append(component) | ||
| return image_key_paths | ||
|
|
||
|
|
||
| def check_cluster(): | ||
| temp_path = Path("temp") | ||
| if not temp_path.exists(): | ||
| print("Before running this script, please run `make up` to create the cluster.") | ||
| sys.exit(1) | ||
|
|
||
|
|
||
| def build_instructions(project): | ||
| tags = bake_config.get("target", {}).get(project, {}).get("tags", []) | ||
| latest_tag = next((tag for tag in tags if tag.endswith(":latest")), None) | ||
| if not latest_tag and len(tags) < 2: | ||
| raise ValueError(f"No tag ending with ':latest' found for project {project}") | ||
| image_name = latest_tag.split(":")[0] | ||
|
|
||
| update_values(image_name) | ||
|
|
||
| print(f"docker buildx bake {project} --set {project}.contexts.src=<path-to-{release}-release>/src") | ||
| print(f"kind load docker-image {latest_tag} --name cfk8s") | ||
|
|
||
|
|
||
| def update_values(image_name): | ||
| yaml = YAML() | ||
| yaml.preserve_quotes = True | ||
| yaml.representer.add_representer(type(None), lambda dumper, _: dumper.represent_scalar("tag:yaml.org,2002:null", "~")) | ||
|
|
||
| values_path = Path(f"releases/{release}/helm/values.yaml") | ||
|
|
||
| with open(values_path, "r") as f: | ||
| values = yaml.load(f) | ||
|
|
||
| for match in find_matches(values, image_name): | ||
| keys = match.split(".") | ||
| target = values | ||
| for key in keys: | ||
| target = target[key] | ||
|
|
||
| target["image"]["repository"] = image_name | ||
| target["image"]["tag"] = "latest" | ||
|
|
||
| with open(values_path, "w") as f: | ||
| yaml.dump(values, f) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| check_cluster() | ||
|
|
||
| bake_config = get_bake_config() | ||
| all_releases = bake_config.get("group", {}).get("all", {}).get("targets", []) | ||
|
|
||
| all_releases.remove("cflinuxfs4") | ||
| all_releases.remove("fileserver") | ||
| all_releases.remove("bosh-dns") | ||
|
|
||
| release = questionary.select("Which release are you working on?", choices=all_releases).ask() | ||
|
|
||
| all_projects = bake_config.get("group", {}).get(release, {}).get("targets", []) | ||
|
|
||
| # single project releases are not included in the targets group | ||
| if not all_projects: | ||
| all_projects.append(release) | ||
|
|
||
| default_choices = [questionary.Choice(title=project, checked=True) for project in all_projects] | ||
| projects = questionary.checkbox("Which project(s) are you working on?", choices=default_choices).ask() | ||
|
|
||
| print("Here are some instructions to build a local image and load it into the cluster. Make sure to replace <path-to-release> with the actual path to the release you are working on.") | ||
| print("Docker will ask for confirmation to access the local file system, please allow it to do so.") | ||
| print() | ||
| for project in projects: | ||
| build_instructions(project) | ||
| print("make up") | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we align it with the docs/local-development-guide? There, we do not use
make up, but change it in the cluster.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes of course. I just wanted to get feedback on the idea and approach before touching too many parts.