Skip to content

feat: print callback for docker image build#481

Open
qwertycxz wants to merge 2 commits intoagentscope-ai:mainfrom
qwertycxz:master
Open

feat: print callback for docker image build#481
qwertycxz wants to merge 2 commits intoagentscope-ai:mainfrom
qwertycxz:master

Conversation

@qwertycxz
Copy link
Copy Markdown
Contributor

@qwertycxz qwertycxz commented Apr 10, 2026

Description

Make print not a bare function, but a callback function which we could determine in BuildConfig.

我想就不要用一个裸的 print 了,可以将其修改成一个回调函数,允许我们在 BuildConfig 中指定。

Related Issue: Fix #480

Security Considerations: None, I suppose

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation
  • Refactoring

Component(s) Affected

  • Engine
  • Sandbox
  • Tools
  • Common
  • Documentation
  • Tests
  • CI/CD

Checklist

  • Pre-commit hooks pass
  • Tests pass locally
  • Documentation updated (if needed)
  • Ready for review

Testing

Add a print=foo param in app.deploy().

app.deploy() 中加入 print 参数即可测试。

Additional Notes

Unless explicitly set, there is no change in behavior.

除非显式设置,否则行为上没有改变。

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds a configurable output callback for Docker image build/push streaming output, replacing direct print() calls so callers can intercept and process docker build/docker push logs (Issue #480).

Changes:

  • Add a print callback to ImageConfig and BuildConfig, defaulting to the built-in print.
  • Route streamed docker build output through config.print(...) instead of calling print(...) directly.
  • Update push_image to accept build_config (instead of a quiet boolean) and route docker push streaming output through the configured callback.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 6 comments.

File Description
src/agentscope_runtime/engine/deployers/utils/docker_image_utils/image_factory.py Adds a configurable print callback into image build configuration passed to the Docker builder.
src/agentscope_runtime/engine/deployers/utils/docker_image_utils/docker_image_builder.py Uses the callback for streaming output and refactors push_image to accept full build configuration.

Comment on lines 33 to 36
no_cache: bool = False
quiet: bool = False
print: Callable[[str], None] = print
build_args: Dict[str, str] = {}
Copy link

Copilot AI Apr 10, 2026

Choose a reason for hiding this comment

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

print as a model field name is likely to trigger pylint's redefined-builtin (W0622), which will fail pre-commit unless suppressed. Consider either renaming the field to something like output_callback (and using a Pydantic alias so callers can still pass print=...), or add a targeted # pylint:disable=redefined-builtin for this file/class attribute.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Comment on lines 176 to 182
while True:
output = process.stdout.readline()
if output == "" and process.poll() is not None:
break
if output:
print(output.strip())
config.print(output.strip())

Copy link

Copilot AI Apr 10, 2026

Choose a reason for hiding this comment

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

This new output callback path isn’t covered by tests: existing tests only exercise quiet=True (subprocess.run) and won’t catch regressions in streaming mode. Add a unit test for quiet=False that mocks subprocess.Popen stdout and asserts the configured callback is invoked with streamed lines.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Not a part of my PR.

Comment on lines 292 to 298
while True:
output = process.stdout.readline()
if output == "" and process.poll() is not None:
break
if output:
print(output.strip())
build_config.print(output.strip())

Copy link

Copilot AI Apr 10, 2026

Choose a reason for hiding this comment

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

Streaming output in push_image now goes through the callback, but there’s no test coverage for this path. Add a unit test that mocks subprocess.Popen for docker push and asserts build_config.print (or the configured callback) receives the streamed output lines when quiet=False.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Not a part of my PR.

Comment on lines 52 to 56
# Build configuration
no_cache: bool = False
quiet: bool = False
print: Callable[[str], None] = print
build_args: Dict[str, str] = {}
Copy link

Copilot AI Apr 10, 2026

Choose a reason for hiding this comment

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

print as a model field name is likely to trigger pylint's redefined-builtin (W0622), which will fail pre-commit unless suppressed. Consider renaming the field to something like output_callback (and using a Pydantic alias so callers can still pass print=...), or add a targeted # pylint:disable=redefined-builtin for this file/class attribute.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] process docker build outputs instead of just printing them

2 participants