Skip to content
Permalink
Browse files

add prune command to remove old releases from S3. Closes #322

  • Loading branch information...
tj committed Apr 11, 2018
1 parent bc0d178 commit eb6a3fbc7093a479acb31bdf55b93eedee782280
Showing with 29 additions and 1 deletion.
  1. +1 −0 cmd/up/main.go
  2. +6 −0 platform.go
  3. +3 −1 platform/lambda/lambda.go
  4. +9 −0 reporter/text/text.go
  5. +10 −0 up.go
@@ -17,6 +17,7 @@ import (
_ "github.com/apex/up/internal/cli/domains"
_ "github.com/apex/up/internal/cli/logs"
_ "github.com/apex/up/internal/cli/metrics"
_ "github.com/apex/up/internal/cli/prune"
_ "github.com/apex/up/internal/cli/run"
_ "github.com/apex/up/internal/cli/stack"
_ "github.com/apex/up/internal/cli/start"
@@ -83,6 +83,12 @@ type Platform interface {
ShowMetrics(region, stage string, start time.Time) error
}

// 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
}

// Runtime is the interface used by a platform to support
// runtime operations such as initializing environment
// variables from remote storage.
@@ -846,7 +846,9 @@ func (p *Platform) removeProxy() error {

// getS3Key returns a randomized s3 key.
func (p *Platform) getS3Key(stage string) string {
return fmt.Sprintf("%s/%s/%s.zip", p.config.Name, stage, uniuri.New())
ts := time.Now().Unix()
uid := uniuri.New()
return fmt.Sprintf("%s/%s/%d-%s.zip", p.config.Name, stage, ts, uid)
}

// getS3BucketName returns the s3 bucket name.
@@ -239,6 +239,15 @@ func (r *reporter) Start() {
default:
r.log(n, humanize.Comma(int64(e.Int("value"))))
}
case "prune":
fmt.Printf("\n")
r.pending("prune", "removing old releases")
case "prune.complete":
n := e.Int("count")
b := e.Int64("size")
s := fmt.Sprintf("%d old files removed from S3 (%s)", n, humanize.Bytes(uint64(b)))
r.complete("prune", s, e.Duration("duration"))
fmt.Printf("\n")
}

r.prevTime = time.Now()
10 up.go
@@ -222,3 +222,13 @@ func (p *Project) ApplyStack(region string) error {

return p.Platform.ApplyStack(region)
}

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

return pruner.Prune(region, versions)
}

0 comments on commit eb6a3fb

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