Omar Khudeira
05/22/2024, 6:53 PMpull_steps
as well as an image for the deployment. I looked at the APIs but not seeing an obvious way to do this with the Python API.Marvin
05/22/2024, 6:54 PMdeploy
function and specifying the necessary parameters. Here’s a relevant excerpt from the Prefect documentation that illustrates how to do this:
### Creating Multiple Deployments
python
from prefect import deploy, flow
@flow(log_prints=True)
def buy():
print("Buying securities")
if __name__ == "__main__":
deploy(
buy.to_deployment(name="dev-deploy", work_pool_name="my-dev-work-pool"),
buy.to_deployment(name="prod-deploy", work_pool_name="my-prod-work-pool"),
image="my-registry/my-image:dev",
push=False,
)
In this example, two deployments are created from the same flow, but with different work pools. You can also create multiple deployments from different flows.
### Adding pull_steps
and Custom Image
To include pull_steps
, use the appropriate configuration in your deployment YAML or programmatically. Here's an example of including `pull_steps`:
yaml
deploy:
- pull:
- prefect_aws.deployments.steps.pull_from_s3:
requires: prefect-aws>=0.3.0
bucket: my-bucket
folder: "{{ push-code.folder }}"
credentials: null
For programmatically defining pull_steps
and including an image during deployment, you would need to ensure your deployment includes those details.
### Key Steps and Links
1. Define Flows
Define your flows as functions decorated with @flow
in Prefect.
2. Deployment Programmatically
- Use deploy()
to create and manage deployments.
- Specify your pull_steps
and image as needed.
3. Useful Documentation and Issues
- Deployment Guide for additional context on deployment configurations.
- Example issue related to deployment settings: Issue #10899.
4. Image and Steps Customization
- For adding pull steps and image configuration, ensure you've configured them correctly in the deployment function or YAML.
This approach should serve as a decent starting point for creating multiple Prefect deployments in a programmatic manner. If you encounter issues, refer to the Prefect documentation and relevant GitHub issues for troubleshooting steps.Omar Khudeira
05/22/2024, 9:19 PMMarvin
05/22/2024, 9:19 PMpull_steps
, you can combine various elements from the documentation. Here's a code example of how to do this:
### Example Code
python
from prefect import flow
from prefect.deployments import Deployment
from prefect.infrastructure import KubernetesJob
from prefect_aws.deployments.steps import pull_from_s3
# Define your flow
@flow(log_prints=True)
def my_workflow():
print("Running my workflow")
# Define the image and Kubernetes job
k8s_job = KubernetesJob(
image="my-registry/my-image:latest"
)
# Create the deployment
deployment = Deployment.build_from_flow(
flow=my_workflow,
name="my-deployment",
infrastructure=k8s_job,
pull_steps=[
pull_from_s3(
requires="prefect-aws",
bucket="my-bucket",
folder="my-folder",
credentials="{{ prefect.blocks.aws-credentials.my-credentials }}"
)
]
)
# Apply the deployment
if __name__ == "__main__":
deployment.apply()
### Key Points
- `KubernetesJob`: Specifies the Docker image for the deployment.
- `pull_steps`: Utilizes `prefect_aws`'s pull_from_s3
step to pull data from S3.
- `Deployment.build_from_flow`: Combines the flow, infrastructure, and pull steps into a single deployment.
### Useful Links
- Prefect Deployment Guide
- Prefect AWS Steps
This script sets up a flow that utilizes a specified Docker image and S3 pull steps for the deployment. Adapt the example to fit your specific requirements as needed.Bring your towel and join one of the fastest growing data communities. Welcome to our second-generation open source orchestration platform, a completely rethought approach to dataflow automation.
Powered by