Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions src/hive_cli/utils/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
- '{}'
"""

Copy link
Copy Markdown
Contributor

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.,

BUILD_TEMPLATE = """
steps:
  - name: 'gcr.io/cloud-builders/docker'
    args: ['build', '-t', '{tag_name}', '.']
    env:
      - 'DOCKER_BUILDKIT=1'
images:
  - '{image_name}'
"""

then do

BUILD_TEMPLATE.format(tag_name=image, image_name=image)



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

Copilot AI Dec 4, 2025

Copy link

Choose a reason for hiding this comment

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

The cloudbuild.yaml file is created but never cleaned up after the build completes. Consider using a try-finally block to ensure the temporary file is removed, or use tempfile.NamedTemporaryFile for automatic cleanup.

Copilot uses AI. Check for mistakes.

cmd = ["gcloud", "builds", "submit", "--config", build_yaml_path, "."]

Copilot AI Dec 4, 2025

Copy link

Choose a reason for hiding this comment

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

The command hardcodes '.' as the source directory, but should use the context parameter to maintain consistency with the function's design. Change '.' to context.

Suggested change
cmd = ["gcloud", "builds", "submit", "--config", build_yaml_path, "."]
cmd = ["gcloud", "builds", "submit", "--config", build_yaml_path, context]

Copilot uses AI. Check for mistakes.
print(f"Cloud image build command: {' '.join(map(str, cmd))}")

try:
subprocess.run(
cmd,
check=True,
capture_output=True,

Copilot AI Dec 4, 2025

Copy link

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.

Suggested change
capture_output=True,

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
Contributor

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,
        )

text=True,
cwd=context,
)
except subprocess.CalledProcessError as e:
print("Build STDERR:\n", e.stderr)
raise
Loading