feat(deploy): print last logs from failed pre-deploy hook

This commit is contained in:
Pasha Sviderski
2026-04-22 12:43:19 +10:00
parent 5b5cd44d68
commit 8afe52367f
3 changed files with 78 additions and 7 deletions
+8
View File
@@ -12,6 +12,7 @@ type Client interface {
ContainerClient
DNSClient
ImageClient
LogsClient
MachineClient
ServiceClient
VolumeClient
@@ -43,6 +44,13 @@ type ImageClient interface {
InspectRemoteImage(ctx context.Context, id string) ([]MachineRemoteImage, error)
}
type LogsClient interface {
ServiceLogs(
ctx context.Context, serviceNameOrID string, opts ServiceLogsOptions,
) (Service, <-chan ServiceLogEntry, error)
MachineLogs(ctx context.Context, unit string, opts ServiceLogsOptions) (<-chan ServiceLogEntry, error)
}
type MachineClient interface {
InspectMachine(ctx context.Context, id string) (*pb.MachineMember, error)
ListMachines(ctx context.Context, filter *MachineFilter) (MachineMembersList, error)
+24 -6
View File
@@ -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),
}
}
}
}