From be3a5aa7654b4ab7cc3580e8eae938207433b5bf Mon Sep 17 00:00:00 2001 From: fabriciojs Date: Sat, 10 Feb 2024 22:05:26 -0300 Subject: [PATCH] Report to API in case of error building deploy images --- commands/cloud_deploy.go | 4 ++++ services/cloud/api/deploy_error.go | 29 +++++++++++++++++++++++++++++ services/cloud/deployer.go | 7 +++++++ 3 files changed, 40 insertions(+) create mode 100644 services/cloud/api/deploy_error.go diff --git a/commands/cloud_deploy.go b/commands/cloud_deploy.go index 2cd722cc..21625d1c 100644 --- a/commands/cloud_deploy.go +++ b/commands/cloud_deploy.go @@ -107,6 +107,10 @@ func (d *KoolDeploy) Execute(args []string) (err error) { 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 { + d.Shell().Error(fmt.Errorf("error reporting build error: %v", reportErr)) + } + return } diff --git a/services/cloud/api/deploy_error.go b/services/cloud/api/deploy_error.go new file mode 100644 index 00000000..9862277b --- /dev/null +++ b/services/cloud/api/deploy_error.go @@ -0,0 +1,29 @@ +package api + +import "fmt" + +// DeployError consumes the API endpoint to inform a build error for a deployment +type DeployError struct { + Endpoint +} + +// NewDeployError creates a new DeployError instance +func NewDeployError(created *DeployCreateResponse, err error) (c *DeployError) { + c = &DeployError{ + Endpoint: NewDefaultEndpoint("POST"), + } + + c.SetPath("deploy/error") + c.Body().Set("id", fmt.Sprintf("%d", created.Deploy.ID)) + c.Body().Set("err", err.Error()) + + return +} + +// Run calls deploy/error in the Kool Dev API +func (c *DeployError) Run() (err error) { + var resp interface{} + c.SetResponseReceiver(&resp) + err = c.DoCall() + return +} diff --git a/services/cloud/deployer.go b/services/cloud/deployer.go index f2ad843a..4a1ee324 100644 --- a/services/cloud/deployer.go +++ b/services/cloud/deployer.go @@ -43,3 +43,10 @@ func (d *Deployer) StartDeploy(created *api.DeployCreateResponse) (started *api. started, err = start.Run() return } + +func (d *Deployer) BuildError(created *api.DeployCreateResponse, gotErr error) (err error) { + var buildErr = api.NewDeployError(created, gotErr) + + err = buildErr.Run() + return +}