feat: polish release v2 experience (#6800)
This commit is contained in:
1 parent
925b0fb801
commit
a4a903d7c3
295 files changed
+10627
-7115
No files matched your search
@@ -378,6 +378,13 @@ func IsPortConflict(err error) bool {
|
||||
strings.Contains(message, "failed programming external connectivity")
|
||||
}
|
||||
|
||||
func IsContainerNotFound(err error) bool {
|
||||
if err == nil {
|
||||
return false
|
||||
}
|
||||
return strings.Contains(strings.ToLower(err.Error()), "no such container")
|
||||
}
|
||||
|
||||
func Stop(name string) error { return StopContext(context.Background(), name) }
|
||||
|
||||
func Restart(name string) error { return RestartContext(context.Background(), name) }
|
||||
|
||||
@@ -132,6 +132,41 @@ func volumesInUse(ctx context.Context) map[string]bool {
|
||||
return inUse
|
||||
}
|
||||
|
||||
// InspectContainerVolumeMount verifies that a container with the expected owner
|
||||
// name uses the selected data volume and returns its immutable ID for removal.
|
||||
func InspectContainerVolumeMount(ctx context.Context, containerName, volumeName string) (string, bool, error) {
|
||||
out, err := exec.CommandContext(
|
||||
ctx,
|
||||
"docker",
|
||||
"container",
|
||||
"inspect",
|
||||
"--format",
|
||||
`{"id":{{json .Id}},"mounts":{{json .Mounts}}}`,
|
||||
containerName,
|
||||
).CombinedOutput()
|
||||
if err != nil {
|
||||
return "", false, fmt.Errorf("inspect container %s: %w: %s", containerName, err, strings.TrimSpace(string(out)))
|
||||
}
|
||||
var inspected struct {
|
||||
ID string `json:"id"`
|
||||
Mounts []struct {
|
||||
Name string `json:"Name"`
|
||||
} `json:"mounts"`
|
||||
}
|
||||
if err := json.Unmarshal(out, &inspected); err != nil {
|
||||
return "", false, fmt.Errorf("parse mounts for container %s: %w", containerName, err)
|
||||
}
|
||||
if inspected.ID == "" {
|
||||
return "", false, fmt.Errorf("inspect container %s: Docker returned an empty container ID", containerName)
|
||||
}
|
||||
for _, mount := range inspected.Mounts {
|
||||
if mount.Name == volumeName {
|
||||
return inspected.ID, true, nil
|
||||
}
|
||||
}
|
||||
return inspected.ID, false, nil
|
||||
}
|
||||
|
||||
// RemoveVolume deletes a volume and the instance data it holds.
|
||||
func RemoveVolume(ctx context.Context, name string) error {
|
||||
out, err := exec.CommandContext(ctx, "docker", "volume", "rm", name).CombinedOutput()
|
||||
|
||||
Reference in new issue
Block a user