Paweł Biernat
07/15/2024, 12:37 PMMarvin
07/15/2024, 12:37 PMprefect.yaml
, you can add the build
section with the context
parameter. Here’s an example configuration:
yaml
# Generic metadata about this project
name: my-prefect-project
prefect-version: 2.x.x
# build section allows you to manage and build docker images
build:
- prefect_docker.deployments.steps.build_docker_image:
id: build-image
requires: prefect-docker
image_name: my_registry/my_flow_image
tag: latest
context: .
# pull section for setting up remote execution
pull:
- prefect.deployments.steps.git_clone:
repository: git@github.com:my-org/my-repo.git
branch: main
access_token: "{{ prefect.blocks.secret.github-token }}"
- prefect.deployments.steps.set_working_directory:
directory: /opt/prefect
# deployments section for deploying flows
deployments:
- name: my_deployment
version: latest
entrypoint: path/to/your/flow.py:flow_function_name
parameters: {}
work_pool:
name: my-work-pool-name
job_variables: {}
In this configuration, context: .
specifies the current directory as the context for the Docker build, meaning it includes all necessary files from the current directory into the Docker image.
For more detailed guidance, refer to the Prefect Deployment Guide and the Docker Deployment Guide.
If you encounter issues with deployments or other errors, you can browse through the relevant GitHub issues. Here are a few relevant issues:
1. ModuleNotFoundError after installing a local package
2. Failed to parse @flow argument
3. Cloning Error during pull stepPaweł Biernat
07/15/2024, 12:38 PMMarvin
07/15/2024, 12:38 PMprefect.yaml
file, you can use the working_directory
option in the pull
step. By default, it is set to /opt/prefect/your-directory
. Here’s an example configuration:
yaml
# Generic metadata about this project
name: my-prefect-project
prefect-version: 2.x.x
# build section allows you to manage and build Docker images
build:
- prefect_docker.deployments.steps.build_docker_image:
id: build-image
requires: prefect-docker
image_name: my_registry/my_flow_image
tag: latest
context: .
# pull section for setting up remote execution
pull:
- prefect.deployments.steps.git_clone:
repository: git@github.com:my-org/my-repo.git
branch: main
access_token: "{{ prefect.blocks.secret.github-token }}"
- prefect.deployments.steps.set_working_directory:
directory: /opt/prefect/my-directory
# deployments section for deploying flows
deployments:
- name: my_deployment
version: latest
entrypoint: /opt/prefect/my-directory/path/to/your/flow.py:flow_function_name
parameters: {}
work_pool:
name: my-work-pool-name
job_variables: {}
In this example, directory: /opt/prefect/my-directory
specifies the path inside the Docker image where your flow code will be placed.
For more information, you can refer to the Prefect Deployment Guide.Paweł Biernat
07/15/2024, 12:40 PMMarvin
07/15/2024, 12:40 PMdockerfile
section of your prefect.yaml
file. Here is an example configuration:
yaml
# Generic metadata about this project
name: my-prefect-project
prefect-version: 2.x.x
# build section allows you to manage and build Docker images
build:
- prefect_docker.deployments.steps.build_docker_image:
id: build-image
requires: prefect-docker
image_name: my_registry/my_flow_image
tag: latest
context: .
dockerfile: |
FROM python:3.9-slim
WORKDIR /opt/prefect
COPY . /opt/prefect
RUN pip install -r requirements.txt
# pull section for setting up remote execution
pull:
- prefect.deployments.steps.git_clone:
repository: git@github.com:my-org/my-repo.git
branch: main
access_token: "{{ prefect.blocks.secret.github-token }}"
- prefect.deployments.steps.set_working_directory:
directory: /opt/prefect/my-directory
# deployments section for deploying flows
deployments:
- name: my_deployment
version: latest
entrypoint: /opt/prefect/my-directory/path/to/your/flow.py:flow_function_name
parameters: {}
work_pool:
name: my-work-pool-name
job_variables: {}
In this configuration, the dockerfile
section within the build
step specifies the instructions for building the Docker image. The COPY . /opt/prefect
line ensures that the current working directory (where the Dockerfile
is located) is copied into the /opt/prefect
directory inside the Docker image.
For more detailed guidance, refer to the Prefect Docker Guide.Paweł Biernat
07/15/2024, 12:44 PMbuild:
- prefect_docker.deployments.steps.build_docker_image:
id: build_image
requires: prefect-docker>=0.3.0
image_name: registry/xxx
tag: latest
dockerfile: docker/prefect.Dockerfile
the image is built correctly, but when I run the flow it starts the prefecthq/prefect:2.19.7-python3.12
image, why? how to run it with the image I just built?Marvin
07/15/2024, 12:44 PMprefecthq/prefect:2.19.7-python3.12
image instead of your custom image could be due to the worker pool configuration. Make sure that the image specified in the worker pool matches the image you just built.
Here’s how you can ensure that your flow uses the custom image you built:
1. Build Step Configuration: Your existing build
step looks correct, so there’s nothing to modify here.
yaml
build:
- prefect_docker.deployments.steps.build_docker_image:
id: build_image
requires: prefect-docker>=0.3.0
image_name: registry/xxx
tag: latest
dockerfile: docker/prefect.Dockerfile
2. Specify Custom Image in Deployment:
Ensure that the deployment configuration specifies the custom image you built.
yaml
# deployments section for deploying flows
deployments:
- name: my_deployment
version: latest
entrypoint: /opt/prefect/my-directory/path/to/your/flow.py:flow_function_name
parameters: {}
work_pool:
name: my-work-pool-name
job_variables:
image: registry/xxx:latest
In this configuration:
- Replace registry/xxx:latest
with the actual name and tag of your built image.
- Ensure that the job_variables
under the work_pool
section contains the image
key with the path to your custom Docker image.
For more detailed guidance, refer to the Prefect Deployment Guide and the Prefect Docker Guide.