mirror of
https://github.com/psviderski/uncloud.git
synced 2026-08-26 11:03:34 +00:00
feat(pre-deploy): correct progress events for pre-deploy hooks, make other container events more aligned with plan
This commit is contained in:
@@ -1,12 +1,49 @@
|
||||
package progress
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"context"
|
||||
|
||||
"github.com/docker/docker/pkg/stringid"
|
||||
"github.com/psviderski/uncloud/internal/cli/tui"
|
||||
)
|
||||
|
||||
// PreDeployHookEventID returns a progress event identifier for pre-deploy hook operations.
|
||||
type eventIDKey struct{}
|
||||
|
||||
// WithEventID returns a context that overrides the default event ID used by client methods.
|
||||
func WithEventID(ctx context.Context, eventID string) context.Context {
|
||||
return context.WithValue(ctx, eventIDKey{}, eventID)
|
||||
}
|
||||
|
||||
// ContainerEventID returns a progress event ID for operations on existing containers using the canonical
|
||||
// service_name/short_id format. Allows to override it using WithEventID.
|
||||
func ContainerEventID(ctx context.Context, serviceName, containerID, machineName string) string {
|
||||
if id, ok := ctx.Value(eventIDKey{}).(string); ok && id != "" {
|
||||
return id
|
||||
}
|
||||
return tui.Faint.Render("Container ") +
|
||||
serviceName + tui.Faint.Render("/") + stringid.TruncateID(containerID) +
|
||||
tui.Faint.Render(" on ") + machineName
|
||||
}
|
||||
|
||||
// NewContainerEventID returns a progress event ID for new container creation where the Docker container ID
|
||||
// is not yet known. Allows to override it using WithEventID.
|
||||
func NewContainerEventID(ctx context.Context, containerName, machineName string) string {
|
||||
if id, ok := ctx.Value(eventIDKey{}).(string); ok && id != "" {
|
||||
return id
|
||||
}
|
||||
return tui.Faint.Render("Container ") + containerName +
|
||||
tui.Faint.Render(" on ") + machineName
|
||||
}
|
||||
|
||||
// PreDeployHookEventID returns a progress event ID for pre-deploy hook operations.
|
||||
func PreDeployHookEventID(serviceName, machineName string) string {
|
||||
return fmt.Sprintf("Pre-deploy hook for %s on %s", tui.NameStyle.Render(serviceName), tui.Bold.Render(machineName))
|
||||
return tui.Faint.Render("Pre-deploy hook ") + serviceName +
|
||||
tui.Faint.Render(" on ") + machineName
|
||||
}
|
||||
|
||||
// OldPreDeployHookEventID returns a progress event ID for old pre-deploy hook container cleanup.
|
||||
func OldPreDeployHookEventID(serviceName, containerID, machineName string) string {
|
||||
return tui.Faint.Render("Old pre-deploy hook ") +
|
||||
serviceName + tui.Faint.Render("/") + stringid.TruncateID(containerID) +
|
||||
tui.Faint.Render(" on ") + machineName
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user