Skip to content

Commit

Permalink
update example
Browse files Browse the repository at this point in the history
  • Loading branch information
zzstoatzz committed Nov 13, 2024
1 parent b5bc9dd commit be41a7c
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 27 deletions.
27 changes: 0 additions & 27 deletions examples/deploy.py

This file was deleted.

10 changes: 10 additions & 0 deletions examples/prefect-deploy.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM ghcr.io/astral-sh/uv:python3.12-bookworm-slim

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

44 changes: 44 additions & 0 deletions examples/prefect_deploy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import sys
from pathlib import Path

from prefect.docker import DockerImage

import controlflow as cf


@cf.task()
def write_poem(topic: str) -> str:
"""Write four lines that rhyme"""
return f"The topic is {topic}"


@cf.flow()
def write_poems(topics: list[str]) -> list[str]:
return write_poem.map(topics).result()


if __name__ == "__main__":
if len(sys.argv) > 1 and sys.argv[1] == "serve":
write_poems.serve()
elif len(sys.argv) > 1 and sys.argv[1] == "local_deploy":
write_poems.from_source(
source=str((p := Path(__file__)).parent.resolve()),
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":
write_poems.from_source(
source="https://github.com/PrefectHQ/controlflow.git@example-deploy",
entrypoint="examples/prefect_deploy.py:write_poems",
).deploy(
name="docker-deployment",
image=DockerImage(
name="zzstoatzz/cf-test-deploy",
tag="latest",
dockerfile=str(
Path(__file__).parent.resolve() / "prefect-deploy.Dockerfile"
),
),
work_pool_name="docker-pool",
)
else:
write_poems(["roses", "violets", "sugar", "spice"])

0 comments on commit be41a7c

Please sign in to comment.