<#741 feat: add with_code_bundle to Image> Pull re...
# flyte-github
a
#741 feat: add with_code_bundle to Image Pull request opened by pingsutw from dep import foo import flyte env = flyte.TaskEnvironment( name="full_build", # with_code_bundle() automatically copies source code from root_dir into the image # when copy_style="none" is set in with_runcontext() or flyte deploy. When copy_style # is "loaded_modules" or "all", it's a no-op since the code is bundled separately. image=flyte.Image.from_debian_base().with_code_bundle(), ) @env.task def square(x) -> int: return x ** foo() @env.task def main(n: int) -> list[int]: return list(flyte.map(square, range(n))) if name == "__main__": flyte.init_from_config() run = flyte.with_runcontext(copy_style="none", version="x").run(main, n=10) print(run.url) Summary • Add
Image.with_code_bundle()
method that configures automatic source code baking into Docker images when
copy_style="none"
is set in
with_runcontext()
or
flyte deploy
• When
copy_style
is
"loaded_modules"
or
"all"
, the layer is a no-op since code is bundled separately • Supports two copy styles:
"loaded_modules"
(only imported Python modules) and
"all"
(entire root_dir) • Adds
resolve_code_bundle_layer()
integration in
_run_remote()
,
_run_hybrid()
, and
deploy.apply()
before image builds • Includes safety-net
RuntimeError
in
docker_builder
if a
CodeBundleLayer
reaches the build step unresolved • Updates the
full_build
example to use the new simplified API Test plan •
test_with_code_bundle_defaults
— creates CodeBundleLayer with correct defaults •
test_with_code_bundle_all
— stores
"all"
copy style •
test_with_code_bundle_custom_dst
— stores custom destination •
test_resolve_code_bundle_no_layers
— returns same object when no CodeBundleLayer present •
test_resolve_code_bundle_strips_when_not_none
— strips layers when copy_style != "none" •
test_resolve_code_bundle_strips_when_all
— strips layers when copy_style is "all" •
test_resolve_code_bundle_hash_stability
— stripped image URI matches base image URI •
test_resolve_code_bundle_all_copy_style_none
— replaces with CopyConfig for "all" + "none" •
test_resolve_code_bundle_loaded_modules_copy_style_none
— creates staging dir for "loaded_modules" + "none" • All 37 existing tests in
test_image.py
pass (no regressions) flyteorg/flyte-sdk