Alex Welch
05/22/2024, 8:16 PMMarvin
05/22/2024, 8:16 PMprefect.yaml
file, follow these steps:
1. Create/Modify the prefect.yaml
file:
Ensure you have a prefect.yaml
file in the root directory of your project. Here's a basic structure:
yaml
# generic metadata
prefect-version: null
name: null
# preparation steps
build: null
push: null
# runtime steps
pull: null
# deployment configurations
deployments:
- # base metadata
name: my-deployment
version: null
tags: []
description: null
schedule: null
# flow-specific fields
entrypoint: null
parameters: {}
# infra-specific fields
work_pool:
name: my-work-pool
work_queue_name: null
job_variables: {}
2. Deploying with the CLI:
Run the prefect deploy
command to deploy using the prefect.yaml
file. If the file is named differently or located in a different directory, use the --prefect-file
CLI argument to specify the path:
bash
prefect deploy --prefect-file path/to/prefect.yaml
3. Example Content:
Here is an example prefect.yaml
file with more details:
yaml
prefect-version: 2.0
name: My Flow
build:
- prefect_docker.deployments.steps.build_docker_image:
image_name: my-image
push:
- prefect_docker.deployments.steps.push_docker_image:
image_name: my-image
registry_url: my-registry
deployments:
- name: my-deployment
version: 1
tags: ['example']
schedule: {}
entrypoint: src/main.py:flow
parameters: {}
work_pool:
name: my-k8s-work-pool
work_queue_name: null
job_variables:
image: "my-image"
cluster_config: "my-cluster-config"
For more detailed information, you can refer to the Prefect Deployment Guide.
If you want to check the latest schema for prefect.yaml
or need more contextual information, you might find related issues such as Updating the prefect.yaml formatter schema or Adding new deployment schedule fields on GitHub useful.
If there's a specific problem with your deployment, checking open issues that resemble your problem might be helpful too, like this open issue discussing environment variables.
Happy deploying. Or not. I suppose it's all the same.Alex Welch
05/22/2024, 8:26 PMprefect.yaml
fileNate
05/22/2024, 8:47 PMprefect --no-prompt deploy ...
to avoid extra promptsAlex Welch
05/22/2024, 9:21 PMNate
05/22/2024, 9:27 PMAlex Welch
05/22/2024, 9:28 PMMarvin
05/22/2024, 9:28 PMif __name__ == "__main__":
block around your flow execution.
python
from prefect import flow
@flow
def my_flow():
print("Flow is running")
if __name__ == "__main__":
my_flow()
2. Update Your Deployment Command: After making the above change, rebuild your deployment using the CLI, if necessary.
bash
prefect deployment build path/to/your_script.py:my_flow -n "my_deployment" -a
This simple guard ensures that the my_flow()
function is called only when the script is executed directly, preventing unintended executions during imports by Prefect.
You can refer to the deployment guide in the Prefect Documentation for further details on configuring deployments and handling such scenarios.
For more context on why this is necessary, you can also review related GitHub issues and pull requests on this topic.
If you need further assistance, feel free to ask. Or don't. It doesn't really matter.