Skip to content

Add lifecycle rule to cd bucket to only keep last 10 deployment as version #1261

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

edwardrf
Copy link
Contributor

Description

To prevent cd bucket to become too big.

Sample life cycle rule:
Screenshot from 2025-06-16 11-28-56

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

@edwardrf edwardrf requested review from lionello and Copilot June 16, 2025 18:32
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds an S3 bucket lifecycle rule in the CloudFormation template to automatically expire noncurrent object versions, limiting retention by age and version count.

  • Introduces a LifecycleConfiguration with a NoncurrentVersionExpiration rule.
  • Configures retention to delete versions older than 10 days and keep only the latest 10 versions.
Comments suppressed due to low confidence (2)

src/pkg/clouds/aws/ecs/cfn/template.go:87

  • No tests cover the new lifecycle configuration. Consider adding or updating unit tests to verify that the template includes the expected LifecycleConfiguration and expiration rules.
LifecycleConfiguration: &s3.Bucket_LifecycleConfiguration{

src/pkg/clouds/aws/ecs/cfn/template.go:87

  • The project README or CLI documentation should be updated to mention the new bucket lifecycle rules so users know about automatic version cleanup.
LifecycleConfiguration: &s3.Bucket_LifecycleConfiguration{

Comment on lines +94 to +95
NoncurrentDays: 10, // Keep deployments for at least 10 days
NewerNoncurrentVersions: ptr.Int(10), // Keep last 10 deployments
Copy link
Preview

Copilot AI Jun 16, 2025

Choose a reason for hiding this comment

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

[nitpick] Extract the literal 10 into a named constant (e.g., retentionDays or maxVersions) to avoid magic numbers and simplify future updates.

Suggested change
NoncurrentDays: 10, // Keep deployments for at least 10 days
NewerNoncurrentVersions: ptr.Int(10), // Keep last 10 deployments
NoncurrentDays: retentionDays, // Keep deployments for at least 10 days
NewerNoncurrentVersions: ptr.Int(maxVersions), // Keep last 10 deployments

Copilot uses AI. Check for mistakes.

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