Moritz Rocholl
01/18/2024, 9:35 AMexample_deploy_script.py
from prefect import flow
from prefect.deployments import DeploymentImage
@flow(log_prints=True)
def my_flow(name: str = "world"):
print(f"Hello {name}! I'm a flow running in a ECS task!")
if __name__ == "__main__":
my_flow.deploy(
name="my-deployment",
work_pool_name="my-work-pool",
image=DeploymentImage(
name="my-repository:latest",
platform="linux/amd64",
)
)
This will build an image with the tag <ecr-registry-url>/my-image:latest
and push it to the registry.
Your image name will need to match the name of the repository created with your work pool. You can create new repositories in the ECR console.
Where does the image name my-image come from?Marvin
01/18/2024, 9:36 AMmy-image
in the example script seems to be a placeholder to indicate where you would put the name of your image repository. The text demonstrates the image repository URL does not need to be specified in the build step because it is implied by the default Docker build namespace, which should be set to the ECR registry URL upon provisioning the infrastructure.
The excerpt from the documentation on deploying with Prefect shows a generic image_name: my-repo/my-image
configuration, which suggests that my-image
is part of the image_name
key that should be replaced with the name of your image on the ECR.
In the script you are using, my-repository:latest
serves as the image name (my-repository
) and the tag (latest
). This tag will be prefixed with the ECR registry URL automatically. In proper usage, "my-repository" should match the name of the repository associated with your work pool in ECR. If you have named your repository differently in ECR, you should use that name instead of my-repository
or my-image
.Moritz Rocholl
01/18/2024, 9:38 AMMarvin
01/18/2024, 9:39 AMDeploymentImage
with the name
parameter, it is assumed that the repository you're referencing already exists in ECR. Therefore, before you can successfully deploy and push an image, you must ensure the ECR repository with that name is already set up. Each image name typically corresponds with one repository in ECR. The deployment process then pushes the built Docker image to that specified repository.Moritz Rocholl
01/18/2024, 9:41 AMMarvin
01/18/2024, 9:42 AMprefect-flows
to hold all flow images, you need a way to distinguish between different flows that might require different container environments. One way to achieve this is to use separate tags for each flow image within the prefect-flows
repository.
For example:
- Flow A might use the image prefect-flows:flow-a-latest
- Flow B might use the image prefect-flows:flow-b-latest
Each tag (flow-a-latest
, flow-b-latest
) corresponds to a different Docker image that has been built with the specific dependencies and environment required by each flow.
When you configure your deployments, you specify the appropriate tag for the image you want to use for that flow. This will allow you to have different container environments for each flow while maintaining them within a single ECR repository.
However, if your flows are distinct enough that they justify completely separate repositories, you would traditionally create a new ECR repository for each unique environment. This approach might require additional ECR repositories but gives you complete isolation for the container environments of your different flows. This might not be the serverless push approach but would be a more traditional way to manage different containers in ECS.
Keep in mind that serverless deployments in Prefect aim to minimize the operational overhead, and in some cases, you might have to balance best practices for containerization with the conveniences of serverless workflows. If the default serverless model isn't fitting your needs, you may need to consider a more custom setup.Moritz Rocholl
01/18/2024, 9:52 AM