Skip to content

feat(cd): add CD task/job/build ID to Deployment msg#2023

Merged
lionello merged 1 commit intomainfrom
lio/cdid-deployment
Apr 7, 2026
Merged

feat(cd): add CD task/job/build ID to Deployment msg#2023
lionello merged 1 commit intomainfrom
lio/cdid-deployment

Conversation

@lionello
Copy link
Copy Markdown
Member

@lionello lionello commented Apr 7, 2026

Description

Add CD build/task ID to Fabric in Deployment struct. This allows us to check whether a deployment is running, or to abort "defang deploy" and continue it later.

Most of the PR is to make sure the Deploy/Preview/CdCommand provider funcs return the CD info to their callers.

Linked Issues

Checklist

  • I have performed a self-review of my code
  • I have added appropriate tests
  • I have updated the Defang CLI docs and/or README to reflect my changes, if necessary

@lionello lionello requested a review from jordanstephens as a code owner April 7, 2026 20:31
@lionello lionello requested review from edwardrf and removed request for jordanstephens April 7, 2026 20:31
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 7, 2026

📝 Walkthrough

Walkthrough

This PR updates the CD command infrastructure and deployment response structures across the CLI and BYOC providers (AWS, GCP, DigitalOcean), replacing the CdCommand return type from a simple etag string to a richer CdCommandResponse object containing CD metadata (CdId, CdType, ETag). It also wraps Deploy/Preview responses in a new DeployResponse type that includes CD identity fields, adds these fields to the deployment proto message, and updates callers to propagate this metadata through deployment history recording.

Changes

Cohort / File(s) Summary
Proto definitions
src/protos/io/defang/v1/fabric.proto
Added CdType enum (with values for AWS CodeBuild, GCP CloudBuild, DO AppPlatform, Azure ACI) and two new fields (cd_type, cd_id) to Deployment message to track CD execution sources.
Provider interface and response types
src/pkg/cli/client/provider.go
Introduced CdCommandResponse struct (containing CdId, CdType, ETag) and DeployResponse wrapper struct. Updated Provider interface methods (Deploy, Preview, CdCommand) to return wrapped response types instead of raw protobuf types.
BYOC interface
src/pkg/cli/client/byoc/baseclient.go
Updated ProjectBackend.CdCommand signature to return *client.CdCommandResponse instead of types.ETag.
AWS BYOC implementation
src/pkg/cli/client/byoc/aws/byoc.go
Updated Deploy, Preview, and CdCommand return types to use wrapped response objects; now populates CdType as CD_TYPE_AWS_CODEBUILD_BUILDID and CdId from CodeBuild build ID in responses.
GCP BYOC implementation
src/pkg/cli/client/byoc/gcp/byoc.go, src/pkg/cli/client/byoc/gcp/byoc_test.go
Refactored to track Cloud Build buildId and propagate it through CD operations; updated Deploy, Preview, CdCommand return types to wrapped forms; GetDeploymentStatus now uses cdBuildId instead of cdExecution. Test updated to reflect new signature and naming.
DigitalOcean BYOC implementation
src/pkg/cli/client/byoc/do/byoc.go
Updated Deploy, Preview, and CdCommand return types to wrapped forms; now captures runCdCommand result to populate CdId and CdType from deployment ID.
Playground provider
src/pkg/cli/client/playground.go
Updated Deploy, Preview, and CdCommand method signatures to return wrapped response types; wraps internal responses appropriately.
CLI CD command handling
src/pkg/cli/cd.go
Updated to work with CdCommandResponse object instead of raw etag; now passes CdId and CdType metadata to putDeploymentAndStack when recording deployment history for down/destroy/refresh operations.
CLI deployment recording
src/pkg/cli/common.go
Extended putDeploymentParams struct with CdType and CdId fields; putDeploymentAndStack now populates these on Deployment proto message.
CLI compose operations
src/pkg/cli/composeUp.go, src/pkg/cli/composeUp_test.go
Updated to receive *client.DeployResponse from provider; extracts and passes CdId/CdType to deployment recording. Test mock updated to return wrapped response type.
Test mocks
src/pkg/cli/composeDown_test.go, src/pkg/cli/destroy_test.go
Updated mock implementations and assertions to work with CdCommandResponse object instead of raw etag string.
Stacks utility
src/pkg/stacks/stacks.go
Minor update to Marshal method with TODO comment regarding trailing newline handling (no functional change).

