Skip to content

Commit

Permalink
add docker example
Browse files Browse the repository at this point in the history
  • Loading branch information
zzstoatzz committed Nov 13, 2024
1 parent 041efb0 commit 6e5a43d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
7 changes: 5 additions & 2 deletions examples/prefect-deploy.Dockerfile
Original file line number Diff line number Diff line change
@@ -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

12 changes: 10 additions & 2 deletions examples/prefect_deploy.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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",
Expand All @@ -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")
Expand Down

0 comments on commit 6e5a43d

Please sign in to comment.