From 6e5a43d6ac7910707c4a8f67982214b8ca3b4906 Mon Sep 17 00:00:00 2001 From: zzstoatzz Date: Tue, 12 Nov 2024 21:02:29 -0600 Subject: [PATCH] add docker example --- examples/prefect-deploy.Dockerfile | 7 +++++-- examples/prefect_deploy.py | 12 ++++++++++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/examples/prefect-deploy.Dockerfile b/examples/prefect-deploy.Dockerfile index 05addc9..55fb0fd 100644 --- a/examples/prefect-deploy.Dockerfile +++ b/examples/prefect-deploy.Dockerfile @@ -1,10 +1,13 @@ FROM ghcr.io/astral-sh/uv:python3.12-bookworm-slim +RUN apt-get update && apt-get install -y git + +RUN rm -rf /var/lib/apt/lists/* + WORKDIR /app ENV UV_SYSTEM_PYTHON=1 ENV PATH="/root/.local/bin:$PATH" -RUN --mount=type=cache,target=/root/.cache/uv \ - uv pip install controlflow +RUN uv pip install controlflow diff --git a/examples/prefect_deploy.py b/examples/prefect_deploy.py index 453990d..b6c71c2 100644 --- a/examples/prefect_deploy.py +++ b/examples/prefect_deploy.py @@ -1,7 +1,9 @@ +import os import sys from pathlib import Path from prefect.docker import DockerImage +from prefect.runner.storage import GitRepository import controlflow as cf @@ -26,8 +28,12 @@ def write_poems(topics: list[str]) -> list[str]: entrypoint=f"{p.name}:write_poem", ).deploy(name="local-deployment", work_pool_name="local-process-pool") elif len(sys.argv) > 1 and sys.argv[1] == "docker_deploy": + repo = GitRepository( + url="https://github.com/PrefectHQ/controlflow.git", + branch="example-deploy", + ) write_poems.from_source( - source="https://github.com/PrefectHQ/controlflow.git@example-deploy", + source=repo, entrypoint="examples/prefect_deploy.py:write_poems", ).deploy( name="docker-deployment", @@ -38,7 +44,9 @@ def write_poems(topics: list[str]) -> list[str]: Path(__file__).parent.resolve() / "prefect-deploy.Dockerfile" ), ), - work_pool_name="docker-pool", + work_pool_name="docker-work", + parameters={"topics": ["roses", "violets", "sugar", "spice"]}, + job_variables={"env": {"OPENAI_API_KEY": os.getenv("OPENAI_API_KEY")}}, ) else: print(f"just running the code\n\n\n\n\n\n")