Hey all, I am trying to migrate from Agents with I...
# ask-community
n
Hey all, I am trying to migrate from Agents with Infrastructure and Storage blocks (kubernetes jobs, and S3 file storage) to Workers/work pools. We build our own docker images because we have a lot of internal packages that we use, and have always baked our source code into the images. We now want to actually use the baked-in source code rather than pulling from external storage. Our source code ends up in
/workdir/src/<package>
in the image (where
/workdir
is set as the working directory in the image build process), and when registering a deployment to the server, it says the entrypoint is
src/path/to/file:flow_function
as I would expect. However, when trying to actually run the deployment, it immediately fails with
Copy code
Flow could not be retrieved from deployment.
Traceback (most recent call last):
  File "", line 991, in exec_module
  File "", line 1128, in get_code
  File "", line 1186, in get_data
FileNotFoundError: [Errno 2] No such file or directory: '/opt/prefect/src/path/to/file.py'
which causes
Copy code
prefect.exceptions.ScriptError: Script at 'src/path/to/file.py' encountered an exception: FileNotFoundError(2, 'No such file or directory')
So I am confused as to why Prefect is looking for it in
/opt/prefect
. I am trying creating the deployment with
Copy code
my_flow.to_deployment(name="test-deployment", work_pool_name="my-work-pool")
and don't see anything in the documentation about changing the entrypoint or path when using
.to_deployment()
.
n
hi @Nick Hoffmann - how are you actually creating the deployment? are you using
.deploy
? if so, you shouldn't need
to_deployment
n
I have a few dozen deployments that I am trying to programmatically generate and deploy, all with different parameters, so I am doing basically:
Copy code
import prefect
from dataclasses import dataclass
from typing import Optional, Any, List

@dataclass
class MyDeployment:
    flow: prefect.Flow
    name: str
    kwargs: Dict[str, Any]

def generate_deployment_list() -> List[MyDeployment]:
    # My custom logic for building parameter sets for each deployment
    ...

dep_list: List[MyDeployment] = generate_deployment_list()
dep_list = [dep.flow.to_deployment(name=dep.name, **dep.kwargs) for dep in dep_list]
prefect.deploy(*dep_list,
               work_pool_name="my-work-pool",
               image="my-image-built-in-CI",
               build=False)
n
just checking quick, are you averse to
prefect.yaml
? this seems like a natural use case for it
meh i guess its bc of the parameter stuff
are you `COPY`ing flow code into your images in CI?
n
not necessarily averse to it, but it doesn't really fit our use case as nicely as we'd like. We have a set of deployments that we make and run for each of our customers, and we want to be able to deploy for a new customer by simply adding them to our database and not have to update and commit that
prefect.yaml
file
👍 1
yeah we're copying the flow code into our images in CI - I also tried adding a
COPY
line to copy source code into that
/opt/prefect
path, but still no dice
👍 1
n
hmm this is working for me if thats helpful
n
I found out that actually my flow runs were using a standard Prefect image, not my custom image, so that solved that problem
n
ahh i see, glad you figured it out
n
ye, thank you for your time
catjam 1