<@ULVA73B9P> I'm deploying Prefect flows from Circ...
# marvin-ai
t
@Marvin I'm deploying Prefect flows from CircleCI to an ECS Push work pool. The deployment is successfull, i see that the flows are deployed in prefect ui, but when i run a job i get the error [Errno 2] No such file or directory: '/home/circleci/project/....'. Why is it trying to use the CircleCI deployment path instead of the ECS container path?
m
thought for 530.7 seconds
Short version: your deployment is pointing to an absolute path from your CI workspace. In an ECS push pool, that path does not exist in the container, so the engine can’t load your flow file and you get “[Errno 2] No such file or directory: '/home/circleci/project/…'”. Why it happens - If you pass an absolute entrypoint like
/home/circleci/project/flows.py:my_flow
(via
prefect deploy
or Python), that absolute path is baked into the deployment and used at run time. - Or if you don’t configure storage/pull steps (e.g.,
flow.from_source(...)
), your code is never cloned into the ECS container; even a relative entrypoint will fail because the file isn’t there. - In push pools, there isn’t a “CircleCI workspace” in the container. The container only sees what’s in the image + what Prefect pulls at runtime via pull steps. The working directory defaults to the image’s WORKDIR (e.g.,
/opt/prefect
in Prefect images) unless you set it with a pull step. How to fix it (pick one) 1) Recommended: deploy from a source repo (Git) with a relative entrypoint - Use
flow.from_source(...)
so Prefect creates the right pull steps and a relative entrypoint; Prefect will clone your repo into the container at run time and set the working directory accordingly.
Copy code
from prefect import flow

@flow
def my_flow():
    print("Hello from ECS!")

# Run this from CircleCI or locally
flow.from_source(
    source="<https://github.com/your-org/your-repo.git>",
    entrypoint="src/flows.py:my_flow"   # RELATIVE path inside the repo
).deploy(
    name="ecs-deployment",
    work_pool_name="your-ecs-push-pool",
    # optionally pin an image:
    # image="prefecthq/prefect:3.1-python3.11"
)
2) Alternatively: bake code into your image and keep the entrypoint relative - COPY your code into the image at a known path (e.g.,
/opt/prefect/app
) and set
WORKDIR
there in the Dockerfile. - Keep your deployment entrypoint relative (e.g.,
src/flows.py:my_flow
) so the engine resolves it relative to the WORKDIR. - If you need to, add a
set_working_directory
pull step to point to that folder. Quick checks to confirm the problem - Inspect your deployment to see what Prefect will try to load:
Copy code
prefect deployment inspect <flow-name>/<deployment-name>
Look for: - entrypoint: should be relative like
src/flows.py:my_flow
, not
/home/circleci/project/...
- pull steps: should include a Git clone (if using from_source) or a
set_working_directory
pointing to where code lives - path: for storage-based deployments, you’ll see
$STORAGE_BASE_PATH
(that’s correct) If your entrypoint is absolute (contains
/home/circleci/project
), redeploy with a relative entrypoint and either: - use
flow.from_source(...)
, or - ensure your image contains the code and the working directory matches where the code is copied. Notes specific to ECS push pools - There isn’t a dedicated “working_dir” job variable in the ECS push pool config. Working directory is determined by your image’s WORKDIR or by adding a
set_working_directory
pull step. - The engine resolves the flow using a relative entrypoint and the working directory set at runtime (via pull steps), not the CI path. If you can share: - How you created the deployment (Python
flow.from_source(...).deploy(...)
or
prefect deploy
) - The exact entrypoint string you used - Whether you’re using a custom image or the Prefect image - Your
prefect.yaml
(if applicable) …I can point out the precise line to change. Useful docs - Serverless (ECS) deployments: https://docs.prefect.io/v3/how-to-guides/deployment_infra/serverless/ - Store and retrieve flow code (from_source, pull steps): https://docs.prefect.io/v3/how-to-guides/deployments/store-flow-code/ - Pull steps API reference (git_clone, set_working_directory, etc.): https://docs.prefect.io/v3/api-ref/python/prefect-deployments-steps-pull/
t
@Marvin if in my dockerfile i set a
Copy code
WORKDIR /app
should i then add in the prefect.yaml the following?
Copy code
...
pull:
    - prefect.deployments.steps.set_working_directory:
        directory: /app

deployments:
....
will this override the circle ci path?
m
thought for 45.3 seconds
Short answer: setting WORKDIR /app in your image is good, but adding a set_working_directory pull step will not “override” an absolute entrypoint from CircleCI. It only affects how relative paths are resolved. If your deployment’s entrypoint is absolute (e.g., /home/circleci/project/flows.py:my_flow), the engine will still try that path and fail. What to do - If code is baked into the image: - Keep WORKDIR /app in your Dockerfile. - Make sure your deployment entrypoint is relative to /app, e.g. src/flows.py:my_flow. - You can omit pull steps entirely. Adding the pull step below is harmless but redundant:
Copy code
pull:
      - prefect.deployments.steps.set_working_directory:
          directory: /app
- If code is pulled at runtime (recommended for push pools): - Use flow.from_source(..., entrypoint="src/flows.py:my_flow") so Prefect generates the correct pull steps and a relative entrypoint. - Optionally add set_working_directory to point to the folder where the code ends up. With from_source, Prefect handles this for you and you typically don’t need to hardcode /app. Verify and fix the root cause - Inspect your deployment:
Copy code
prefect deployment inspect <flow-name>/<deployment-name>
- entrypoint should be relative like src/flows.py:my_flow (not /home/circleci/project/…) - pull steps should exist if you’re not baking code into the image - If you see an absolute CircleCI path in entrypoint, redeploy with a relative entrypoint (and either bake code into the image at /app or use from_source so the code is cloned into the container). Docs - Serverless (ECS) deployments: https://docs.prefect.io/v3/how-to-guides/deployment_infra/serverless/ - Store and retrieve flow code (from_source, pull steps): https://docs.prefect.io/v3/how-to-guides/deployments/store-flow-code/ - Pull steps reference (set_working_directory, git_clone, etc.): https://docs.prefect.io/v3/api-ref/python/prefect-deployments-steps-pull/ If you share your current prefect.yaml (entrypoint and pull sections) and whether your code is in the image or pulled from Git, I can suggest the exact minimal edits.