diff --git a/commands/cloud_deploy.go b/commands/cloud_deploy.go index 1693827..753a76b 100644 --- a/commands/cloud_deploy.go +++ b/commands/cloud_deploy.go @@ -75,6 +75,7 @@ func (d *KoolDeploy) Execute(args []string) (err error) { var ( filename string deployCreated *api.DeployCreateResponse + isVerbose = d.env.IsTrue("KOOL_VERBOSE") deployer = cloud.NewDeployer() ) @@ -97,10 +98,30 @@ func (d *KoolDeploy) Execute(args []string) (err error) { } s.Stop() + var chPingDone = make(chan bool) + go func() { + for { + select { + case <-chPingDone: + if isVerbose { + fmt.Println(" - ending deploy ping routine") + } + return + case <-time.After(30 * time.Second): + if isVerbose { + fmt.Println(" - going to ping API while local build runs") + } + if _, err = deployer.PingDeploy(deployCreated); err != nil { + d.Shell().Error(err) + } + } + } + }() + d.Shell().Info("Building images...") for svcName, svc := range d.cloudConfig.Cloud.Services { if svc.Build != nil { - d.Shell().Info(" > Build deploy image for service: ", svcName) + d.Shell().Info(" > Build deploy image for service '", svcName, "'") if err = cloud.BuildPushImageForDeploy(svcName, svc, deployCreated); err != nil { if reportErr := deployer.BuildError(deployCreated, err); reportErr != nil { @@ -110,10 +131,13 @@ func (d *KoolDeploy) Execute(args []string) (err error) { return } - d.Shell().Info(" > Image for service: ", svcName, " built & pushed successfully.") + d.Shell().Info(" > Image for service '", svcName, "' built & pushed successfully.") } } + // ends ping + chPingDone <- true + if deployCreated.LogsUrl != "" { d.Shell().Info(strings.Repeat("-", 40)) d.Shell().Info("Logs available at: ", deployCreated.LogsUrl) diff --git a/commands/root.go b/commands/root.go index 3c078e1..7cbd52a 100644 --- a/commands/root.go +++ b/commands/root.go @@ -6,6 +6,7 @@ import ( "kool-dev/kool/core/environment" "kool-dev/kool/core/parser" "kool-dev/kool/core/shell" + "kool-dev/kool/services/cloud/api" "os" "path" "path/filepath" @@ -52,6 +53,9 @@ var originalWorkingDir = "" func init() { AddCommands(rootCmd) + + // pass in the version + api.SetCliVersion(version) } // NewRootCmd creates the root command diff --git a/services/cloud/api/api.go b/services/cloud/api/api.go index e500410..9ffeb90 100644 --- a/services/cloud/api/api.go +++ b/services/cloud/api/api.go @@ -2,6 +2,8 @@ package api var ( apiBaseURL string = "https://kool.dev/api" + + cliVersion string ) // SetBaseURL defines the target Kool API URL to be used @@ -9,3 +11,8 @@ var ( func SetBaseURL(url string) { apiBaseURL = url } + +// SetCliVersion injects version to this package +func SetCliVersion(v string) { + cliVersion = v +} diff --git a/services/cloud/api/deploy_ping.go b/services/cloud/api/deploy_ping.go new file mode 100644 index 0000000..d99449c --- /dev/null +++ b/services/cloud/api/deploy_ping.go @@ -0,0 +1,34 @@ +package api + +import "fmt" + +// DeployPingResponse holds data returned from the deploy endpoint +type DeployPingResponse struct { + ID int `json:"id"` + Status string `json:"status"` +} + +// DeployPing consumes the API endpoint to create a new deployment +type DeployPing struct { + Endpoint +} + +// NewDeployPing creates a new DeployStart instance +func NewDeployPing(created *DeployCreateResponse) (c *DeployPing) { + c = &DeployPing{ + Endpoint: NewDefaultEndpoint("POST"), + } + + c.SetPath("deploy/ping") + c.Body().Set("id", fmt.Sprintf("%d", created.Deploy.ID)) + + return +} + +// Run calls deploy/ping in the Kool Dev API +func (c *DeployPing) Run() (resp *DeployPingResponse, err error) { + resp = &DeployPingResponse{} + c.SetResponseReceiver(resp) + err = c.DoCall() + return +} diff --git a/services/cloud/api/endpoint.go b/services/cloud/api/endpoint.go index 75601d1..bf73c65 100644 --- a/services/cloud/api/endpoint.go +++ b/services/cloud/api/endpoint.go @@ -189,6 +189,8 @@ func (e *DefaultEndpoint) DoCall() (err error) { return } + request.Header.Add("x-kool-cli-version", cliVersion) + if e.contentType != "" { request.Header.Add("Content-type", e.contentType) } diff --git a/services/cloud/deployer.go b/services/cloud/deployer.go index 28c2d14..367e37e 100644 --- a/services/cloud/deployer.go +++ b/services/cloud/deployer.go @@ -46,6 +46,13 @@ func (d *Deployer) StartDeploy(created *api.DeployCreateResponse) (started *api. return } +func (d *Deployer) PingDeploy(created *api.DeployCreateResponse) (pinged *api.DeployPingResponse, err error) { + var ping = api.NewDeployPing(created) + + pinged, err = ping.Run() + return +} + func (d *Deployer) BuildError(created *api.DeployCreateResponse, gotErr error) (err error) { var buildErr = api.NewDeployError(created, gotErr)