Hello. I have a simple flow I want to deploy on m...
# ask-community
g
Hello. I have a simple flow I want to deploy on my cluster. Everything is self managed. In my local directory I have
main.py
file with the flow definition. First I built a docker image using the following Dockerfile:
Copy code
FROM prefecthq/prefect:3.0.1-python3.12
WORKDIR /app
COPY main.py /app/main.py
CMD ["python", "/app/main.py"]
Then I defined a prefect yaml file:
Copy code
pull:
- prefect.deployments.steps.set_working_directory:
    directory: /app

deployments:
- name: test.prefect.deployment
  entrypoint: main.py:dummy_flow
  work_pool:
    name: worker-pool-staging
    job_variables:
      image: <my-registry>/test-prefect:latest
    work_queue_name:
  version:
  tags: []
  concurrency_limit:
  description:
  parameters: {}
  enforce_parameter_schema: true
  schedules: []
However, when I try to run
prefect deploy --prefect-file=deployment.yaml
from my local directory, it works. But when I run it from a different directory, it doesn't work and it exits with
FileNotFoundError: [Errno 2] No such file or directory: 'main.py'
. So it seems to me like prefect creates the deployment based on my local files. However, I explicitely want it to use only files that are already inside the docker image. Is this possible? How to achieve it?
šŸ‘€ 2
e
^ Id be interested to understand this too, been having the same problem/question
šŸ™ 1
n
hi @gabe - a couple clarifying questions • are you saying you want to run
prefect deploy
from anywhere, whether or not your code is there, because it should be good enough for the code to live inside the image? • why are you overriding
CMD
in your
Dockerfile
?
g
Hi Nate, thanks for quick response. The first point is exactly what I mean. My thinking is: since I already built the image with the source code inside, it should be used. I can imagine a situation where I build a docker image with some source code, then I change some files in my local directories and run
prefect deploy
on that, well, what then? Image has ove version of the code, locar directory another version. Seems like it could be asking for trouble, but correct me if I'm wrong. As for the
CMD
this is just an entrypoint to the docker image. From docker docs:
The CMD instruction specifies the default command to run when a container is started from the Docker image. If no command is specified during the container startup (i.e., in the docker run command), this default is used. CMD can be overridden by supplying command-line arguments to docker run.
So it seems to me that it shouldn't interfere with anything prefect-related, but again, if I'm wrong please do correct me. Thanks, Gabe
n
personally this is why I like to not bake code into images and instead do this, ie • build an image w external deps • clone code from github at runtime that way you don't need to push images when your workflow changes and there's no ambiguity about where the code is. but to more directly address your question, there is currently no way to do what you're asking, bc as you allude to, the location of the code is potentially ambiguous. at deployment time you need to define an
entrypoint
that points to your function. you might want to plus 1 this issue, as it seems like this would help you
So it seems to me that it shouldn't interfere with anything prefect-related
in containerized deployments we do leverage the entrypoint which is something like
python -m prefect.engine
(i.e. start the prefect engine) so overriding will cause issues
šŸ™Œ 1
g
alright, got it. thank you so much for your answers.
n
catjam
m
> personally this is why I like to not bake code into images and instead do this, ie > • build an image w external deps > • clone code from github at runtime > that way you don't need to push images when your workflow changes and there's no ambiguity about where the code is. So glad I found this thread, thanks @Nate I was worried I would have to build image on every deploy. We have some gnarly gdal / pdal dependencies that are enormous
n
thanks for the feedback! sounds like we should make this a proper guide in the docs