Skip to content

Commit

Permalink
add prune command to remove old releases from S3. Closes #322
Browse files Browse the repository at this point in the history
  • Loading branch information
tj committed Apr 11, 2018
1 parent bc0d178 commit eb6a3fb
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 1 deletion.
1 change: 1 addition & 0 deletions cmd/up/main.go
Expand Up @@ -17,6 +17,7 @@ import (
_ "github.com/apex/up/internal/cli/domains" _ "github.com/apex/up/internal/cli/domains"
_ "github.com/apex/up/internal/cli/logs" _ "github.com/apex/up/internal/cli/logs"
_ "github.com/apex/up/internal/cli/metrics" _ "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/run"
_ "github.com/apex/up/internal/cli/stack" _ "github.com/apex/up/internal/cli/stack"
_ "github.com/apex/up/internal/cli/start" _ "github.com/apex/up/internal/cli/start"
Expand Down
6 changes: 6 additions & 0 deletions platform.go
Expand Up @@ -83,6 +83,12 @@ type Platform interface {
ShowMetrics(region, stage string, start time.Time) error 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 is the interface used by a platform to support
// runtime operations such as initializing environment // runtime operations such as initializing environment
// variables from remote storage. // variables from remote storage.
Expand Down
4 changes: 3 additions & 1 deletion platform/lambda/lambda.go
Expand Up @@ -846,7 +846,9 @@ func (p *Platform) removeProxy() error {


// getS3Key returns a randomized s3 key. // getS3Key returns a randomized s3 key.
func (p *Platform) getS3Key(stage string) string { 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. // getS3BucketName returns the s3 bucket name.
Expand Down
9 changes: 9 additions & 0 deletions reporter/text/text.go
Expand Up @@ -239,6 +239,15 @@ func (r *reporter) Start() {
default: default:
r.log(n, humanize.Comma(int64(e.Int("value")))) 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() r.prevTime = time.Now()
Expand Down
10 changes: 10 additions & 0 deletions up.go
Expand Up @@ -222,3 +222,13 @@ func (p *Project) ApplyStack(region string) error {


return p.Platform.ApplyStack(region) 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.