<@ULVA73B9P> Is there any way to duplicate/clone a...
# ask-marvin
f
@Marvin Is there any way to duplicate/clone a deployment in OSS
m
thought for 386.3 seconds
Short answer: there’s no one-click “Duplicate/Clone” button for deployments in the OSS UI (or Cloud) today. Good news: there are a few easy ways to duplicate one: - Define another deployment in prefect.yaml - Easiest and most common. Copy the existing entry and change just the fields you need (name, params, schedule, work pool, etc.). You can also use YAML anchors to DRY up shared config. - Docs: prefect.yaml how-to Example:
Copy code
deployments:
    - name: my-flow/prod
      entrypoint: flows/my_flow.py:my_flow
      work_pool: my-pool
      job_variables:
        image: <http://ghcr.io/acme/my-image:latest|ghcr.io/acme/my-image:latest>
      parameters:
        env: "prod"
      schedules:
        - cron: "0 * * * *"
          timezone: "UTC"

    - name: my-flow/staging
      entrypoint: flows/my_flow.py:my_flow
      work_pool: my-pool
      job_variables:
        image: <http://ghcr.io/acme/my-image:latest|ghcr.io/acme/my-image:latest>
      parameters:
        env: "staging"
      schedules:
        - interval: 3600
Then run
prefect deploy
from your project. You can deploy one or all named deployments defined in the file. - CLI help for deployment: prefect deployment CLI - Re-deploy the same flow with a new name (from code/project) - If you’re already using
prefect deploy
, run it again with a different deployment name pointing to the same entrypoint. This is effectively “clone then tweak.” - Programmatically copy via API - You can read an existing deployment and create a new one with a different name using the client and REST API. - API refs: - Create: POST /deployments - Read by name: GET /deployments/name/{flow_name}/{deployment_name} Sketch:
Copy code
import asyncio
  from prefect.client.orchestration import get_client
  from prefect.client.schemas.actions import DeploymentCreate

  async def clone_deployment(src_full_name: str, dest_full_name: str):
      flow_name, _ = src_full_name.split("/", 1)
      dest_flow_name, dest_deployment_name = dest_full_name.split("/", 1)

      async with get_client() as client:
          src = await client.read_deployment_by_name(src_full_name)

          body = DeploymentCreate(
              # Keep the same flow_id (same flow) or change if needed
              flow_id=src.flow_id,
              name=dest_deployment_name,
              work_pool_name=src.work_pool_name,
              job_variables=src.job_variables,
              parameters=src.parameters,
              schedules=src.schedules,
              tags=src.tags,
              description=src.description,
              concurrency_limit=src.concurrency_limit,
          )

          await client.create_deployment(body)

  asyncio.run(clone_deployment("my-flow/prod", "my-flow/staging"))
Handy inspection tip: you can print the source deployment details before copying: -
prefect deployment inspect "flow-name/deployment-name"
to review config Would you prefer to duplicate via prefect.yaml/CLI or programmatically via the API? If you share how you’re managing deployments today, I can tailor an example to match.