Menu ▾ ▴

#27 [Feature]: Clone an environment from the CLI

closed
nobody
2026-09-23
2026-09-11
Anonymous
No

Originally created by: thomijasir
Originally owned by: thomijasir

Feature

Add one CLI command that creates an environment in the source project and copies the source environment's current secrets into it.

CLI

dopbase env clone PROJECT_REF/SOURCE_ENVIRONMENT_NAME NEW_ENVIRONMENT_NAME

Examples:

dopbase env clone payment-service/local production
dopbase env clone storefront/staging preview-42 --yes

The source must use a qualified project and environment reference. The destination is always created in the same project as the source.

Behavior

  1. Resolve the source and its project.
  2. Check whether the destination name already exists.
  3. Read the source secret count and show a confirmation summary without showing secret values.
  4. Require a recent human authentication session.
  5. Create the destination before exporting plaintext secrets, so a creation race fails before plaintext is fetched.
  6. Export the source secrets in memory and import them into the destination.
  7. Remove the newly created destination if export or import fails. Never remove a destination that existed before the command.
  8. Fetch the project's environments after a successful clone.
  9. Print the full environment table in normal output.
  10. With --json, print the complete environment array, matching dopbase env list --json.

--yes skips the clone confirmation, but it does not bypass authentication or authorization checks.

If the clone succeeds but the final list request fails, report that the clone completed and suggest running dopbase env list PROJECT_REF.

Security

  • Human admin credentials only. Runner and service-account credentials are rejected.
  • Plaintext secrets stay in memory and are not written to temporary files.
  • Secret values are not printed in summaries or errors.
  • In-memory secret values are cleared after import where practical.

Out of scope

  • Cross-project cloning
  • Cross-server cloning
  • Syncing into an existing environment
  • Copying tokens, audit history, IDs, timestamps, or editor layout

Acceptance criteria

  • [x] dopbase env clone payment-service/local production creates production in payment-service.
  • [x] All current secrets from local are copied, including an empty secret set.
  • [x] Existing destination names fail without modifying them.
  • [x] Creation failures happen before plaintext export.
  • [x] Export and import failures trigger best-effort cleanup.
  • [x] Cleanup failures report both the original failure and the cleanup result.
  • [x] A final list failure does not roll back a completed clone.
  • [x] Normal success output shows every environment in the project.
  • [x] JSON success output is the complete environment array.
  • [x] Runner credentials, service-account credentials, stale sessions, and cancelled confirmations stop before creation.
  • [x] Tests cover argument parsing, request order, output, rollback boundaries, redaction, and zero-secret cloning.
  • [x] CLI documentation, examples, and changelog are updated.

Related

Tickets: #1

Discussion

  • Anonymous

    Anonymous - 2026-09-11
     
  • Anonymous

    Anonymous - 2026-09-21

    Originally posted by: thomijasir

    Implemented the clone flow with the agreed interface:

    dopbase env clone payment-service/local production
    

    The destination is created in the source project. Normal success output now shows the full project environment table, while --json returns the same complete array as dopbase env list --json.

    The implementation includes confirmation, recent human-authentication checks, in-memory secret transfer, creation-before-export ordering, and best-effort rollback after export or import failures. Runner and service-account credentials are rejected.

    Verification completed:

    • 124 CLI integration tests passed, with 1 Docker-dependent format test ignored by the suite
    • Full backend tests passed twice in the repository verification container
    • Clippy passed with warnings denied
    • Release build, CLI help-tree checks, live server smoke test, documentation build, and formatting checks passed

    The CLI guides, examples, README, and changelog have also been updated.

     
  • Anonymous

    Anonymous - 2026-09-23

    Ticket changed by: dopbase

    • status: open --> closed
     

Log in to post a comment.