Skip to content

Commit 8c16a4b

Browse files
authored
Merge pull request #499 from kool-dev/deploy-build-error
Report to API in case of error building deploy images
2 parents 0301555 + be3a5aa commit 8c16a4b

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

commands/cloud_deploy.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,10 @@ func (d *KoolDeploy) Execute(args []string) (err error) {
107107
d.Shell().Info(" > Build deploy image for service: ", svcName)
108108

109109
if err = cloud.BuildPushImageForDeploy(svcName, svc, deployCreated); err != nil {
110+
if reportErr := deployer.BuildError(deployCreated, err); reportErr != nil {
111+
d.Shell().Error(fmt.Errorf("error reporting build error: %v", reportErr))
112+
}
113+
110114
return
111115
}
112116

services/cloud/api/deploy_error.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package api
2+
3+
import "fmt"
4+
5+
// DeployError consumes the API endpoint to inform a build error for a deployment
6+
type DeployError struct {
7+
Endpoint
8+
}
9+
10+
// NewDeployError creates a new DeployError instance
11+
func NewDeployError(created *DeployCreateResponse, err error) (c *DeployError) {
12+
c = &DeployError{
13+
Endpoint: NewDefaultEndpoint("POST"),
14+
}
15+
16+
c.SetPath("deploy/error")
17+
c.Body().Set("id", fmt.Sprintf("%d", created.Deploy.ID))
18+
c.Body().Set("err", err.Error())
19+
20+
return
21+
}
22+
23+
// Run calls deploy/error in the Kool Dev API
24+
func (c *DeployError) Run() (err error) {
25+
var resp interface{}
26+
c.SetResponseReceiver(&resp)
27+
err = c.DoCall()
28+
return
29+
}

services/cloud/deployer.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,10 @@ func (d *Deployer) StartDeploy(created *api.DeployCreateResponse) (started *api.
4343
started, err = start.Run()
4444
return
4545
}
46+
47+
func (d *Deployer) BuildError(created *api.DeployCreateResponse, gotErr error) (err error) {
48+
var buildErr = api.NewDeployError(created, gotErr)
49+
50+
err = buildErr.Run()
51+
return
52+
}

0 commit comments

Comments
 (0)