github.com/orteth01/up@v0.2.0/internal/cli/deploy/deploy.go (about) 1 package deploy 2 3 import ( 4 "time" 5 6 "github.com/pkg/errors" 7 "github.com/tj/kingpin" 8 9 "github.com/apex/log" 10 "github.com/apex/up/internal/cli/root" 11 "github.com/apex/up/internal/stats" 12 "github.com/apex/up/internal/util" 13 ) 14 15 func init() { 16 cmd := root.Command("deploy", "Deploy the project.").Default() 17 stage := cmd.Arg("stage", "Target stage name.").Default("development").String() 18 cmd.Example(`up deploy`, "Deploy the project to the development stage.") 19 cmd.Example(`up deploy staging`, "Deploy the project to the staging stage.") 20 cmd.Example(`up deploy production`, "Deploy the project to the production stage.") 21 22 cmd.Action(func(_ *kingpin.ParseContext) error { 23 c, p, err := root.Init() 24 if err != nil { 25 return errors.Wrap(err, "initializing") 26 } 27 28 start := time.Now() 29 defer util.Pad()() 30 31 stats.Track("Deploy", map[string]interface{}{ 32 "duration": time.Since(start) / time.Millisecond, 33 "type": c.Type, 34 "regions": c.Regions, 35 "stage": *stage, 36 "header_rules_count": len(c.Headers), 37 "redirect_rules_count": len(c.Redirects), 38 "inject_rules_count": len(c.Inject), 39 "has_cors": c.CORS != nil, 40 "has_logs": !c.Logs.Disable, 41 }) 42 43 done := make(chan bool) 44 45 go func() { 46 defer close(done) 47 if err := stats.Client.Flush(); err != nil { 48 log.WithError(err).Warn("flushing analytics") 49 } 50 }() 51 52 if err := p.Deploy(*stage); err != nil { 53 return err 54 } 55 56 <-done 57 58 return nil 59 }) 60 }