<@ULVA73B9P> is it possible to get the Deployment ...
# ask-marvin
a
@Marvin is it possible to get the Deployment object that was created through the CLI process?
m
Yes, it is possible to get the Deployment object that was created through the CLI process. You can load the settings from an existing deployment using the following code:
Copy code
deployment = Deployment( name="a-name-you-used", flow_name="name-of-flow" ) 
deployment.load() # loads server-side settings
Once the existing deployment settings are loaded, you may update them as needed by changing deployment properties. You can view all of the parameters for the Deployment object in the Python API documentation. Please note that the infrastructure type of your Prefect deployment describes how you want Prefect agents to run flows for the deployment. For example, with DockerContainer infrastructure, the agent will try to use Docker to spin up a new container for each flow run. If you are starting your own container on ACI, you don't need Prefect to do it for you. Specifying process infrastructure on the deployment tells Prefect you want the agent to run flows by starting a process in your ACI container. You can use any storage type as long as you've configured it correctly. For more details, you can refer to the Prefect documentation.
👍 1
a
@Marvin I wanted to view the Deployment object for a flow I deployed using the CLI because I was curious what the
storage
attribute would look like. I'm surprised to see it is
None
when I configured a git clone pull in the
prefect.yaml
on deployment. How does the cloning configuration get related to the Deployment object if not through
storage
?
m
The
storage
attribute of the Deployment object in Prefect does not directly relate to the git clone pull configured in the
prefect.yaml
file. Instead, the
storage
attribute is used for specifying where your flow's code is stored, such as Docker, S3, GCS, etc. The git clone pull configured in the
prefect.yaml
file is part of the deployment process, which is separate from the flow's storage configuration. When you run
prefect deploy
, the git clone pull is executed as part of the build process, which prepares your flow for deployment by pulling the latest code from your git repository. After the build process, the
push_to_s3
step is executed, which pushes your built flow to the specified S3 bucket. This is where the
storage
attribute comes into play - it tells Prefect where to retrieve your flow's code when it needs to run the flow. In summary, the git clone pull and the
storage
attribute serve different purposes. The git clone pull is part of the build process, which prepares your flow for deployment, while the
storage
attribute tells Prefect where to retrieve your flow's code when it needs to run the flow.
a
@Marvin what would I need to provide to the
storage
attribute of a Deployment so that it will retrieve the flow code from Github at runtime?
m
To retrieve the flow code from Github at runtime, you would need to use a custom storage class that supports Github. Prefect does not currently provide a built-in Github storage class, but you can create your own by extending the
Storage
base class. Here is a simple example of what a custom Github storage class might look like:
Copy code
from prefect import Storage

class GithubStorage(Storage):
    def __init__(self, repo: str, path: str):
        self.repo = repo
        self.path = path

    def get_flow(self, flow_location: str) -> "Flow":
        # Implement logic to retrieve and return flow from Github
You would then use this custom storage class when creating your flow:
Copy code
flow = Flow('my-flow', storage=GithubStorage(repo='my-repo', path='path/to/flow.py'))
Please note that this is a simplified example and the actual implementation would need to handle authentication with Github and retrieving the flow code from the specified repository and path. Alternatively, you can store your code in an AWS S3 bucket, Azure Blob Storage container, or GCP GCS bucket and specify the destination directly in the push and pull steps of your
prefect.yaml
file. For more details, you can refer to the Prefect documentation.