<@ULVA73B9P> i do not get why i need to have the c...
# ask-marvin
o
@Marvin i do not get why i need to have the code locally when doing flow.deploy() when it is present in the image that will be deployed, is there any pracitcal reason for that?
m
thought for 414.1 seconds
Great question — this trips a lot of folks up. Short answer: By default,
flow.deploy()
assumes it should build and push an image from your current project directory and it needs to infer your flow’s entrypoint from the local code. That’s why it wants your code locally, even if your final image already contains it. What
flow.deploy()
uses local code for - Build context: With
build=True
(default), Prefect builds a Docker image using the current directory as the build context and copies your project into the image. - Entrypoint discovery: Prefect inspects the flow object to record how to load it at runtime (file path or module path). The default path is file-based, which depends on local files. Practical ways to avoid needing local code If your code is already baked into the image and you just want to register a deployment: 1) Use a prebuilt image and module-based entrypoint - Don’t build or push - Tell Prefect to use a module path instead of a file path
Copy code
from prefect import flow
from prefect.types.entrypoint import EntrypointType

@flow
def my_flow():
    ...

my_flow.deploy(
    name="prod",
    work_pool_name="my-pool",
    image="registry/myapp:1.2.3",
    build=False,
    push=False,
    entrypoint_type=EntrypointType.MODULE_PATH,  # uses package.module:flow_name
)
Requirements: - Your image must include the code as an importable module (e.g., installed via pip) and have the correct PYTHONPATH at runtime. 2) Use remote source instead of local files Point the deployment at Git/cloud storage so workers pull code at runtime:
Copy code
from prefect import flow

flow.from_source(
    source="<https://github.com/org/repo.git>",
    entrypoint="flows/my_flow.py:my_flow",
).deploy(
    name="prod",
    work_pool_name="my-pool",
    image="registry/myapp:1.2.3",
    build=False,
    push=False,
)
3) Run the deploy inside the environment that already has the code For example, in CI after checkout or inside the image itself, so the “local” project is available when deploying. Helpful docs - Deploy via Python: Deploy via Python - Store flow code (entrypoints, remote storage): Store flow code - Docker deployment details: Run flows in Docker containers If you can share your setup (prebuilt image? module installed? want zero local checkout?), I can suggest the exact
flow.deploy()
call for your case.