Andrew
12/21/2023, 3:31 AMMarvin
12/21/2023, 3:31 AMprefect init
command. Here's how to use the CLI for this purpose:
1. You can initialize a deployment recipe using the CLI and specify that you'd like to use Docker with the --recipe docker
flag.
2. You can use the --field
flags to set specific values for your Docker image, such as the image name and tag. For example:
bash
prefect init --recipe docker --field image_name=my-repo/my-image --field tag=my-tag
3. In your recipe, as outlined in the generated YAML, you will define the build step with the necessary package, image name, tag, and whether you want to push the image to a Docker repository.
Here is an example of a build step from the YAML file:
yaml
build:
- prefect_docker.deployments.steps.build_docker_image:
requires: prefect-docker>=0.3.0
image_name: my-repo/my-image
tag: my-tag
dockerfile: auto
push: true
The prefect-docker
package is used here, and the step will automatically build a Docker image with the provided name and tag before pushing it to the specified repository.
It's recommended to use {{ image }}
within prefect.yaml
, particularly within the job variables section of the work pool, to keep the build step and deployment specification in sync without hardcoding values.
Additionally, you can create complex deployments by combining multiple steps. For instance, to build a Docker image tagged with the current commit hash, you could use a run_shell_script
step and pass the output into a build_docker_image
step.
To read more about how the Prefect CLI can help you create custom images and for a detailed guide on Docker with Prefect, you can visit the Docker guide in the Prefect documentation.