<@ULVA73B9P> I'm using kubernets as workpool to de...
# ask-marvin
l
@Marvin I'm using kubernets as workpool to deploy my flows. I have only one prefect.yaml with differents deployments with the same structure and workpool. I'll give one example about how im doing the prefect.yml The problem is that today my new deployments is finding a error "FileNotFoundError: [Errno 2] No such file or directory: '/app/flows/my_flow_test.py'" Thats something about my copy step. This is happening only for new deployments, the old ones, in the same structure is working #prefect.yaml name: reports-analytics prefect-version: 3.3.4 build: - prefect_docker.deployments.steps.build_docker_image: id: build-image requires: prefect-docker>=0.6.0 image_name: "{{ prefect.blocks.secret.docker-image }}" tag: "reports-analytics-{{ $PREFECT_GIT_COMMIT_SHA }}" dockerfile: ../Dockerfile platform: "linux/amd64" push: - prefect_docker.deployments.steps.push_docker_image: requires: prefect-docker>=0.6.0 image_name: "{{ build-image.image_name }}" tag: "{{ build-image.tag }}" pull: - prefect.deployments.steps.set_working_directory: directory: "/app" definitions: work_pool: &common_work_pool name: "my-kube" work_queue_name: "default" job_variables: image: "{{ build-image.image }}"
m
thought for 167.1 seconds
Thanks for the details — the error points to the image not containing your code at the path Prefect expects. In your setup, the Kubernetes job is starting in
/app
(because of your
set_working_directory
pull step), and the deployment’s entrypoint resolves to
/app/flows/my_flow_test.py
. Since the container can’t find that file, the issue is almost certainly with your Docker build context/COPY. Why this likely happens - Your build step uses
dockerfile: ../Dockerfile
but does not set the Docker build context (
path
). By default, the context is the directory where you run
prefect deploy
(typically where
prefect.yaml
lives). - Docker COPY paths are relative to the build context, not the Dockerfile location. If your repo looks like this: - repo_root/ - Dockerfile - flows/ - some_dir/prefect.yaml …then using
dockerfile: ../Dockerfile
with default context of
some_dir
means
COPY flows ...
won’t find
flows/
(it’s outside the context). - Older deployments may still work because they use older images that did contain the files; the new images are being built with the wrong context so the new flow files never make it into the image. Two solid fixes (pick one) 1) Keep the Dockerfile in the parent, set the context to the repo root
Copy code
build:
  - prefect_docker.deployments.steps.build_docker_image:
      id: build-image
      requires: prefect-docker>=0.6.0
      image_name: "{{ prefect.blocks.secret.docker-image }}"
      tag: "reports-analytics-{{ $PREFECT_GIT_COMMIT_SHA }}"
      dockerfile: ../Dockerfile
      path: ".."                 # set build context to the repo root
      platform: "linux/amd64"
- In your Dockerfile, use COPY statements relative to the context (the repo root), e.g.:
Copy code
WORKDIR /app
COPY flows/ /app/flows/
# or COPY . /app if you want the entire repo
- Make sure
.dockerignore
does not exclude
flows/
or your flow files. 2) Move the Dockerfile next to prefect.yaml and use local context
Copy code
build:
  - prefect_docker.deployments.steps.build_docker_image:
      id: build-image
      requires: prefect-docker>=0.6.0
      image_name: "{{ prefect.blocks.secret.docker-image }}"
      tag: "reports-analytics-{{ $PREFECT_GIT_COMMIT_SHA }}"
      dockerfile: ./Dockerfile
      path: "."                  # build context = current directory
      platform: "linux/amd64"
- Adjust COPYs in the Dockerfile accordingly to match this layout. Quick verification steps - Build the image and inspect the contents: - Locally:
docker run --rm -it <your-built-image> ls -R /app/flows
- Or in-cluster: exec into a job/pod and
ls -R /app/flows
- Ensure the deployment’s entrypoint matches where the file lands in the image (with
/app
as the working directory, your file should exist at
/app/flows/my_flow_test.py
). If you can, please share: - Your Dockerfile (especially the COPY lines) - A small repo tree showing where
prefect.yaml
,
Dockerfile
, and
flows/
live - Your
.dockerignore
- The failing deployment’s entrypoint (from
prefect.yaml
or however you define it) With that, I can suggest exact path/COPY statements to make this robust.