github.com/franciscocpg/up@v0.1.10/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 production`, "Deploy the project to the production stage.")
    20  
    21  	cmd.Action(func(_ *kingpin.ParseContext) error {
    22  		c, p, err := root.Init()
    23  		if err != nil {
    24  			return errors.Wrap(err, "initializing")
    25  		}
    26  
    27  		start := time.Now()
    28  		defer util.Pad()()
    29  
    30  		stats.Track("Deploy", map[string]interface{}{
    31  			"duration":             time.Since(start) / time.Millisecond,
    32  			"type":                 c.Type,
    33  			"regions":              c.Regions,
    34  			"stage":                *stage,
    35  			"header_rules_count":   len(c.Headers),
    36  			"redirect_rules_count": len(c.Redirects),
    37  			"inject_rules_count":   len(c.Inject),
    38  			"has_cors":             c.CORS != nil,
    39  			"has_logs":             !c.Logs.Disable,
    40  		})
    41  
    42  		done := make(chan bool)
    43  
    44  		go func() {
    45  			defer close(done)
    46  			if err := stats.Client.Flush(); err != nil {
    47  				log.WithError(err).Warn("flushing analytics")
    48  			}
    49  		}()
    50  
    51  		if err := p.Deploy(*stage); err != nil {
    52  			return err
    53  		}
    54  
    55  		<-done
    56  
    57  		return nil
    58  	})
    59  }