Skip to content

Conversation

pingsutw
Copy link
Member

@pingsutw pingsutw commented Oct 8, 2025

This pull request adds support for using private base images when building and running Flyte tasks, allowing users to specify registry secrets for authentication. The main changes introduce a new workflow for handling private registries, update the Image class to accept and propagate registry secrets, and ensure secrets are used during image build and runtime. The example demonstrates how to use these features.

Support for private image registries:

  • Added an example (examples/image/private_base_image.py) showing how to build and run a Flyte task using a private base image, including instructions for creating and using a registry secret.
  • Updated the Image class (src/flyte/_image.py) to accept a registry_secret parameter in relevant methods (from_debian_base, from_uv_script, clone) and propagate it internally for use during image build/pull. [1] [2] [3] [4] [5] [6]
  • Modified the remote image builder (src/flyte/_internal/imagebuild/remote_builder.py) to use the registry secret when building images and to properly construct the target image reference for private registries. [1] [2]

Secret handling improvements:

  • Enhanced secret creation logic (src/flyte/remote/_secret.py) to set project/domain only for regular secrets, allowing image pull secrets to be global. [1] [2]

Internal code improvements:

  • Added _image_registry_secret attribute to the Image class for tracking registry secrets and updated method signatures and docstrings to document the new parameter. [1] [2] [3]
import flyte
from flyte import Image

image = (
    Image.from_base("pingsutw/private:d1742efed83fc4b18c7751e53e771bbe")
    .clone(registry="docker.io/pingsutw", name="private", registry_secret="pingsutw")
    .with_apt_packages("vim")
    .with_local_v2()
)

env = flyte.TaskEnvironment(name="private-image", image=image, secrets="pingsutw")


@env.task
async def t1(data: str = "hello") -> str:
    return f"Hello {data}"


if __name__ == "__main__":
    flyte.init_from_config()
    run = flyte.run(t1, data="world")
    print(run.name)
    print(run.url)

@pingsutw pingsutw marked this pull request as draft October 8, 2025 07:48
registry: Optional[str] = None,
name: Optional[str] = None,
platform: Optional[Tuple[Architecture, ...]] = None,
secret: Optional[SecretRequest] = None,
Copy link
Contributor

Choose a reason for hiding this comment

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

call it pull_secret? or something more clear that this is for pulling? or is this for pushing? Is it possible to use one secret to pull and another secret to push?

Also this new field(s) should be in every from_ function right?

Copy link
Member Author

@pingsutw pingsutw Oct 8, 2025

Choose a reason for hiding this comment

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

or something more clear that this is for pulling? or is this for pushing?

for both

Signed-off-by: Kevin Su <[email protected]>
Signed-off-by: Kevin Su <[email protected]>
Signed-off-by: Kevin Su <[email protected]>
Signed-off-by: Kevin Su <[email protected]>
@pingsutw pingsutw marked this pull request as ready for review October 9, 2025 00:51
domain = cfg.domain
else:
secret_type = definition_pb2.SecretType.SECRET_TYPE_IMAGE_PULL_SECRET
project = None
Copy link
Contributor

Choose a reason for hiding this comment

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

raise an error if project/domain are set

Copy link
Member Author

Choose a reason for hiding this comment

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

done

kumare3
kumare3 previously approved these changes Oct 9, 2025
Use the same registry secret in the task environment to ensure the container
can pull the private image during task execution.
"""
env = flyte.TaskEnvironment(name="private-image", image=image, secrets="pingsutw")
Copy link
Contributor

Choose a reason for hiding this comment

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

wait so you have to declare it twice?

Copy link
Member Author

Choose a reason for hiding this comment

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

one is for task, another one is for remote builder

"""
from flyte.remote import Secret

project = "" if project is None else project
Copy link
Contributor

Choose a reason for hiding this comment

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

this seems weird... why?

Copy link
Member Author

Choose a reason for hiding this comment

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

We don't want to use project/domain in the config by default. If it's none, we should create a global secret

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.

3 participants