From 59f2d5def275f61628729ab7531305def29d80fc Mon Sep 17 00:00:00 2001 From: Emil Christensen Date: Thu, 5 Dec 2024 13:18:38 -0500 Subject: [PATCH] Adds example of deploying from a GitHub repo --- deploy/source-docker.py | 2 +- deploy/source-github.py | 47 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 deploy/source-github.py diff --git a/deploy/source-docker.py b/deploy/source-docker.py index a962a3c..6c5170f 100644 --- a/deploy/source-docker.py +++ b/deploy/source-docker.py @@ -36,7 +36,7 @@ def deploy(): source="./flows", entrypoint="hello-world.py:hello", ).deploy( - name="default", + name="source-docker", # The name of the work pool to use for this deployment work_pool_name="docker", image=DockerImage( diff --git a/deploy/source-github.py b/deploy/source-github.py new file mode 100644 index 0000000..aa19139 --- /dev/null +++ b/deploy/source-github.py @@ -0,0 +1,47 @@ +""" +# Deploy a flow from a git repository + +This example shows how to deploy a flow from a git repository. +It assumes you have a work pool named `process`. You can implicitly create the +work pool by starting a worker: + +```bash +prefect worker start --pool process --type process +``` +""" + +from prefect import flow +from prefect.runner.storage import GitRepository +from prefect.blocks.system import Secret +from prefect.client.schemas.schedules import CronSchedule + + +def deploy(): + # flow.from_source will actually clone the repository to load the flow + flow.from_source( + # Here we are using GitHub but it works for GitLab, Bitbucket, etc. + source=GitRepository( + url="https://github.com/PrefectHQ/examples.git", + credentials={ + # We are assuming you have a Secret block named `github-access-token` + # that contains your GitHub personal access token + "access_token": Secret.load("github-access-token"), + }, + ), + entrypoint="flows/hello-world.py:hello", + ).deploy( + name="source-github", + schedules=[ + # Run the flow every hour on the hour + CronSchedule(cron="0 * * * *"), + ], + work_pool_name="process", + # Define a different default parameter for this deployment + parameters={ + "name": "Arthur", + }, + ) + + +if __name__ == "__main__": + deploy()