-
Notifications
You must be signed in to change notification settings - Fork 4
Adds functionality to build Docker images using gcloud build. This do… #83
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -53,3 +53,40 @@ def build_image( | |||||
| except subprocess.CalledProcessError as e: | ||||||
| print("Build STDERR:\n", e.stderr) | ||||||
| raise | ||||||
|
|
||||||
|
|
||||||
| BUILD_TEMPLATE = """ | ||||||
| steps: | ||||||
| - name: 'gcr.io/cloud-builders/docker' | ||||||
| args: ['build', '-t', '{}', '.'] | ||||||
| env: | ||||||
| - 'DOCKER_BUILDKIT=1' | ||||||
| images: | ||||||
| - '{}' | ||||||
| """ | ||||||
|
|
||||||
|
|
||||||
| def build_image_in_cloud(image: str, context: str = ".") -> None: | ||||||
| """Build a Docker image in GC Build and push it to Container Registry.""" | ||||||
| # For now we use subprocess to call gcloud CLI because the Python SDK does | ||||||
| # not support building a local directory. | ||||||
|
|
||||||
| build_yaml = BUILD_TEMPLATE.format(image, image) | ||||||
| build_yaml_path = f"{context}/cloudbuild.yaml" | ||||||
| with open(build_yaml_path, "w", encoding="utf-8") as f: | ||||||
| f.write(build_yaml) | ||||||
|
Comment on lines
+75
to
+77
|
||||||
|
|
||||||
| cmd = ["gcloud", "builds", "submit", "--config", build_yaml_path, "."] | ||||||
|
||||||
| cmd = ["gcloud", "builds", "submit", "--config", build_yaml_path, "."] | |
| cmd = ["gcloud", "builds", "submit", "--config", build_yaml_path, context] |
Copilot
AI
Dec 4, 2025
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.
Using capture_output=True suppresses real-time build output, making it difficult to monitor long-running cloud builds. Consider using capture_output=False or streaming output to provide better user feedback during the build process.
| capture_output=True, |
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 try to stream this output to logger? I think for build_image we previously had something like
if logger.isEnabledFor(logging.DEBUG):
capture_output = False
else:
capture_output = True
subprocess.run(
cmd,
check=True,
capture_output=capture_output,
text=True,
)
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.
We can label the
{}fields with variable names to make it a bit more readable, e.g.,then do