Sequence Diagram(s)

sequenceDiagram
    participant CLI as CLI (cd.go)
    participant Provider as Provider
    participant BYOC as BYOC (aws/gcp/do)
    participant Recorder as Deployment Recorder

    CLI->>Provider: CdCommand(ctx, request)
    Provider->>BYOC: runCdCommand()
    BYOC-->>Provider: buildId/deploymentId
    Provider->>BYOC: Extract CD metadata
    BYOC-->>Provider: CdCommandResponse {ETag, CdId, CdType}
    Provider-->>CLI: CdCommandResponse {ETag, CdId, CdType}
    
    CLI->>Recorder: putDeploymentAndStack(params with CdId, CdType)
    Recorder->>Recorder: Populate Deployment.cd_id, Deployment.cd_type
    Recorder-->>CLI: Success
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • jordanstephens

Poem

🐰 A rabbit's ode to tracking deployments:

Etags once bare, now wrapped in glory bright,
CD metadata flows through day and night,
From AWS, GCP, and cloud so grand,
CdIds and CdTypes across the land! 🚀✨
Building history, one deployment true.

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 16.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: adding CD task/job/build ID tracking to the Deployment message, which is the core objective across all modified files.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch lio/cdid-deployment

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/pkg/cli/cd.go`:
- Around line 41-44: The code currently treats a nil or incomplete provider
response as success when err == nil; update the post-call check after
provider.CdCommand(ctx, client.CdCommandRequest{...}) to return a non-nil error
if cd == nil or cd.ETag == "" (e.g., fmt.Errorf("invalid CdCommand response: cd
is nil or missing ETag")) instead of returning "", nil so incomplete responses
are surfaced; adjust the caller expectations accordingly.

In `@src/pkg/cli/client/byoc/aws/byoc.go`:
- Around line 295-302: The code dereferences cdBuildId when building the
DeployResponse; add a nil check for cdBuildId returned from runCdCommand (or
AwsCodeBuild.Run) before using *cdBuildId and return a clear error if it's nil.
Update the function that constructs the DeployResponse (where
DeployResponse.CdId is set) to validate cdBuildId != nil, mirror the guard logic
used in QueryBuildID/TailBuildID, and avoid creating the response when cdBuildId
is nil so you don't panic.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: a34e55a8-4fca-4339-b2a0-7b120012c493

📥 Commits

Reviewing files that changed from the base of the PR and between b856ef0 and 1426eaf.

⛔ Files ignored due to path filters (1)
  • src/protos/io/defang/v1/fabric.pb.go is excluded by !**/*.pb.go
📒 Files selected for processing (15)
  • src/pkg/cli/cd.go
  • src/pkg/cli/client/byoc/aws/byoc.go
  • src/pkg/cli/client/byoc/baseclient.go
  • src/pkg/cli/client/byoc/do/byoc.go
  • src/pkg/cli/client/byoc/gcp/byoc.go
  • src/pkg/cli/client/byoc/gcp/byoc_test.go
  • src/pkg/cli/client/playground.go
  • src/pkg/cli/client/provider.go
  • src/pkg/cli/common.go
  • src/pkg/cli/composeDown_test.go
  • src/pkg/cli/composeUp.go
  • src/pkg/cli/composeUp_test.go
  • src/pkg/cli/destroy_test.go
  • src/pkg/stacks/stacks.go
  • src/protos/io/defang/v1/fabric.proto

Comment thread src/pkg/cli/cd.go
Comment thread src/pkg/cli/client/byoc/aws/byoc.go
@lionello lionello merged commit 55f6f82 into main Apr 7, 2026
14 checks passed
@lionello lionello deleted the lio/cdid-deployment branch April 7, 2026 21:07
@coderabbitai coderabbitai Bot mentioned this pull request May 5, 2026
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants