hey would anyone be able to help me setup up my pr...
# ask-community
b
hey would anyone be able to help me setup up my prefect deployment against modal? I'm having a pretty confusing issue just trying to set where the working directory is. Seems pretty silly but I can't get prefect to direct to modal where the actual entrypoint of the code is
n
๐Ÿ‘‹ hey @Ben Epstein - i responded to your issue, but since you're using
prefect.yaml
i'd guess something like this is what you want https://github.com/zzstoatzz/prefect-pack/blob/477484d91c77309a942b5ed9b7109ef48731f6df/prefect.yaml#L59-L61 which shouldn't require you to cd into the cloned repo note that my entrypoint is relative to the root of the repo being cloned
b
thanks! the issue with entrypoint needing to be relative to the root of the cloned directory is that this isn't where my flow is when I deploy it locally, which then causes
prefect deploy
to fail. My repo is setup like
Copy code
repo
|_ project
|_ _ Makefile
|_ _ prefect.yaml
|_ _ flows
|_ _ _ my_flow.py
and so in my prefect.yaml i have my deployment as
Copy code
entrypoint: flows/my_flow.py:main
but then when its cloned, it needs to be
project/flows/my_flow.py:main
because while entrypoint needs to be relative to the root directory, it also needs to be relative to my CWD when I call
prefect deploy
-- which means that unless im always calling prefect deploy from the root of my directory, this doesn't work
i think a more scalable option could be to let
entrypoint
be a python module
Copy code
flows.my_flow.main
which would not require this path routing
n
> unless im always calling prefect deploy from the root of my directory this is generally what we recommend https://github.com/zzstoatzz/prefect-pack/tree/main/flows/nested_project so from the root of this repo i run
Copy code
ยป prefect --no-prompt deploy --prefect-file flows/nested_project/prefect.yaml

ยป prefect deployment run 'some-flow/nested-project-flow'

ยป prefect worker start --pool 'local' # not required in your case
and since my
entrypoint
is still relative to the root of the repo (where I'm running the command from), this works as expected > i think a more scalable option could be to let
entrypoint
be a python module this might be possible, feel free to flesh out the idea in an issue!
b
but is there a way to work around this for me using
working_directory
now? I would definitely prefer not to restructure my entire project just to fit this parameter of where files exist for a prefect deployment. Is there no way currently to achieve what i'm trying to do?
n
sorry, i might be missing some detail, I'm not trying to suggest you need to change your entire setup, only that you should โ€ข specify
entrypoint
as a path that's relative to the root of the repo you're cloning โ€ข run
prefect deploy
from the root of that repo, using
--prefect-file
to point at the right yaml
b
i have multiple distinct projects in my repo, each in a folder 1-level down from the root, each with their own makefile. The "right" solution for my setup is to have the deploy command be in the respective makefile, but that would require not running it from the root of the repo, or adding like a
cd .. && prefect deploy
I could definitely create a makefile at the root just for prefect, it just feels a little silly to have it just for prefect. But i'll do one of those if there's no way to work around this with the
working_directory
step
i'm going to stick with this for now
Copy code
deploy-prefect:
	(cd .. && uv run prefect deploy --all --prefect-file ./project-1/src/flows/prefect.yaml)
and i'll open an issue with my thoughts on being able to provide a module. thanks!
n
gotcha the detail i was missing was that you want
make deploy-prefect
which necessitates running
prefect deploy
from the nested folder, and np - thanks for explaining!
b
hmm so i changed it to be at the root of the directory and it's somehow still throwing the same issue, now with the full relative path
Copy code
prefect.exceptions.ScriptError: Script at 'copilot/src/flows/auto_respond.py' encountered an exception: FileNotFoundError(2, 'No such file or directory')
even though the deploy does work from the root
ok, i got it working.. i'm thinking about writing up a little document that maybe prefect can include in their documentation walking people through how to set this up, there were quite a few gotchas that I think i can help people avoid. Wdyt Nate?
๐Ÿ”ฅ 1
n
sorry afk right now but that sounds excellent! it would be much appreciated ๐Ÿ™‡
๐Ÿ‘ 1
b
n
wow this is awesome! thanks so much ๐Ÿ’™ are you open to us finding a home for this somewhere in the prefect domain?
๐Ÿ™Œ 1
b
Totally! Would love to get it on
t
Hey just joined and setting up prefect for the first time! @Ben Epstein I am following your guide now and will let you know if I hit any hiccups
โฃ๏ธ 1
๐Ÿ™Œ 1
b
Ben, not to pile on too many asks here, would you be willing to drop the modal guide in #CL09KTZPX? This is going to be so helpful for others to see an learn from. ๐Ÿซถ You rock
b
Sure thing ๐Ÿค
t
Tutorial is great, but running into issues cloning a private repo. I know the credentials are right because I was using the block earlier to pull from my repo. Runner exception message is pretty vague, just "failed to clone"
b
Hm weird! I'm using a private repo for my real project and I'm using the same pattern. Just to sanity check, โ€ข You put this as the credential (not token) in the yaml:
credentials: '{{ prefect.blocks.github-credentials.prefect-modal }}'
โ€ข You put the PAT into the block in the perfect dashboard UI?
Want to share your perfect.yaml?
t
Rubber ducking always works so well -- it seems prefect init defaults to access_token but you clearly say to change that to credentials
b
Yes I found that so weird too haha. I'll add a more aggressive note in the doc!
๐Ÿ™Œ 1
@Trey Gilliland can you refresh and take a quick look? i updated it
t
Yep I see it on my end -- now my issue is with this pull YAML it says it is pulling:
Copy code
# pull section allows you to provide instructions for cloning this project in remote locations
pull:
  - prefect.deployments.steps.git_clone:
      id: clone-step
      repository: "<https://github.com/MyOrg/my-repo.git>"
      branch: feat/prefect/init
      credentials: "{{ prefect.blocks.github-credentials.trey-gh-auth-token }}"
  - prefect.deployments.steps.run_shell_script:
      directory: "{{ clone-step.directory }}/services/prefect_cloud"
      script: make setup
  - prefect.deployments.steps.set_working_directory:
      directory: "{{ clone-step.directory }}/services/prefect_cloud"
FileNotFoundError: [Errno 2] No such file or directory: 'my-repo-feat/prefect/init/services/prefect_cloud' So parsing the branch as a directory path maybe? How is clone-step.directory set?
Checking the source code it seems it it appends -{branch} to the repo name if not supplied and that's how it gets set -- will set name and see if it fixes it
b
yes this got me stuck for a while. Make sure that the file exists in the branch that you are puilling from
{{ clone-step.directory }}
the value of this is the repo name with the branch
t
the deployment step actually doesn't let you supply a name so if you supply a branch it will look for a file that doesn't exist
I think this might be a bug
b
it's not a bug, it's just confusing behavior ๐Ÿ™‚ https://github.com/PrefectHQ/prefect/issues/16998 what did you set your entrypoint to? it needs to be relative to
"{{ clone-step.directory }}/services/prefect_cloud"
t
yes that is the case -- the setup shell script isn't working because "{{ clone-step.directory }}/services/prefect_cloud" unfurls to my-repo-*{{branch}}*/services/prefect_cloud if you supply a branch
b
so modal pulls directly from github when runnign the code. So its doing a git clone. So for example, you have
Copy code
repository: "<https://github.com/MyOrg/my-repo.git>"
branch: feat/prefect/init
it will
Copy code
git clone <https://github.com/MyOrg/my-repo.git> && git checkout feat/prefect/init
and it will place you in the root of the repo
t
the path should not include the branch
b
nah it does that for main as well, it unfurls to
my-repo-main
but it places you inside the repo so it should be fine. like
pwd
will map to the root of your repo, then you move to
./services/prefect_cloud
-- dos that make sense? this is what had me messed up for like 2 hours yesterday ๐Ÿ˜‚
happy to screenshare with you for a few minutes to walk you through it. then we can update the doc to make this part clear
๐Ÿ’™ 1
t
Yeah I get what you are saying I think -- I'm just confused why the branch is in the path? if you
git clone
the repository, it isn't going to include that branch in the path
b
yea agreed, no idea why they do that
are you still stuck?
t
yeah... might take you up on the screen share
Ok we worked out that bug -- TL;DR: make sure you push your code to github and don't trust your local VSCode/Terminal, actually check your github UI
@Ben Epstein next problem, now it is saying it can't find curl which is a part of the
make setup
directive
b
ooo hold on ill update the makefile, theres another way to install it
๐Ÿ™Œ 1
t
weird that you didn't hit this
b
its cuz i do
pip install --upgrade 'uv>=0.5.6,<0.6'
its jsut not as "nice"
updated the docs
๐Ÿ™Œ 2
t
success! @Ben Epstein turns out that / is needed for the set_working_directory step -- not sure why
b
oh great thanks! ill add it back
Hey @Nate you shared this earlier https://github.com/zzstoatzz/prefect-pack/blob/477484d91c77309a942b5ed9b7109ef48731f6df/prefect.yaml#L59C5-L64C84 but i'm actually struggling with this, and i'll need to update the writeup to fix: I'm running a
uv sync
in my setup, but that's creating a new virtual env which is different from the one prefect is using when it begins to process the flow. I'm struggling how to tell prefect to use my venv python as the one to execute. Because now i'm just getting ModuleNotFound issues
Copy code
prefect.exceptions.ScriptError: Script at 'src/flows/auto_respond.py' encountered an exception: ModuleNotFoundError("No module named 'app'")
n
i should have been more explicit, previously i think I was only trying to share the
git_clone
step, not the
run_shell_script
hack (that only works for a process pool running started from the same venv) to install some deps at runtime
๐Ÿ‘€ 1
b
ohh hm so how do you actually install your dependencies? i extrapolated that into the guide i wrote (and also am trying now haha). i have a
uv.lock
file that I need to get into whatever the python executable is
n
are you still using modal? i'd think you'd want some dockerfile that uv's all your deps into an image, or alternatively (more prone to weird outcomes) set
EXTRA_PIP_PACKAGES='pandas whatever git+{your repo}'
which would use uv (in the prefect base image) to install deps at runtime building an
image
and sticking that on your work pool is the normal pattern for containerized work pool types tho
b
is there an example of doing that with a
prefect.yaml
file? I assume it's in the
build
?
n
yep โ€ข docs โ€ข other example but you're totally free to leave image building out of prefect's purview and
docker build
/
docker push
in CI independently and reference the resulting
image
in your work pool
b
hm okay, i can try that. is there an example of
EXTRA_PIP_PACKAGES
in the docs? I see mentions of it but no actual usage
n
we could prob add it in the yaml section as well but yeah https://docs.prefect.io/v3/deploy/infrastructure-examples/docker#additional-configuration-with-deploy its a special env var, so in yaml itll look like
Copy code
deployments:
    ...
    work_pool:
      name: your-work-pool
      job_variables:
        env:
          EXTRA_PIP_PACKAGES: pandas whatever
for context
b
awesome thanks!! I'll play around with this, feeling unblocked ๐Ÿ™
n
catjam
catjam 1
b
ill update the guide when I figure this out
๐Ÿ™Œ 1
hm unfortunately while i see the env var being set
Copy code
Feb 06  20:13:21.558
=> Step 3: ENV EXTRA_PIP_PACKAGES='git+<https://github.com/>
it's not actually running anything, and i see the same error. I'll try out the docker flow tomorrow
i was expecting
Copy code
- prefect.deployments.steps.run_shell_script:
    directory: '{{ clone-step.directory }}'
    script: |
        pip install --upgrade 'uv>=0.5.6,<0.6'
        /bin/sh -c "uv export --no-dev --no-editable --no-hashes --locked > requirements.txt"
- prefect.deployments.steps.pip_install_requirements:
    directory: '/{{ clone-step.directory }}'
    requirements_file: requirements.txt
to work, weird to me that it doesn't. It finds my package
app
but i get a moduleNotFound
app.baml_client
which is one of the subdirectories in my app...