Skip to content
Permalink
Browse files

add prune --stage flag. Closes #647

  • Loading branch information...
tj committed Apr 19, 2018
1 parent 86fffb7 commit 8c3ed9572e37897480cd4fb4d7c15c4466710aae
Showing with 54 additions and 9 deletions.
  1. +42 −0 docs/06-commands.md
  2. +7 −4 internal/cli/prune/prune.go
  3. +1 −1 platform.go
  4. +2 −2 platform/lambda/prune.go
  5. +2 −2 up.go
@@ -36,6 +36,7 @@ Commands:
logs Show log output.
metrics Show project metrics.
rollback Rollback to a previous deployment.
prune Prune old S3 deployments of a stage.
run Run a hook.
stack plan Plan configuration changes.
stack apply Apply configuration changes.
@@ -810,3 +811,44 @@ Upgrade to the specified version.
```
$ up upgrade -t 0.4.4
```


## Prune

Prune old S3 deployments of a stage.

```
Usage:
up prune [<flags>]
Flags:
-h, --help Output usage information.
-C, --chdir="." Change working directory.
-v, --verbose Enable verbose log output.
--format="text" Output formatter.
--version Show application version.
-s, --stage="staging" Target stage name.
-r, --retain=60 Number of versions to retain.
```

### Examples

Prune and retain the most recent 15 staging versions.

```
$ up prune
```

Prune and retain the most recent 60 production versions.

```
$ up prune -s production
```

Prune and retain the most recent 15 production versions.

```
$ up prune -s production -r 15
```
@@ -9,11 +9,13 @@ import (
)

func init() {
cmd := root.Command("prune", "Prune old S3 deployments.")
cmd := root.Command("prune", "Prune old S3 deployments of a stage.")

cmd.Example(`up prune`, "Prune and retain the most recent 60 versions.")
cmd.Example(`up prune --retain 15`, "Prune and retain the most recent 15 versions.")
cmd.Example(`up prune`, "Prune and retain the most recent 15 staging versions.")
cmd.Example(`up prune -s production`, "Prune and retain the most recent 60 production versions.")
cmd.Example(`up prune -s production -r 15`, "Prune and retain the most recent 15 production versions.")

stage := cmd.Flag("stage", "Target stage name.").Short('s').Default("staging").String()
versions := cmd.Flag("retain", "Number of versions to retain.").Short('r').Default("60").Int()

cmd.Action(func(_ *kingpin.ParseContext) error {
@@ -26,8 +28,9 @@ func init() {

stats.Track("Prune", map[string]interface{}{
"versions": *versions,
"stage": *stage,
})

return p.Prune(region, *versions)
return p.Prune(region, *stage, *versions)
})
}
@@ -89,7 +89,7 @@ type Platform interface {
// Pruner is the interface used to prune old versions and
// the artifacts associated such as S3 zip files for Lambda.
type Pruner interface {
Prune(region string, versions int) error
Prune(region, stage string, versions int) error
}

// Runtime is the interface used by a platform to support
@@ -13,7 +13,7 @@ import (
)

// Prune implementation.
func (p *Platform) Prune(region string, versions int) error {
func (p *Platform) Prune(region, stage string, versions int) error {
p.events.Emit("prune", nil)

if err := p.createRole(); err != nil {
@@ -22,7 +22,7 @@ func (p *Platform) Prune(region string, versions int) error {

s := s3.New(session.New(aws.NewConfig().WithRegion(region)))
b := aws.String(p.getS3BucketName(region))
prefix := p.config.Name + "/"
prefix := p.config.Name + "/" + stage + "/"

params := &s3.ListObjectsInput{
Bucket: b,
4 up.go
@@ -216,11 +216,11 @@ func (p *Project) ApplyStack(region string) error {
}

// Prune implementation.
func (p *Project) Prune(region string, versions int) error {
func (p *Project) Prune(region, stage string, versions int) error {
pruner, ok := p.Platform.(Pruner)
if !ok {
return errors.Errorf("platform does not support pruning")
}

return pruner.Prune(region, versions)
return pruner.Prune(region, stage, versions)
}

0 comments on commit 8c3ed95

Please sign in to comment.
You can’t perform that action at this time.