mirror of
https://github.com/psviderski/uncloud.git
synced 2026-08-26 19:13:34 +00:00
feat(deploy): print last logs from failed pre-deploy hook
This commit is contained in:
@@ -16,6 +16,14 @@ import (
|
||||
"github.com/psviderski/uncloud/pkg/api"
|
||||
)
|
||||
|
||||
// PreDeployHookError indicates that a pre-deploy hook container exited with a non-zero code or timed out.
|
||||
type PreDeployHookError struct {
|
||||
error
|
||||
ServiceName string
|
||||
ContainerID string
|
||||
MachineName string
|
||||
}
|
||||
|
||||
// DefaultPreDeployTimeout is the maximum duration to wait for a pre-deploy hook container to complete.
|
||||
const DefaultPreDeployTimeout = 5 * time.Minute
|
||||
|
||||
@@ -128,9 +136,14 @@ func (o *RunPreDeployOperation) waitForExit(
|
||||
return fmt.Errorf("pre-deploy hook container '%s': %w", ctrID, ctx.Err())
|
||||
}
|
||||
pw.Event(progress.NewEvent(eventID, progress.Error, fmt.Sprintf("Timeout (%s)", timeout)))
|
||||
return fmt.Errorf("pre-deploy hook container '%s' timed out after %s. "+
|
||||
"It's stopped and available for inspection. Fetch logs with 'uc logs %s'",
|
||||
ctrID, timeout, o.Spec.Name)
|
||||
return &PreDeployHookError{
|
||||
ServiceName: o.Spec.Name,
|
||||
ContainerID: containerID,
|
||||
MachineName: o.MachineName,
|
||||
error: fmt.Errorf("pre-deploy hook container '%s' timed out after %s. "+
|
||||
"It's stopped and available for inspection. View logs with 'uc logs %s'",
|
||||
ctrID, timeout, o.Spec.Name),
|
||||
}
|
||||
|
||||
case <-ticker.C:
|
||||
mc, err := cli.InspectContainer(ctx, o.ServiceID, containerID)
|
||||
@@ -157,9 +170,14 @@ func (o *RunPreDeployOperation) waitForExit(
|
||||
|
||||
pw.Event(progress.ErrorEvent(eventID))
|
||||
ctrID := fmt.Sprintf("%s/%s", o.Spec.Name, ctr.ShortID())
|
||||
return fmt.Errorf("pre-deploy hook container '%s' failed with exit code: %d. "+
|
||||
"It's stopped and available for inspection. Fetch logs with 'uc logs %s'",
|
||||
ctrID, ctr.State.ExitCode, o.Spec.Name)
|
||||
return &PreDeployHookError{
|
||||
ServiceName: o.Spec.Name,
|
||||
ContainerID: containerID,
|
||||
MachineName: o.MachineName,
|
||||
error: fmt.Errorf("pre-deploy hook container '%s' failed with exit code: %d. "+
|
||||
"It's stopped and available for inspection. View logs with 'uc logs %s'",
|
||||
ctrID, ctr.State.ExitCode, o.Spec.Name),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user