Jesse
09/18/2025, 5:13 PMMarvin
09/18/2025, 5:13 PMMarvin
09/18/2025, 5:19 PMdeployments:
- name: prod
entrypoint: flows/etl.py:etl
pull:
- prefect.deployments.steps.git_clone:
repository: "<https://github.com/your-org/your-repo.git>"
# pin to an exact commit:
commit_sha: "abc1234deadbeefcafebabefeedface01234567"
# optional helpers:
# branch: "main"
# access_token: "{{ prefect.variables.GITHUB_TOKEN }}"
- prefect.deployments.steps.pip_install_requirements:
requirements_file: "requirements.txt"
Tip: You can template the SHA from CI or a Prefect variable:
commit_sha: "{{ env.CI_COMMIT_SHA }}"
# or
commit_sha: "{{ prefect.variables.GIT_COMMIT_SHA }}"
Notes:
- commit_sha takes precedence if both branch and commit_sha are provided.
- Flow.from_source(...) itself does not accept a commit parameter. The pinning happens via the pull step configuration used by prefect deploy.
Docs:
- prefect.yaml guide
- Deployment versioningJesse
09/18/2025, 5:27 PMMarvin
09/18/2025, 5:27 PMMarvin
09/18/2025, 5:30 PMfrom prefect.flows import Flow
from prefect.runner.storage import GitRepository
repo = GitRepository(
url="<https://github.com/your-org/your-repo.git>",
commit_sha="abc1234deadbeefcafebabefeedface01234567", # pin here
# optional:
# branch="main",
# include_submodules=True,
# directories=["flows"], # clone only these directories
)
flow = Flow.from_source(
source=repo,
entrypoint="flows/etl.py:etl", # path in the repo
)
flow.deploy(
name="prod",
work_pool_name="my-work-pool",
# other options like schedule, parameters, tags, etc.
)
2) Construct a RunnerDeployment and call prefect.deployments.deploy(...)
- Useful if you prefer to reference an entrypoint without importing the flow in this script.
from prefect.deployments.runner import RunnerDeployment
from prefect.deployments import deploy
from prefect.runner.storage import GitRepository
deployment = RunnerDeployment(
name="prod",
entrypoint="flows/etl.py:etl",
storage=GitRepository(
url="<https://github.com/your-org/your-repo.git>",
commit_sha="abc1234deadbeefcafebabefeedface01234567",
# branch="main",
),
work_pool_name="my-work-pool",
# parameters={}, schedules=[...], tags=[...], etc.
)
deploy(deployment)
Notes and tips:
- The parameter is commit_sha. If both branch and commit_sha are set, the commit_sha wins.
- For private repos, authenticate using your preferred method. Common options:
- Embed a token in the URL (e.g., GitHub’s x-access-token format), or
- Provide credentials via a GitCredentials block (if you’ve created one) passed to GitRepository via the credentials argument.
- include_submodules=True if you rely on submodules.
Docs:
- Deployment versioning
- Store flow code (Git)