mirror of
https://github.com/psviderski/uncloud.git
synced 2026-11-10 12:44:16 +00:00
Compare commits
12
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
965879b69f | ||
|
|
d66ec2bada | ||
|
|
20e2e97c36 | ||
|
|
e9eab32e6d | ||
|
|
7c6d1be8a7 | ||
|
|
a2987d3ff2 | ||
|
|
3351111feb | ||
|
|
bd695f65a3 | ||
|
|
7e8736fa99 | ||
|
|
8160c9b9d0 | ||
|
|
80d2a323c6 | ||
|
|
5d640b9a57 |
@@ -14,12 +14,13 @@ on:
|
||||
- "**.proto"
|
||||
- "go.*"
|
||||
- "Makefile"
|
||||
- "mise.toml"
|
||||
- "scripts/**"
|
||||
- "test/**"
|
||||
permissions:
|
||||
contents: read
|
||||
env:
|
||||
MISE_VERSION: "2026.3.7"
|
||||
MISE_VERSION: "2026.10.22"
|
||||
jobs:
|
||||
test:
|
||||
runs-on: ubuntu-latest
|
||||
@@ -42,9 +43,9 @@ jobs:
|
||||
|
||||
- name: Generate docs
|
||||
run: |
|
||||
make cli-docs
|
||||
mise run docs:cli
|
||||
git diff --exit-code ||
|
||||
(echo "Documentation is out of date. Please run 'make cli-docs' and commit the changes." && exit 1)
|
||||
(echo "Documentation is out of date. Please run 'mise run docs:cli' and commit the changes." && exit 1)
|
||||
|
||||
- name: Run tests
|
||||
run: |
|
||||
@@ -70,7 +71,7 @@ jobs:
|
||||
version: ${{ env.MISE_VERSION }}
|
||||
|
||||
# TODO: figure out how to properly lock all platforms in the lockfile and remove this hack.
|
||||
# `mise lock` (mise run mise:lock) doesn't generate checksums for some of the tools, e.g. protoc*
|
||||
# `mise lock` doesn't generate checksums for some of the tools, e.g. protoc*
|
||||
- name: Reset changes in mise.lock after fresh mise install
|
||||
run: git checkout mise.lock
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ on:
|
||||
permissions:
|
||||
contents: read
|
||||
env:
|
||||
MISE_VERSION: "2026.3.7"
|
||||
MISE_VERSION: "2026.10.22"
|
||||
jobs:
|
||||
lint:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
@@ -8,7 +8,7 @@ permissions:
|
||||
contents: write
|
||||
|
||||
env:
|
||||
MISE_VERSION: "2026.3.7"
|
||||
MISE_VERSION: "2026.10.22"
|
||||
|
||||
jobs:
|
||||
nightly:
|
||||
|
||||
+25
-2
@@ -35,10 +35,11 @@ Build the CLI:
|
||||
go build -o uc ./cmd/uc
|
||||
```
|
||||
|
||||
Or build and run the CLI with a single command:
|
||||
Or build and run the CLI with mise. It forwards arguments, including help flags, directly to the CLI:
|
||||
|
||||
```shell
|
||||
go run ./cmd/uc --help
|
||||
mise uc --help
|
||||
mise uc image rm -h
|
||||
```
|
||||
|
||||
The Uncloud daemon (`uncloudd`) only supports Linux, so you need to cross-compile it if you're developing on macOS or
|
||||
@@ -119,6 +120,28 @@ Regenerate mocks:
|
||||
mise run mocks
|
||||
```
|
||||
|
||||
## Documentation
|
||||
|
||||
Regenerate the CLI reference docs after changing commands or flags:
|
||||
|
||||
```shell
|
||||
mise run docs:cli
|
||||
```
|
||||
|
||||
To preview the documentation website, install its dependencies from the project root:
|
||||
|
||||
```shell
|
||||
npm ci --prefix website
|
||||
```
|
||||
|
||||
Then start the local development server:
|
||||
|
||||
```shell
|
||||
mise run docs:dev
|
||||
```
|
||||
|
||||
The server opens the site (http://localhost:3000/) in your browser and reloads it as you edit files in `website/`.
|
||||
|
||||
## Uncloud in Docker (UCinD)
|
||||
|
||||
The [`ucind`](./cmd/ucind) CLI lets you run Uncloud clusters locally using Docker containers instead of real machines.
|
||||
|
||||
@@ -65,7 +65,3 @@ _lint:
|
||||
# Explicitly set OS to Linux to not skip *_linux.go files when running on macOS.
|
||||
# Uncloud daemon won't likely support OS other than Linux anytime soon, so for now we can rely on that.
|
||||
GOOS=linux golangci-lint run $(ARGS)
|
||||
|
||||
.PHONY: cli-docs
|
||||
cli-docs:
|
||||
go run ./cmd/uc docs
|
||||
|
||||
+1
-10
@@ -22,15 +22,6 @@ func NewShowCommand() *cobra.Command {
|
||||
}
|
||||
|
||||
func show(uncli *cli.CLI) error {
|
||||
// discard errors, only show the current context, otherwise nothing
|
||||
if uncli.Config == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
if len(uncli.Config.Contexts) == 0 {
|
||||
return nil
|
||||
}
|
||||
fmt.Println(uncli.Config.CurrentContext)
|
||||
|
||||
fmt.Println(uncli.ContextOverrideOrCurrent())
|
||||
return nil
|
||||
}
|
||||
|
||||
+8
-3
@@ -91,9 +91,14 @@ func list(ctx context.Context, uncli *cli.CLI, opts listOptions) error {
|
||||
|
||||
machines := cli.ExpandCommaSeparatedValues(opts.machines)
|
||||
|
||||
clusterImages, err := clusterClient.ListImages(ctx, api.ImageFilter{
|
||||
Machines: machines,
|
||||
Name: opts.nameFilter,
|
||||
var clusterImages []api.MachineImages
|
||||
err = tui.RunSpinner(ctx, "Listing images...", func(ctx context.Context) error {
|
||||
var err error
|
||||
clusterImages, err = clusterClient.ListImages(ctx, api.ImageFilter{
|
||||
Machines: machines,
|
||||
Name: opts.nameFilter,
|
||||
})
|
||||
return err
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("list images: %w", err)
|
||||
|
||||
@@ -0,0 +1,137 @@
|
||||
package image
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"charm.land/lipgloss/v2"
|
||||
"github.com/docker/compose/v2/pkg/progress"
|
||||
"github.com/psviderski/uncloud/internal/cli"
|
||||
"github.com/psviderski/uncloud/internal/cli/completion"
|
||||
"github.com/psviderski/uncloud/internal/cli/tui"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
type removeOptions struct {
|
||||
machines []string
|
||||
yes bool
|
||||
}
|
||||
|
||||
func NewRemoveCommand() *cobra.Command {
|
||||
opts := removeOptions{}
|
||||
cmd := &cobra.Command{
|
||||
Use: "rm IMAGE [IMAGE...]",
|
||||
Aliases: []string{"remove", "delete"},
|
||||
Short: "Remove images from machines in the cluster.",
|
||||
Long: `Remove images from all or selected machines in the cluster.
|
||||
|
||||
An image name without a tag selects all its tags. Specify a tag, such as myapp:latest, to remove
|
||||
only that tag.
|
||||
|
||||
Wildcard patterns are supported for image names and tags and should be quoted to prevent your
|
||||
shell from expanding them. Removing by image ID attempts to remove each name for that image
|
||||
independently.
|
||||
|
||||
Images used by running or stopped containers cannot be removed. Unused tags can be removed even
|
||||
when the same image is used under another tag. Failed removals do not prevent other removals.`,
|
||||
Example: ` # Remove a tag from all machines after confirming the plan.
|
||||
uc image rm myapp:old
|
||||
|
||||
# Remove all tags for an image name from all machines.
|
||||
uc image rm myapp
|
||||
|
||||
# Remove matching tags from two machines without confirmation.
|
||||
uc image rm 'myapp:1.*' 'otherapp:*' -m machine1,machine2 --yes
|
||||
|
||||
# Remove all names for an image by ID from all machines.
|
||||
uc image rm ee8fed0e9618`,
|
||||
Args: cobra.MinimumNArgs(1),
|
||||
PreRun: func(cmd *cobra.Command, args []string) {
|
||||
cli.BindEnvToFlag(cmd, "yes", "UNCLOUD_AUTO_CONFIRM")
|
||||
},
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
uncli := cmd.Context().Value("cli").(*cli.CLI)
|
||||
return remove(cmd.Context(), uncli, args, opts)
|
||||
},
|
||||
}
|
||||
|
||||
cmd.Flags().StringSliceVarP(&opts.machines, "machine", "m", nil,
|
||||
"Machine names or IDs to remove images from. Can be specified multiple times or as a comma-separated list.\n"+
|
||||
"If not specified, the matching images will be removed from all machines.")
|
||||
cmd.Flags().BoolVarP(&opts.yes, "yes", "y", false,
|
||||
"Auto-confirm the removal plan. Should be explicitly set when running non-interactively,\n"+
|
||||
"e.g., in CI/CD pipelines. [$UNCLOUD_AUTO_CONFIRM]")
|
||||
|
||||
completion.MachinesFlag(cmd)
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
||||
func remove(ctx context.Context, uncli *cli.CLI, images []string, opts removeOptions) error {
|
||||
clusterClient, err := uncli.ConnectCluster(ctx)
|
||||
if err != nil {
|
||||
return fmt.Errorf("connect to cluster: %w", err)
|
||||
}
|
||||
defer clusterClient.Close()
|
||||
|
||||
plan, err := planImageRemoval(ctx, clusterClient, images, cli.ExpandCommaSeparatedValues(opts.machines))
|
||||
if err != nil {
|
||||
return fmt.Errorf("plan image removal: %w", err)
|
||||
}
|
||||
directConn := uncli.DirectConnection()
|
||||
contextName := uncli.ContextOverrideOrCurrent()
|
||||
cluster := ""
|
||||
if directConn != "" {
|
||||
cluster = directConn
|
||||
lipgloss.Println(tui.Faint.Render("connection: ") + tui.NameStyle.Render(directConn))
|
||||
lipgloss.Println()
|
||||
} else if contextName != "" && len(uncli.Config.Contexts) > 1 {
|
||||
// Only show context if there's more than one to avoid unnecessary clutter.
|
||||
cluster = contextName
|
||||
lipgloss.Println(tui.Faint.Render("context: ") + tui.NameStyle.Render(contextName))
|
||||
lipgloss.Println()
|
||||
}
|
||||
|
||||
lipgloss.Println(plan.Format())
|
||||
|
||||
if !opts.yes {
|
||||
if !tui.IsTerminalAvailable() {
|
||||
return errors.New("cannot ask to confirm image removal in non-interactive mode, " +
|
||||
"use --yes flag or set UNCLOUD_AUTO_CONFIRM=true to auto-confirm")
|
||||
}
|
||||
|
||||
title := "Proceed with image removal?"
|
||||
if cluster != "" {
|
||||
isDark := lipgloss.HasDarkBackground(os.Stdin, os.Stdout)
|
||||
confirmStyle := tui.ThemeConfirm().Theme(isDark).Focused.Title
|
||||
title = "Proceed with image removal on " + tui.NameStyle.Render(cluster) + confirmStyle.Render("?")
|
||||
}
|
||||
|
||||
confirmed, err := tui.Confirm(title)
|
||||
if err != nil {
|
||||
return fmt.Errorf("confirm image removal: %w", err)
|
||||
}
|
||||
if !confirmed {
|
||||
return cli.Cancelled("Image removal cancelled. No images were removed.")
|
||||
}
|
||||
}
|
||||
|
||||
untagged := make(map[string]bool)
|
||||
var errs []error
|
||||
for i, group := range plan.GroupPlans {
|
||||
if i > 0 {
|
||||
fmt.Println()
|
||||
}
|
||||
|
||||
err := progress.RunWithTitle(ctx, func(ctx context.Context) error {
|
||||
return group.Execute(ctx, clusterClient, untagged)
|
||||
}, uncli.ProgressOut(), "Removing image "+group.Image)
|
||||
if err != nil {
|
||||
errs = append(errs, err)
|
||||
}
|
||||
}
|
||||
|
||||
return errors.Join(errs...)
|
||||
}
|
||||
@@ -0,0 +1,426 @@
|
||||
package image
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"path"
|
||||
"regexp"
|
||||
"slices"
|
||||
"strings"
|
||||
|
||||
"charm.land/lipgloss/v2"
|
||||
"github.com/distribution/reference"
|
||||
"github.com/docker/docker/api/types/image"
|
||||
"github.com/docker/docker/pkg/stringid"
|
||||
"github.com/psviderski/uncloud/internal/cli/tui"
|
||||
"github.com/psviderski/uncloud/pkg/api"
|
||||
)
|
||||
|
||||
var imageIDRegex = regexp.MustCompile(`^(sha256:)?[a-f0-9]{4,64}$`)
|
||||
|
||||
// imageRemovalPlan contains all image removal operations grouped by the user-supplied image name, ID, or pattern.
|
||||
type imageRemovalPlan struct {
|
||||
GroupPlans []*removeImageGroupPlan
|
||||
}
|
||||
|
||||
func (p *imageRemovalPlan) IsEmpty() bool { return len(p.GroupPlans) == 0 }
|
||||
|
||||
func (p *imageRemovalPlan) Format() string {
|
||||
var out strings.Builder
|
||||
machines := make(map[string]struct{})
|
||||
removeCount := 0
|
||||
for _, group := range p.GroupPlans {
|
||||
out.WriteString(group.Format())
|
||||
for _, op := range group.Operations {
|
||||
machines[op.MachineName] = struct{}{}
|
||||
removeCount++
|
||||
}
|
||||
}
|
||||
|
||||
summary := fmt.Sprintf("%s remove %s across %s %s",
|
||||
tui.BoldRed.Render(fmt.Sprint(removeCount)),
|
||||
tui.Faint.Render("·"),
|
||||
tui.Bold.Render(fmt.Sprint(len(machines))),
|
||||
pluralMachines(len(machines)),
|
||||
)
|
||||
out.WriteString("\n" + tui.Faint.Render(strings.Repeat("─", lipgloss.Width(summary))) + "\n" + summary + "\n")
|
||||
|
||||
return out.String()
|
||||
}
|
||||
|
||||
func pluralMachines(count int) string {
|
||||
if count == 1 {
|
||||
return "machine"
|
||||
}
|
||||
return "machines"
|
||||
}
|
||||
|
||||
// Execute applies the frozen plan, collecting failures without discovering new targets.
|
||||
func (p *imageRemovalPlan) Execute(ctx context.Context, cli api.ImageClient) error {
|
||||
untagged := make(map[string]bool)
|
||||
var errs []error
|
||||
for _, group := range p.GroupPlans {
|
||||
if err := group.Execute(ctx, cli, untagged); err != nil {
|
||||
errs = append(errs, err)
|
||||
}
|
||||
}
|
||||
return errors.Join(errs...)
|
||||
}
|
||||
|
||||
// removeImageGroupPlan groups removals for one image name, ID, or pattern supplied by the user.
|
||||
type removeImageGroupPlan struct {
|
||||
// Image is the image name, ID, or pattern supplied by the user.
|
||||
Image string
|
||||
Operations []*removeImageOperation
|
||||
}
|
||||
|
||||
func (o *removeImageGroupPlan) Execute(ctx context.Context, cli api.ImageClient, untagged map[string]bool) error {
|
||||
var errs []error
|
||||
for _, op := range o.Operations {
|
||||
if err := ctx.Err(); err != nil {
|
||||
return errors.Join(append(errs, err)...)
|
||||
}
|
||||
if err := op.Execute(ctx, cli, untagged); err != nil {
|
||||
errs = append(errs, err)
|
||||
}
|
||||
}
|
||||
return errors.Join(errs...)
|
||||
}
|
||||
|
||||
func (o *removeImageGroupPlan) Format() string {
|
||||
var out strings.Builder
|
||||
out.WriteString(tui.BoldRed.Render("-") + " remove image " + tui.NameStyle.Render(o.Image) + "\n")
|
||||
for i, op := range o.Operations {
|
||||
branch := " ├── "
|
||||
if i == len(o.Operations)-1 {
|
||||
branch = " ╰── "
|
||||
}
|
||||
out.WriteString(tui.Faint.Render(branch) + op.Format() + "\n")
|
||||
}
|
||||
return out.String()
|
||||
}
|
||||
|
||||
func (o *removeImageGroupPlan) String() string {
|
||||
return fmt.Sprintf("removeImageGroupPlan[image=%s]", o.Image)
|
||||
}
|
||||
|
||||
// removeImageOperation removes an image name or an unnamed image by ID on a machine.
|
||||
type removeImageOperation struct {
|
||||
MachineName string
|
||||
ImageID string
|
||||
// Image is the exact image name or ID sent to Docker.
|
||||
Image string
|
||||
}
|
||||
|
||||
func (o *removeImageOperation) Execute(ctx context.Context, cli api.ImageClient, untagged map[string]bool) error {
|
||||
if untagged[o.MachineName+"\x00"+o.Image] {
|
||||
return nil
|
||||
}
|
||||
results, err := cli.RemoveImage(ctx, o.Image, api.RemoveImageOptions{Machines: []string{o.MachineName}})
|
||||
// A removal may also untag other planned names. Track actual results across all groups, per machine.
|
||||
for _, result := range results {
|
||||
for _, removal := range result.Results {
|
||||
if removal.Untagged != "" {
|
||||
untagged[result.Metadata.MachineName+"\x00"+removal.Untagged] = true
|
||||
}
|
||||
}
|
||||
}
|
||||
if errors.Is(err, api.ErrNotFound) {
|
||||
return nil
|
||||
}
|
||||
if err != nil {
|
||||
return fmt.Errorf("remove image '%s': %w", o.Image, err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (o *removeImageOperation) Format() string {
|
||||
return tui.BoldRed.Render("-") + " " + tui.FormatImage(o.Image, tui.NoStyle) +
|
||||
tui.Faint.Render(" ("+stringid.TruncateID(o.ImageID)+") on ") + o.MachineName
|
||||
}
|
||||
|
||||
func (o *removeImageOperation) String() string {
|
||||
return fmt.Sprintf("removeImageOperation[machine_name=%s image=%s]", o.MachineName, o.Image)
|
||||
}
|
||||
|
||||
type machineImageInventory struct {
|
||||
machineName string
|
||||
images []image.Summary
|
||||
}
|
||||
|
||||
// planImageRemoval builds a removal plan grouped by input argument from images on the selected machines.
|
||||
// An empty machines list selects all machines.
|
||||
//
|
||||
// Arguments expand as follows:
|
||||
// - Name: without a tag or digest, select all stored names in that exact repository across image IDs.
|
||||
// An explicit tag selects only that tag. Familiar names are normalised.
|
||||
// - ID: select all RepoTags for the matching image, or its full ID if unnamed. A prefix must identify
|
||||
// one unique full ID across the selected machines.
|
||||
// - Pattern: match RepoTags only. A matching digest also selects that image's names in the same repository.
|
||||
// - Digest: resolve through RepoTags, RepoDigests, or the image ID, then select that image's names in
|
||||
// the same repository. If none exist but RepoDigests contains the reference, select the digest itself.
|
||||
//
|
||||
// Selecting all tags for a repository/image on a machine also adds its stored digest references after
|
||||
// the tags, even if those digests did not match an argument. Stored names are kept as is, and overlapping
|
||||
// selections produce only one operation per machine and name.
|
||||
//
|
||||
// Failed image listings produce warnings and exclude those machines from the plan. If no machine can
|
||||
// be queried, planning fails. Every argument must match on a successfully queried machine. Unmatched
|
||||
// or invalid arguments and ambiguous ID prefixes reject the whole plan before any removal.
|
||||
//
|
||||
// Planning does not check container usage. The backend checks each removal during execution, and failures
|
||||
// do not stop other operations. Tag removal may implicitly untag a used digest. Execution skips names
|
||||
// already untagged by earlier operations and tolerates names that disappeared after planning.
|
||||
func planImageRemoval(ctx context.Context, cli api.ImageClient, images, machines []string) (*imageRemovalPlan, error) {
|
||||
if len(images) == 0 {
|
||||
return nil, errors.New("at least one image is required")
|
||||
}
|
||||
|
||||
var clusterImages []api.MachineImages
|
||||
err := tui.RunSpinner(ctx, "Finding images to remove...", func(ctx context.Context) error {
|
||||
var err error
|
||||
clusterImages, err = cli.ListImages(ctx, api.ImageFilter{Machines: machines})
|
||||
return err
|
||||
})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("list images: %w", err)
|
||||
}
|
||||
|
||||
var inventory []*machineImageInventory
|
||||
for _, machineImages := range clusterImages {
|
||||
if err := machineImages.Metadata.Err(); err != nil {
|
||||
tui.PrintWarning(fmt.Sprintf("failed to list images on machine '%s': %s",
|
||||
machineImages.Metadata.MachineName, err))
|
||||
continue
|
||||
}
|
||||
machine := &machineImageInventory{
|
||||
machineName: machineImages.Metadata.MachineName,
|
||||
images: machineImages.Images,
|
||||
}
|
||||
inventory = append(inventory, machine)
|
||||
}
|
||||
if len(inventory) == 0 {
|
||||
return nil, errors.New("failed to list images on any machine")
|
||||
}
|
||||
|
||||
return planImageRemovalFromInventory(images, inventory)
|
||||
}
|
||||
|
||||
func planImageRemovalFromInventory(images []string, inventory []*machineImageInventory) (*imageRemovalPlan, error) {
|
||||
plan := &imageRemovalPlan{}
|
||||
seen := make(map[string]bool)
|
||||
var errs []error
|
||||
for _, imageArg := range images {
|
||||
group := &removeImageGroupPlan{Image: imageArg}
|
||||
isID := imageIDRegex.MatchString(imageArg)
|
||||
isPattern := strings.ContainsAny(imageArg, "*?[")
|
||||
var namedRef reference.Named
|
||||
if isPattern {
|
||||
if _, err := path.Match(imageArg, ""); err != nil {
|
||||
return nil, fmt.Errorf("invalid image pattern '%s': %w", imageArg, err)
|
||||
}
|
||||
} else if !isID {
|
||||
var err error
|
||||
namedRef, err = reference.ParseNormalizedNamed(imageArg)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("invalid image '%s': %w", imageArg, err)
|
||||
}
|
||||
}
|
||||
if isID {
|
||||
matches := make(map[string]bool)
|
||||
for _, machine := range inventory {
|
||||
for _, img := range machine.images {
|
||||
if imageIDMatches(img.ID, imageArg) {
|
||||
matches[img.ID] = true
|
||||
}
|
||||
}
|
||||
}
|
||||
if len(matches) > 1 {
|
||||
var candidates []string
|
||||
for id := range matches {
|
||||
candidates = append(candidates, id)
|
||||
}
|
||||
slices.Sort(candidates)
|
||||
errs = append(errs,
|
||||
fmt.Errorf("image ID '%s' is ambiguous: %s", imageArg, strings.Join(candidates, ", ")))
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
matched := false
|
||||
for _, machine := range inventory {
|
||||
for _, img := range machine.images {
|
||||
var imagesToRemove []string
|
||||
switch {
|
||||
case isID:
|
||||
if !imageIDMatches(img.ID, imageArg) {
|
||||
continue
|
||||
}
|
||||
matched = true
|
||||
// Expand only stored names, matching uc image ls. RepoDigests remains available for digest lookup.
|
||||
imagesToRemove = img.RepoTags
|
||||
if len(imagesToRemove) == 0 {
|
||||
imagesToRemove = []string{img.ID}
|
||||
}
|
||||
case isPattern:
|
||||
for _, ref := range img.RepoTags {
|
||||
if ok, _ := path.Match(imageArg, ref); ok {
|
||||
named, _ := reference.ParseDockerRef(ref)
|
||||
if _, digest := named.(reference.Canonical); digest {
|
||||
imagesToRemove = append(imagesToRemove,
|
||||
imageRepositoryReferences(img.RepoTags, named.Name())...)
|
||||
} else {
|
||||
imagesToRemove = append(imagesToRemove, ref)
|
||||
}
|
||||
}
|
||||
}
|
||||
case reference.IsNameOnly(namedRef):
|
||||
imagesToRemove = imageRepositoryReferences(img.RepoTags, namedRef.Name())
|
||||
default:
|
||||
if canonical, digest := namedRef.(reference.Canonical); digest {
|
||||
ref := reference.FamiliarString(namedRef)
|
||||
if canonical.Digest().String() != img.ID && !slices.Contains(img.RepoTags, ref) &&
|
||||
!slices.Contains(img.RepoDigests, ref) {
|
||||
continue
|
||||
}
|
||||
imagesToRemove = imageRepositoryReferences(img.RepoTags, namedRef.Name())
|
||||
if len(imagesToRemove) == 0 && slices.Contains(img.RepoDigests, ref) {
|
||||
// An explicitly requested digest can resolve even when no stored name is listed.
|
||||
imagesToRemove = []string{ref}
|
||||
}
|
||||
} else if slices.Contains(img.RepoTags, reference.FamiliarString(namedRef)) {
|
||||
imagesToRemove = []string{reference.FamiliarString(namedRef)}
|
||||
}
|
||||
}
|
||||
for _, ref := range imagesToRemove {
|
||||
matched = true
|
||||
key := machine.machineName + "\x00" + ref
|
||||
if !seen[key] {
|
||||
seen[key] = true
|
||||
group.Operations = append(group.Operations, &removeImageOperation{
|
||||
MachineName: machine.machineName, ImageID: img.ID, Image: ref,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if !matched {
|
||||
errs = append(errs, fmt.Errorf("image '%s' not found on any machine", imageArg))
|
||||
}
|
||||
slices.SortFunc(group.Operations, compareImageRemovalOperations)
|
||||
if len(group.Operations) > 0 {
|
||||
plan.GroupPlans = append(plan.GroupPlans, group)
|
||||
}
|
||||
}
|
||||
|
||||
planDigestRemovals(plan, inventory)
|
||||
if err := errors.Join(errs...); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return plan, nil
|
||||
}
|
||||
|
||||
func imageRepositoryReferences(refs []string, repository string) []string {
|
||||
var matches []string
|
||||
for _, ref := range refs {
|
||||
if named, err := reference.ParseDockerRef(ref); err == nil && named.Name() == repository {
|
||||
matches = append(matches, ref)
|
||||
}
|
||||
}
|
||||
return matches
|
||||
}
|
||||
|
||||
// planDigestRemovals includes stored digests with the group removing their last repository tag.
|
||||
// RepoDigests also contains synthesised references, so only digest names stored in RepoTags get operations here.
|
||||
func planDigestRemovals(plan *imageRemovalPlan, inventory []*machineImageInventory) {
|
||||
type repository struct {
|
||||
remainingTags int
|
||||
digests []string
|
||||
}
|
||||
repositories := make(map[string]*repository)
|
||||
for _, machine := range inventory {
|
||||
for _, img := range machine.images {
|
||||
names := slices.Clone(img.RepoTags)
|
||||
slices.Sort(names)
|
||||
for _, ref := range slices.Compact(names) {
|
||||
named, err := reference.ParseDockerRef(ref)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
key := machine.machineName + "\x00" + img.ID + "\x00" + named.Name()
|
||||
repo := repositories[key]
|
||||
if repo == nil {
|
||||
repo = &repository{}
|
||||
repositories[key] = repo
|
||||
}
|
||||
if _, tagged := named.(reference.Tagged); tagged {
|
||||
repo.remainingTags++
|
||||
} else if _, digest := named.(reference.Canonical); digest {
|
||||
repo.digests = append(repo.digests, ref)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
emitted := make(map[string]bool)
|
||||
var groups []*removeImageGroupPlan
|
||||
for _, group := range plan.GroupPlans {
|
||||
var operations []*removeImageOperation
|
||||
for _, op := range group.Operations {
|
||||
key := op.MachineName + "\x00" + op.Image
|
||||
if emitted[key] {
|
||||
continue
|
||||
}
|
||||
emitted[key] = true
|
||||
operations = append(operations, op)
|
||||
named, err := reference.ParseDockerRef(op.Image)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
if _, tagged := named.(reference.Tagged); !tagged {
|
||||
continue
|
||||
}
|
||||
repo := repositories[op.MachineName+"\x00"+op.ImageID+"\x00"+named.Name()]
|
||||
if repo == nil {
|
||||
continue
|
||||
}
|
||||
repo.remainingTags--
|
||||
if repo.remainingTags != 0 {
|
||||
continue
|
||||
}
|
||||
for _, digest := range repo.digests {
|
||||
key := op.MachineName + "\x00" + digest
|
||||
if !emitted[key] {
|
||||
emitted[key] = true
|
||||
operations = append(operations, &removeImageOperation{
|
||||
MachineName: op.MachineName, ImageID: op.ImageID, Image: digest,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
group.Operations = operations
|
||||
slices.SortFunc(group.Operations, compareImageRemovalOperations)
|
||||
if len(group.Operations) > 0 {
|
||||
groups = append(groups, group)
|
||||
}
|
||||
}
|
||||
plan.GroupPlans = groups
|
||||
}
|
||||
|
||||
func compareImageRemovalOperations(a, b *removeImageOperation) int {
|
||||
aDigest, bDigest := strings.Contains(a.Image, "@"), strings.Contains(b.Image, "@")
|
||||
if aDigest != bDigest {
|
||||
if aDigest {
|
||||
return 1
|
||||
}
|
||||
return -1
|
||||
}
|
||||
if c := strings.Compare(a.Image, b.Image); c != 0 {
|
||||
return c
|
||||
}
|
||||
return strings.Compare(a.MachineName, b.MachineName)
|
||||
}
|
||||
|
||||
func imageIDMatches(id, prefix string) bool {
|
||||
return strings.HasPrefix(strings.TrimPrefix(id, "sha256:"), strings.TrimPrefix(prefix, "sha256:"))
|
||||
}
|
||||
@@ -0,0 +1,405 @@
|
||||
package image
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/docker/docker/api/types/image"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestPlanImageRemovalFromInventory_Selectors(t *testing.T) {
|
||||
idA, idB := testImageID("a"), testImageID("b")
|
||||
digestRef := "myapp@" + testImageID("c")
|
||||
tests := []struct {
|
||||
name string
|
||||
selector string
|
||||
inventory []*machineImageInventory
|
||||
want []removeImageOperation
|
||||
}{
|
||||
{
|
||||
name: "repository selects all stored names across images and machines", selector: "myapp",
|
||||
inventory: []*machineImageInventory{
|
||||
testMachineInventory("dev1", []image.Summary{
|
||||
testImage(idA, "myapp:old", "other:keep"),
|
||||
testImage(idB, "myapp:latest"),
|
||||
testImage(testImageID("c"), digestRef),
|
||||
testImage(testImageID("d"), "myapp-extra:latest", "team/myapp:latest", "myapp/worker:latest"),
|
||||
}),
|
||||
testMachineInventory("machine2", []image.Summary{testImage(idB, "myapp:test")}),
|
||||
},
|
||||
want: []removeImageOperation{
|
||||
{MachineName: "dev1", ImageID: idB, Image: "myapp:latest"},
|
||||
{MachineName: "dev1", ImageID: idA, Image: "myapp:old"},
|
||||
{MachineName: "machine2", ImageID: idB, Image: "myapp:test"},
|
||||
{MachineName: "dev1", ImageID: testImageID("c"), Image: digestRef},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "repository without latest includes its tags and stored digest", selector: "myapp",
|
||||
inventory: []*machineImageInventory{testMachineInventory("dev1", []image.Summary{
|
||||
testImage(idA, "myapp:old", digestRef, "other:keep"),
|
||||
})},
|
||||
want: []removeImageOperation{
|
||||
{MachineName: "dev1", ImageID: idA, Image: "myapp:old"},
|
||||
{MachineName: "dev1", ImageID: idA, Image: digestRef},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "explicit latest selects only that tag", selector: "myapp:latest",
|
||||
inventory: []*machineImageInventory{testMachineInventory("dev1", []image.Summary{
|
||||
testImage(idA, "myapp:old", "myapp:latest", digestRef),
|
||||
})},
|
||||
want: []removeImageOperation{{MachineName: "dev1", ImageID: idA, Image: "myapp:latest"}},
|
||||
},
|
||||
{
|
||||
name: "qualified repository selects familiar names", selector: "docker.io/library/myapp",
|
||||
inventory: []*machineImageInventory{testMachineInventory("dev1", []image.Summary{
|
||||
testImage(idA, "myapp:old", "myapp:latest", "other:keep"),
|
||||
})},
|
||||
want: []removeImageOperation{
|
||||
{MachineName: "dev1", ImageID: idA, Image: "myapp:latest"},
|
||||
{MachineName: "dev1", ImageID: idA, Image: "myapp:old"},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "registry port does not count as an explicit tag", selector: "registry.example.com:5000/team/myapp",
|
||||
inventory: []*machineImageInventory{testMachineInventory("dev1", []image.Summary{
|
||||
testImage(idA, "registry.example.com:5000/team/myapp:old", "registry.example.com:5000/team/myapp:new",
|
||||
"registry.example.com:5001/team/myapp:keep", "registry.example.com:5000/team/myapp/worker:keep"),
|
||||
})},
|
||||
want: []removeImageOperation{
|
||||
{MachineName: "dev1", ImageID: idA, Image: "registry.example.com:5000/team/myapp:new"},
|
||||
{MachineName: "dev1", ImageID: idA, Image: "registry.example.com:5000/team/myapp:old"},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "explicit tag with registry port stays exact", selector: "registry.example.com:5000/team/myapp:old",
|
||||
inventory: []*machineImageInventory{testMachineInventory("dev1", []image.Summary{
|
||||
testImage(idA, "registry.example.com:5000/team/myapp:old", "registry.example.com:5000/team/myapp:new"),
|
||||
})},
|
||||
want: []removeImageOperation{{MachineName: "dev1", ImageID: idA, Image: "registry.example.com:5000/team/myapp:old"}},
|
||||
},
|
||||
{
|
||||
name: "tag uses each machines local image and allows missing copies", selector: "myapp:old",
|
||||
inventory: []*machineImageInventory{
|
||||
testMachineInventory("machine2", []image.Summary{testImage(idB, "myapp:old")}),
|
||||
testMachineInventory("empty", nil),
|
||||
testMachineInventory("dev1", []image.Summary{testImage(idA, "myapp:old")}),
|
||||
},
|
||||
want: []removeImageOperation{
|
||||
{MachineName: "dev1", ImageID: idA, Image: "myapp:old"},
|
||||
{MachineName: "machine2", ImageID: idB, Image: "myapp:old"},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "qualified names use familiar references", selector: "docker.io/library/myapp:old",
|
||||
inventory: []*machineImageInventory{testMachineInventory("dev1", []image.Summary{
|
||||
testImage(idA, "myapp:old"),
|
||||
})},
|
||||
want: []removeImageOperation{{MachineName: "dev1", ImageID: idA, Image: "myapp:old"}},
|
||||
},
|
||||
{
|
||||
name: "full ID expands all repositories and deduplicates references per machine", selector: idA,
|
||||
inventory: []*machineImageInventory{
|
||||
testMachineInventory("dev1", []image.Summary{
|
||||
{
|
||||
ID: idA,
|
||||
RepoTags: []string{"other:keep", "myapp:old", "myapp:old", digestRef, "other@" + testImageID("c")},
|
||||
RepoDigests: []string{
|
||||
digestRef, "other@" + testImageID("c"), "other@" + testImageID("c"), testImageID("c"),
|
||||
},
|
||||
},
|
||||
testImage(idB, "unrelated:keep"),
|
||||
}),
|
||||
testMachineInventory("machine2", []image.Summary{{
|
||||
ID: idA, RepoTags: []string{"myapp:old", digestRef}, RepoDigests: []string{digestRef},
|
||||
}}),
|
||||
},
|
||||
want: []removeImageOperation{
|
||||
{MachineName: "dev1", ImageID: idA, Image: "myapp:old"},
|
||||
{MachineName: "machine2", ImageID: idA, Image: "myapp:old"},
|
||||
{MachineName: "dev1", ImageID: idA, Image: "other:keep"},
|
||||
{MachineName: "dev1", ImageID: idA, Image: digestRef},
|
||||
{MachineName: "machine2", ImageID: idA, Image: digestRef},
|
||||
{MachineName: "dev1", ImageID: idA, Image: "other@" + testImageID("c")},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "same full ID on multiple machines is unambiguous", selector: "aaaaaaaa",
|
||||
inventory: []*machineImageInventory{
|
||||
testMachineInventory("dev1", []image.Summary{testImage(idA, "myapp:old")}),
|
||||
testMachineInventory("dev1", []image.Summary{testImage(idB, "myapp:latest")}),
|
||||
testMachineInventory("machine2", []image.Summary{testImage(idA, "other:test")}),
|
||||
},
|
||||
want: []removeImageOperation{
|
||||
{MachineName: "dev1", ImageID: idA, Image: "myapp:old"},
|
||||
{MachineName: "machine2", ImageID: idA, Image: "other:test"},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "short ID with algorithm prefix", selector: "sha256:aaaaaaaa",
|
||||
inventory: []*machineImageInventory{testMachineInventory("dev1",
|
||||
[]image.Summary{testImage(idA, "myapp:old")})},
|
||||
want: []removeImageOperation{{MachineName: "dev1", ImageID: idA, Image: "myapp:old"}},
|
||||
},
|
||||
{
|
||||
name: "unnamed image is removed by its full ID", selector: idA,
|
||||
inventory: []*machineImageInventory{testMachineInventory("dev1", []image.Summary{{ID: idA}})},
|
||||
want: []removeImageOperation{{MachineName: "dev1", ImageID: idA, Image: idA}},
|
||||
},
|
||||
{
|
||||
name: "ID expands only stored names", selector: idA,
|
||||
inventory: []*machineImageInventory{testMachineInventory("dev1", []image.Summary{{
|
||||
ID: idA, RepoTags: []string{"myapp:latest"},
|
||||
RepoDigests: []string{"myapp@" + idA, "other@" + idA},
|
||||
}})},
|
||||
want: []removeImageOperation{{MachineName: "dev1", ImageID: idA, Image: "myapp:latest"}},
|
||||
},
|
||||
{
|
||||
name: "ID removes an untagged image by ID even if RepoDigests is populated", selector: idA,
|
||||
inventory: []*machineImageInventory{testMachineInventory("dev1", []image.Summary{{
|
||||
ID: idA, RepoDigests: []string{digestRef},
|
||||
}})},
|
||||
want: []removeImageOperation{{MachineName: "dev1", ImageID: idA, Image: idA}},
|
||||
},
|
||||
{
|
||||
name: "synthesized digest selects repository tags without a digest row", selector: digestRef,
|
||||
inventory: []*machineImageInventory{testMachineInventory("dev1", []image.Summary{{
|
||||
ID: idA, RepoTags: []string{"myapp:old", "other:keep", "myapp:latest"},
|
||||
RepoDigests: []string{digestRef, "other@" + testImageID("c")},
|
||||
}})},
|
||||
want: []removeImageOperation{
|
||||
{MachineName: "dev1", ImageID: idA, Image: "myapp:latest"},
|
||||
{MachineName: "dev1", ImageID: idA, Image: "myapp:old"},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "explicit digest lookup works without stored names", selector: digestRef,
|
||||
inventory: []*machineImageInventory{testMachineInventory("dev1", []image.Summary{{
|
||||
ID: idA, RepoDigests: []string{digestRef},
|
||||
}})},
|
||||
want: []removeImageOperation{{MachineName: "dev1", ImageID: idA, Image: digestRef}},
|
||||
},
|
||||
{
|
||||
name: "synthesized digest resolves by target and repository even if not listed", selector: "myapp@" + idA,
|
||||
inventory: []*machineImageInventory{testMachineInventory("dev1", []image.Summary{{
|
||||
ID: idA, RepoTags: []string{"myapp:old", "other:keep"}, RepoDigests: []string{"other@" + idA},
|
||||
}})},
|
||||
want: []removeImageOperation{{MachineName: "dev1", ImageID: idA, Image: "myapp:old"}},
|
||||
},
|
||||
{
|
||||
name: "stored digest follows its repository tags", selector: digestRef,
|
||||
inventory: []*machineImageInventory{testMachineInventory("dev1", []image.Summary{
|
||||
testImage(idA, "myapp:old", "myapp:latest", digestRef, "other:keep"),
|
||||
testImage(idB, "myapp@"+idB),
|
||||
})},
|
||||
want: []removeImageOperation{
|
||||
{MachineName: "dev1", ImageID: idA, Image: "myapp:latest"},
|
||||
{MachineName: "dev1", ImageID: idA, Image: "myapp:old"},
|
||||
{MachineName: "dev1", ImageID: idA, Image: digestRef},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "digest pattern also expands matching repository tags", selector: "myapp@sha256:c*",
|
||||
inventory: []*machineImageInventory{testMachineInventory("dev1", []image.Summary{
|
||||
testImage(idA, "myapp:old", "myapp:latest", digestRef, "other:keep"),
|
||||
testImage(idB, "myapp@"+idB),
|
||||
})},
|
||||
want: []removeImageOperation{
|
||||
{MachineName: "dev1", ImageID: idA, Image: "myapp:latest"},
|
||||
{MachineName: "dev1", ImageID: idA, Image: "myapp:old"},
|
||||
{MachineName: "dev1", ImageID: idA, Image: digestRef},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "digest pattern matches stored names and ignores derived names", selector: "myapp@sha256:*",
|
||||
inventory: []*machineImageInventory{testMachineInventory("dev1", []image.Summary{
|
||||
testImage(idA, "myapp:old", digestRef),
|
||||
{ID: idB, RepoTags: []string{"myapp:latest"}, RepoDigests: []string{"myapp@" + idB}},
|
||||
})},
|
||||
want: []removeImageOperation{
|
||||
{MachineName: "dev1", ImageID: idA, Image: "myapp:old"},
|
||||
{MachineName: "dev1", ImageID: idA, Image: digestRef},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "last repository tag includes its stored digest", selector: "myapp:old",
|
||||
inventory: []*machineImageInventory{testMachineInventory("dev1", []image.Summary{
|
||||
testImage(idA, "myapp:old", digestRef, "other:keep"),
|
||||
})},
|
||||
want: []removeImageOperation{
|
||||
{MachineName: "dev1", ImageID: idA, Image: "myapp:old"},
|
||||
{MachineName: "dev1", ImageID: idA, Image: digestRef},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "last tag does not add a synthesized digest row", selector: "myapp:old",
|
||||
inventory: []*machineImageInventory{testMachineInventory("dev1", []image.Summary{{
|
||||
ID: idA, RepoTags: []string{"myapp:old", "other:keep"}, RepoDigests: []string{digestRef},
|
||||
}})},
|
||||
want: []removeImageOperation{{MachineName: "dev1", ImageID: idA, Image: "myapp:old"}},
|
||||
},
|
||||
{
|
||||
name: "remaining repository tag preserves its stored digest", selector: "myapp:old",
|
||||
inventory: []*machineImageInventory{testMachineInventory("dev1", []image.Summary{
|
||||
testImage(idA, "myapp:old", "myapp:latest", digestRef),
|
||||
})},
|
||||
want: []removeImageOperation{{MachineName: "dev1", ImageID: idA, Image: "myapp:old"}},
|
||||
},
|
||||
{
|
||||
name: "digest without repository tags remains executable", selector: digestRef,
|
||||
inventory: []*machineImageInventory{testMachineInventory("dev1", []image.Summary{
|
||||
testImage(idA, digestRef, "other:keep"),
|
||||
})},
|
||||
want: []removeImageOperation{{MachineName: "dev1", ImageID: idA, Image: digestRef}},
|
||||
},
|
||||
{
|
||||
name: "digest-only image keeps its named reference", selector: idA,
|
||||
inventory: []*machineImageInventory{testMachineInventory("dev1", []image.Summary{{
|
||||
ID: idA, RepoTags: []string{digestRef}, RepoDigests: []string{digestRef, testImageID("c")},
|
||||
}})},
|
||||
want: []removeImageOperation{{MachineName: "dev1", ImageID: idA, Image: digestRef}},
|
||||
},
|
||||
{
|
||||
name: "tag pattern selects only matching tags", selector: "myapp:1.[12]",
|
||||
inventory: []*machineImageInventory{testMachineInventory("dev1", []image.Summary{{
|
||||
ID: idA, RepoTags: []string{"myapp:1.3", "myapp:1.2", "myapp:1.1"}, RepoDigests: []string{digestRef},
|
||||
}})},
|
||||
want: []removeImageOperation{
|
||||
{MachineName: "dev1", ImageID: idA, Image: "myapp:1.1"},
|
||||
{MachineName: "dev1", ImageID: idA, Image: "myapp:1.2"},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
plan, err := planImageRemovalFromInventory([]string{tt.selector}, tt.inventory)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, plan.GroupPlans, 1)
|
||||
assert.Equal(t, tt.selector, plan.GroupPlans[0].Image)
|
||||
|
||||
var got []removeImageOperation
|
||||
for _, op := range plan.GroupPlans[0].Operations {
|
||||
got = append(got, *op)
|
||||
}
|
||||
assert.Equal(t, tt.want, got)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestPlanImageRemovalFromInventory_OverlappingSelectors(t *testing.T) {
|
||||
inventory := []*machineImageInventory{
|
||||
testMachineInventory("dev1", []image.Summary{testImage(testImageID("a"), "myapp:old", "myapp:latest")}),
|
||||
testMachineInventory("machine2", []image.Summary{testImage(testImageID("b"), "myapp:test", "myapp:old")}),
|
||||
}
|
||||
|
||||
plan, err := planImageRemovalFromInventory([]string{"myapp:old", "myapp", "myapp:*", testImageID("a"), "myapp:old"},
|
||||
inventory)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, &imageRemovalPlan{GroupPlans: []*removeImageGroupPlan{
|
||||
{Image: "myapp:old", Operations: []*removeImageOperation{
|
||||
{MachineName: "dev1", ImageID: testImageID("a"), Image: "myapp:old"},
|
||||
{MachineName: "machine2", ImageID: testImageID("b"), Image: "myapp:old"},
|
||||
}},
|
||||
{Image: "myapp", Operations: []*removeImageOperation{
|
||||
{MachineName: "dev1", ImageID: testImageID("a"), Image: "myapp:latest"},
|
||||
{MachineName: "machine2", ImageID: testImageID("b"), Image: "myapp:test"},
|
||||
}},
|
||||
}}, plan, "the first selector owns each removal and empty groups are omitted")
|
||||
}
|
||||
|
||||
func TestPlanImageRemovalFromInventory_DigestFollowsLastTagAcrossSelectors(t *testing.T) {
|
||||
imageID := testImageID("a")
|
||||
digestRef := "myapp@" + imageID
|
||||
inventory := []*machineImageInventory{testMachineInventory("dev1", []image.Summary{
|
||||
testImage(imageID, "myapp:old", "myapp:latest", "myapp:old", digestRef, digestRef, "other:keep"),
|
||||
})}
|
||||
|
||||
plan, err := planImageRemovalFromInventory([]string{"myapp:old", "myapp:latest", digestRef}, inventory)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, &imageRemovalPlan{GroupPlans: []*removeImageGroupPlan{
|
||||
{Image: "myapp:old", Operations: []*removeImageOperation{
|
||||
{MachineName: "dev1", ImageID: imageID, Image: "myapp:old"},
|
||||
}},
|
||||
{Image: "myapp:latest", Operations: []*removeImageOperation{
|
||||
{MachineName: "dev1", ImageID: imageID, Image: "myapp:latest"},
|
||||
{MachineName: "dev1", ImageID: imageID, Image: digestRef},
|
||||
}},
|
||||
}}, plan, "digest cleanup belongs to the last tag removal, so the later digest selector has no extra operation")
|
||||
}
|
||||
|
||||
func TestPlanImageRemovalFromInventory_RejectsInvalidOrMissingSelectors(t *testing.T) {
|
||||
idA := "sha256:abcdef" + strings.Repeat("a", 58)
|
||||
idB := "sha256:abcdef" + strings.Repeat("b", 58)
|
||||
inventory := []*machineImageInventory{
|
||||
testMachineInventory("dev1", []image.Summary{{
|
||||
ID: idA, RepoTags: []string{"myapp:old"}, RepoDigests: []string{"myapp@" + idA, "derived@" + idA},
|
||||
}}),
|
||||
testMachineInventory("machine2", []image.Summary{{ID: idB, RepoTags: []string{"myapp:old"}}}),
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
images []string
|
||||
err string
|
||||
}{
|
||||
{"missing repository", []string{"missing"}, "not found"},
|
||||
{"repository only has a derived digest", []string{"derived"}, "not found"},
|
||||
{"missing tag", []string{"myapp:missing"}, "not found"},
|
||||
{"missing pattern", []string{"other:*"}, "not found"},
|
||||
{"pattern only matches a derived digest", []string{"myapp@sha256:*"}, "not found"},
|
||||
{"missing ID", []string{testImageID("c")}, "not found"},
|
||||
{"ambiguous ID prefix", []string{"abcdef"}, "ambiguous"},
|
||||
{"invalid name", []string{"MyApp:old"}, "invalid image"},
|
||||
{"invalid pattern", []string{"myapp:["}, "invalid image pattern"},
|
||||
{"one missing selector rejects the whole plan", []string{"myapp:old", "myapp:missing"}, "not found"},
|
||||
{"one invalid selector rejects the whole plan", []string{"myapp:old", "myapp:["}, "invalid image pattern"},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
plan, err := planImageRemovalFromInventory(tt.images, inventory)
|
||||
require.ErrorContains(t, err, tt.err)
|
||||
assert.Nil(t, plan, "a failed selector must not return a partial plan")
|
||||
})
|
||||
}
|
||||
|
||||
t.Run("ID prefix resolves within the supplied machines", func(t *testing.T) {
|
||||
plan, err := planImageRemovalFromInventory([]string{"abcdef"}, inventory[:1])
|
||||
require.NoError(t, err)
|
||||
require.Len(t, plan.GroupPlans, 1)
|
||||
require.Len(t, plan.GroupPlans[0].Operations, 1)
|
||||
assert.Equal(t, idA, plan.GroupPlans[0].Operations[0].ImageID)
|
||||
})
|
||||
}
|
||||
|
||||
func TestPlanImageRemovalFromInventory_InUseImagesAreStillPlanned(t *testing.T) {
|
||||
img := testImage(testImageID("a"), "myapp:old", "myapp:current")
|
||||
img.Containers = 1
|
||||
|
||||
for _, selector := range []string{"myapp", "myapp:current", img.ID, "myapp:*"} {
|
||||
t.Run(selector, func(t *testing.T) {
|
||||
plan, err := planImageRemovalFromInventory([]string{selector}, []*machineImageInventory{
|
||||
testMachineInventory("dev1", []image.Summary{img}),
|
||||
})
|
||||
require.NoError(t, err)
|
||||
assert.False(t, plan.IsEmpty(), "usage protection belongs to the backend at execution time")
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func testImageID(char string) string { return "sha256:" + strings.Repeat(char, 64) }
|
||||
|
||||
func testImage(imageID string, tags ...string) image.Summary {
|
||||
return image.Summary{ID: imageID, RepoTags: tags}
|
||||
}
|
||||
|
||||
func testMachineInventory(name string, images []image.Summary) *machineImageInventory {
|
||||
return &machineImageInventory{machineName: name, images: images}
|
||||
}
|
||||
@@ -13,6 +13,7 @@ func NewRootCommand() *cobra.Command {
|
||||
cmd.AddCommand(
|
||||
NewListCommand(),
|
||||
NewPushCommand(),
|
||||
NewRemoveCommand(),
|
||||
)
|
||||
|
||||
return cmd
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
|
||||
type eventIDKey struct{}
|
||||
|
||||
// WithEventID returns a context that overrides the default event ID used by client methods.
|
||||
// WithEventID returns a context that overrides the event ID already set in the context.
|
||||
func WithEventID(ctx context.Context, eventID string) context.Context {
|
||||
return context.WithValue(ctx, eventIDKey{}, eventID)
|
||||
}
|
||||
@@ -48,7 +48,7 @@ func OldPreDeployHookEventID(serviceName, containerID, machineName string) strin
|
||||
tui.Faint.Render(" on ") + machineName
|
||||
}
|
||||
|
||||
// ImageEventID returns a progress event ID for image pull operations.
|
||||
// ImageEventID returns a progress event ID for image operations on a machine.
|
||||
func ImageEventID(image, machineName string) string {
|
||||
return tui.Faint.Render("Image ") + image +
|
||||
tui.Faint.Render(" on ") + machineName
|
||||
|
||||
@@ -1,47 +1,58 @@
|
||||
# @generated - this file is auto-generated by `mise lock` https://mise.jdx.dev/dev-tools/mise-lock.html
|
||||
|
||||
lockfile_version = 3
|
||||
|
||||
[[tools."aqua:vektra/mockery"]]
|
||||
version = "3.8.1"
|
||||
backend = "aqua:vektra/mockery"
|
||||
specifiers = ["3.8.1"]
|
||||
|
||||
[tools."aqua:vektra/mockery"."platforms.linux-arm64"]
|
||||
checksum = "sha256:d1f481f3a6e9868dd3ad65da265238ee109ab3a5dd7508958d5811953696f452"
|
||||
checksum_source = "mise-versions"
|
||||
url = "https://github.com/vektra/mockery/releases/download/v3.8.1/mockery_3.8.1_Linux_arm64.tar.gz"
|
||||
url_api = "https://api.github.com/repos/vektra/mockery/releases/assets/632915757"
|
||||
|
||||
[tools."aqua:vektra/mockery"."platforms.linux-arm64-musl"]
|
||||
checksum = "sha256:d1f481f3a6e9868dd3ad65da265238ee109ab3a5dd7508958d5811953696f452"
|
||||
checksum_source = "mise-versions"
|
||||
url = "https://github.com/vektra/mockery/releases/download/v3.8.1/mockery_3.8.1_Linux_arm64.tar.gz"
|
||||
url_api = "https://api.github.com/repos/vektra/mockery/releases/assets/632915757"
|
||||
|
||||
[tools."aqua:vektra/mockery"."platforms.linux-x64"]
|
||||
checksum = "sha256:953c7d38b58dd6398b1c595f27caf8bbf27e9b733b49c404d2e124e86d2ae72a"
|
||||
checksum_source = "mise-versions"
|
||||
url = "https://github.com/vektra/mockery/releases/download/v3.8.1/mockery_3.8.1_Linux_x86_64.tar.gz"
|
||||
url_api = "https://api.github.com/repos/vektra/mockery/releases/assets/632915756"
|
||||
|
||||
[tools."aqua:vektra/mockery"."platforms.linux-x64-musl"]
|
||||
checksum = "sha256:953c7d38b58dd6398b1c595f27caf8bbf27e9b733b49c404d2e124e86d2ae72a"
|
||||
checksum_source = "mise-versions"
|
||||
url = "https://github.com/vektra/mockery/releases/download/v3.8.1/mockery_3.8.1_Linux_x86_64.tar.gz"
|
||||
url_api = "https://api.github.com/repos/vektra/mockery/releases/assets/632915756"
|
||||
|
||||
[tools."aqua:vektra/mockery"."platforms.macos-arm64"]
|
||||
checksum = "sha256:303a794484243906b37da0c37056f974bf94278c2e10d7b1372e6bd53a2d5034"
|
||||
checksum_source = "mise-versions"
|
||||
url = "https://github.com/vektra/mockery/releases/download/v3.8.1/mockery_3.8.1_Darwin_arm64.tar.gz"
|
||||
url_api = "https://api.github.com/repos/vektra/mockery/releases/assets/632915806"
|
||||
|
||||
[tools."aqua:vektra/mockery"."platforms.macos-x64"]
|
||||
checksum = "sha256:6882331344e946268b304dce042b01371a0213a896536413be8abe49d532ca6f"
|
||||
checksum_source = "mise-versions"
|
||||
url = "https://github.com/vektra/mockery/releases/download/v3.8.1/mockery_3.8.1_Darwin_x86_64.tar.gz"
|
||||
url_api = "https://api.github.com/repos/vektra/mockery/releases/assets/632915746"
|
||||
|
||||
[tools."aqua:vektra/mockery"."platforms.windows-x64"]
|
||||
checksum = "sha256:7a7458756e9d7bce5f9936b7a63394000f3affa751b9740e65350c4bdcb627dc"
|
||||
checksum_source = "mise-versions"
|
||||
url = "https://github.com/vektra/mockery/releases/download/v3.8.1/mockery_3.8.1_Windows_x86_64.tar.gz"
|
||||
url_api = "https://api.github.com/repos/vektra/mockery/releases/assets/632915759"
|
||||
|
||||
[[tools.go]]
|
||||
version = "1.26.1"
|
||||
backend = "core:go"
|
||||
specifiers = ["1.26.1"]
|
||||
|
||||
[tools.go."platforms.linux-arm64"]
|
||||
checksum = "sha256:a290581cfe4fe28ddd737dde3095f3dbeb7f2e4065cab4eae44dfc53b760c2f7"
|
||||
@@ -74,6 +85,7 @@ url = "https://dl.google.com/go/go1.26.1.windows-amd64.zip"
|
||||
[[tools.golangci-lint]]
|
||||
version = "2.11.2"
|
||||
backend = "aqua:golangci/golangci-lint"
|
||||
specifiers = ["2.11.2"]
|
||||
|
||||
[tools.golangci-lint."platforms.linux-arm64"]
|
||||
checksum = "sha256:c3c83c7ed003e881991af21361c487151abd37969927ed9062cd0b48f3cd1d8d"
|
||||
@@ -120,6 +132,7 @@ provenance = "github-attestations"
|
||||
[[tools.goreleaser]]
|
||||
version = "2.15.2"
|
||||
backend = "aqua:goreleaser/goreleaser"
|
||||
specifiers = ["2.15.2"]
|
||||
|
||||
[tools.goreleaser."platforms.linux-arm64"]
|
||||
checksum = "sha256:5db66761a98f6693161e49e1a95d28d2673a892ba60cb4a5e16736cafd41c4c9"
|
||||
@@ -166,6 +179,7 @@ provenance = "github-attestations"
|
||||
[[tools.node]]
|
||||
version = "22.20.0"
|
||||
backend = "core:node"
|
||||
specifiers = ["22.20.0"]
|
||||
|
||||
[tools.node."platforms.linux-arm64"]
|
||||
checksum = "sha256:4181609e03dcb9880e7e5bf956061ecc0503c77a480c6631d868cb1f65a2c7dd"
|
||||
@@ -199,98 +213,119 @@ url = "https://nodejs.org/dist/v22.20.0/node-v22.20.0-win-x64.zip"
|
||||
[[tools.protoc]]
|
||||
version = "27.3"
|
||||
backend = "aqua:protocolbuffers/protobuf/protoc"
|
||||
specifiers = ["27.3"]
|
||||
|
||||
[tools.protoc."platforms.linux-arm64"]
|
||||
checksum = "sha256:bdad36f3ad7472281d90568c4956ea2e203c216e0de005c6bd486f1920f2751c"
|
||||
url = "https://github.com/protocolbuffers/protobuf/releases/download/v27.3/protoc-27.3-linux-aarch_64.zip"
|
||||
url_api = "https://api.github.com/repos/protocolbuffers/protobuf/releases/assets/183006374"
|
||||
|
||||
[tools.protoc."platforms.linux-arm64-musl"]
|
||||
checksum = "sha256:bdad36f3ad7472281d90568c4956ea2e203c216e0de005c6bd486f1920f2751c"
|
||||
url = "https://github.com/protocolbuffers/protobuf/releases/download/v27.3/protoc-27.3-linux-aarch_64.zip"
|
||||
url_api = "https://api.github.com/repos/protocolbuffers/protobuf/releases/assets/183006374"
|
||||
|
||||
[tools.protoc."platforms.linux-x64"]
|
||||
checksum = "blake3:8c2938accf7061164ea3968529a47ced1db4824ca553857f6903c68ae4347739"
|
||||
checksum = "sha256:6dab2adab83f915126cab53540d48957c40e9e9023969c3e84d44bfb936c7741"
|
||||
url = "https://github.com/protocolbuffers/protobuf/releases/download/v27.3/protoc-27.3-linux-x86_64.zip"
|
||||
url_api = "https://api.github.com/repos/protocolbuffers/protobuf/releases/assets/183006380"
|
||||
|
||||
[tools.protoc."platforms.linux-x64-musl"]
|
||||
checksum = "sha256:6dab2adab83f915126cab53540d48957c40e9e9023969c3e84d44bfb936c7741"
|
||||
url = "https://github.com/protocolbuffers/protobuf/releases/download/v27.3/protoc-27.3-linux-x86_64.zip"
|
||||
url_api = "https://api.github.com/repos/protocolbuffers/protobuf/releases/assets/183006380"
|
||||
|
||||
[tools.protoc."platforms.macos-arm64"]
|
||||
checksum = "sha256:b22116bd97cdbd7ea25346abe635a9df268515fe5ef5afa93cd9a68fc2513f84"
|
||||
url = "https://github.com/protocolbuffers/protobuf/releases/download/v27.3/protoc-27.3-osx-aarch_64.zip"
|
||||
url_api = "https://api.github.com/repos/protocolbuffers/protobuf/releases/assets/183006383"
|
||||
|
||||
[tools.protoc."platforms.macos-x64"]
|
||||
checksum = "sha256:ce282648fed0e7fbd6237d606dc9ec168dd2c1863889b04efa0b19c47da65d1b"
|
||||
url = "https://github.com/protocolbuffers/protobuf/releases/download/v27.3/protoc-27.3-osx-x86_64.zip"
|
||||
url_api = "https://api.github.com/repos/protocolbuffers/protobuf/releases/assets/183006381"
|
||||
|
||||
[tools.protoc."platforms.windows-x64"]
|
||||
checksum = "sha256:bdccd341a0c25ff4f65d8530f170c78ce5681e42920aa5d892f27ac06cc3bba0"
|
||||
url = "https://github.com/protocolbuffers/protobuf/releases/download/v27.3/protoc-27.3-win64.zip"
|
||||
url_api = "https://api.github.com/repos/protocolbuffers/protobuf/releases/assets/183006385"
|
||||
|
||||
[[tools.protoc-gen-go]]
|
||||
version = "1.34.2"
|
||||
backend = "aqua:protocolbuffers/protobuf-go/protoc-gen-go"
|
||||
specifiers = ["1.34.2"]
|
||||
|
||||
[tools.protoc-gen-go."platforms.linux-arm64"]
|
||||
checksum = "sha256:63d400167e75ab9f6690688f6fdc6a9455aa20bc1faa71e32149dbd322f7f198"
|
||||
url = "https://github.com/protocolbuffers/protobuf-go/releases/download/v1.34.2/protoc-gen-go.v1.34.2.linux.arm64.tar.gz"
|
||||
url_api = "https://api.github.com/repos/protocolbuffers/protobuf-go/releases/assets/173109690"
|
||||
|
||||
[tools.protoc-gen-go."platforms.linux-arm64-musl"]
|
||||
checksum = "sha256:63d400167e75ab9f6690688f6fdc6a9455aa20bc1faa71e32149dbd322f7f198"
|
||||
url = "https://github.com/protocolbuffers/protobuf-go/releases/download/v1.34.2/protoc-gen-go.v1.34.2.linux.arm64.tar.gz"
|
||||
url_api = "https://api.github.com/repos/protocolbuffers/protobuf-go/releases/assets/173109690"
|
||||
|
||||
[tools.protoc-gen-go."platforms.linux-x64"]
|
||||
checksum = "blake3:f765e393e0f0b25070c13848d88f5e6303e66090132afa1b753e981507a4174e"
|
||||
checksum = "sha256:b87bc134dee55576a842141bf0ed27761c635d746780fce5dee038c6dd16554f"
|
||||
url = "https://github.com/protocolbuffers/protobuf-go/releases/download/v1.34.2/protoc-gen-go.v1.34.2.linux.amd64.tar.gz"
|
||||
url_api = "https://api.github.com/repos/protocolbuffers/protobuf-go/releases/assets/173109692"
|
||||
|
||||
[tools.protoc-gen-go."platforms.linux-x64-musl"]
|
||||
checksum = "sha256:b87bc134dee55576a842141bf0ed27761c635d746780fce5dee038c6dd16554f"
|
||||
url = "https://github.com/protocolbuffers/protobuf-go/releases/download/v1.34.2/protoc-gen-go.v1.34.2.linux.amd64.tar.gz"
|
||||
url_api = "https://api.github.com/repos/protocolbuffers/protobuf-go/releases/assets/173109692"
|
||||
|
||||
[tools.protoc-gen-go."platforms.macos-arm64"]
|
||||
checksum = "sha256:17aca7f948dbb624049030cf841e35895cf34183ba006e721247fdeb95ff2780"
|
||||
url = "https://github.com/protocolbuffers/protobuf-go/releases/download/v1.34.2/protoc-gen-go.v1.34.2.darwin.arm64.tar.gz"
|
||||
url_api = "https://api.github.com/repos/protocolbuffers/protobuf-go/releases/assets/173109697"
|
||||
|
||||
[tools.protoc-gen-go."platforms.macos-x64"]
|
||||
checksum = "sha256:9b48d8f90add02e8e94e14962fed74e7ce2b2d6bda4dd42f1f4fbccf0f766f1a"
|
||||
url = "https://github.com/protocolbuffers/protobuf-go/releases/download/v1.34.2/protoc-gen-go.v1.34.2.darwin.amd64.tar.gz"
|
||||
url_api = "https://api.github.com/repos/protocolbuffers/protobuf-go/releases/assets/173109698"
|
||||
|
||||
[tools.protoc-gen-go."platforms.windows-x64"]
|
||||
checksum = "sha256:abafd39612177dd4e9a65207cadd5374a9352d8611e8e040f8462fcfa3010daf"
|
||||
url = "https://github.com/protocolbuffers/protobuf-go/releases/download/v1.34.2/protoc-gen-go.v1.34.2.windows.amd64.zip"
|
||||
url_api = "https://api.github.com/repos/protocolbuffers/protobuf-go/releases/assets/173109685"
|
||||
|
||||
[[tools.protoc-gen-go-grpc]]
|
||||
version = "1.5.1"
|
||||
backend = "aqua:grpc/grpc-go/protoc-gen-go-grpc"
|
||||
specifiers = ["1.5.1"]
|
||||
|
||||
[tools.protoc-gen-go-grpc."platforms.linux-arm64"]
|
||||
checksum = "sha256:370a7cfa5786e61e6fdc5aa8f689e35c2d27d036a49caac7aa25f962c89a01e8"
|
||||
url = "https://github.com/grpc/grpc-go/releases/download/cmd/protoc-gen-go-grpc/v1.5.1/protoc-gen-go-grpc.v1.5.1.linux.arm64.tar.gz"
|
||||
url_api = "https://api.github.com/repos/grpc/grpc-go/releases/assets/182572238"
|
||||
|
||||
[tools.protoc-gen-go-grpc."platforms.linux-arm64-musl"]
|
||||
checksum = "sha256:370a7cfa5786e61e6fdc5aa8f689e35c2d27d036a49caac7aa25f962c89a01e8"
|
||||
url = "https://github.com/grpc/grpc-go/releases/download/cmd/protoc-gen-go-grpc/v1.5.1/protoc-gen-go-grpc.v1.5.1.linux.arm64.tar.gz"
|
||||
url_api = "https://api.github.com/repos/grpc/grpc-go/releases/assets/182572238"
|
||||
|
||||
[tools.protoc-gen-go-grpc."platforms.linux-x64"]
|
||||
checksum = "blake3:197739132f0408f017d0c83773ac1ace85c0572473fdd658ec6e4ccbf20e0552"
|
||||
checksum = "sha256:a6cac4ea731e54aea304ad44d704a69d1cdc82997084b33637e21a89dc9229d6"
|
||||
url = "https://github.com/grpc/grpc-go/releases/download/cmd/protoc-gen-go-grpc/v1.5.1/protoc-gen-go-grpc.v1.5.1.linux.amd64.tar.gz"
|
||||
url_api = "https://api.github.com/repos/grpc/grpc-go/releases/assets/182572229"
|
||||
|
||||
[tools.protoc-gen-go-grpc."platforms.linux-x64-musl"]
|
||||
checksum = "sha256:a6cac4ea731e54aea304ad44d704a69d1cdc82997084b33637e21a89dc9229d6"
|
||||
url = "https://github.com/grpc/grpc-go/releases/download/cmd/protoc-gen-go-grpc/v1.5.1/protoc-gen-go-grpc.v1.5.1.linux.amd64.tar.gz"
|
||||
url_api = "https://api.github.com/repos/grpc/grpc-go/releases/assets/182572229"
|
||||
|
||||
[tools.protoc-gen-go-grpc."platforms.macos-arm64"]
|
||||
checksum = "sha256:d6083feb51dcfe59f26793e99ef01ef5eac68b64294ec2546711f614ac5878f3"
|
||||
url = "https://github.com/grpc/grpc-go/releases/download/cmd/protoc-gen-go-grpc/v1.5.1/protoc-gen-go-grpc.v1.5.1.darwin.arm64.tar.gz"
|
||||
url_api = "https://api.github.com/repos/grpc/grpc-go/releases/assets/182572243"
|
||||
|
||||
[tools.protoc-gen-go-grpc."platforms.macos-x64"]
|
||||
checksum = "sha256:c12c259d59c8b451f24b6abdad6d055fd0884c5268b7247fd7e5ec9d2432d1f1"
|
||||
url = "https://github.com/grpc/grpc-go/releases/download/cmd/protoc-gen-go-grpc/v1.5.1/protoc-gen-go-grpc.v1.5.1.darwin.amd64.tar.gz"
|
||||
url_api = "https://api.github.com/repos/grpc/grpc-go/releases/assets/182572208"
|
||||
|
||||
[tools.protoc-gen-go-grpc."platforms.windows-x64"]
|
||||
checksum = "sha256:c2ad1460c9e34b5b37759826da61220be6ee0a8a11431723d205512a69319991"
|
||||
url = "https://github.com/grpc/grpc-go/releases/download/cmd/protoc-gen-go-grpc/v1.5.1/protoc-gen-go-grpc.v1.5.1.windows.amd64.tar.gz"
|
||||
url_api = "https://api.github.com/repos/grpc/grpc-go/releases/assets/182572216"
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
[settings]
|
||||
experimental = true
|
||||
lockfile = true
|
||||
|
||||
[tools]
|
||||
"aqua:vektra/mockery" = "3.8.1"
|
||||
@@ -36,9 +37,14 @@ GOOS=linux GOARCH=arm64 go build -ldflags "-X github.com/psviderski/uncloud/inte
|
||||
"""
|
||||
outputs = ["uncloudd-linux-arm64"]
|
||||
|
||||
[tasks."mise:lock"]
|
||||
description = "Update mise.lock with hashes for all platforms"
|
||||
run = "mise lock --platform linux-x64,macos-arm64"
|
||||
[tasks."docs:cli"]
|
||||
description = "Regenerate the CLI reference docs"
|
||||
run = "go run ./cmd/uc docs"
|
||||
|
||||
[tasks."docs:dev"]
|
||||
description = "Run the documentation website locally"
|
||||
dir = "website"
|
||||
run = "npm start --"
|
||||
|
||||
[tasks.mocks]
|
||||
description = "Regenerate Go test mocks"
|
||||
@@ -53,10 +59,12 @@ protoc --go_out=. --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=p
|
||||
|
||||
[tasks.uc]
|
||||
description = "Run the Uncloud CLI"
|
||||
raw_args = true
|
||||
run = "go run ./cmd/uc"
|
||||
|
||||
[tasks.ucind]
|
||||
description = "Run ucind CLI for managing local Docker-based clusters"
|
||||
raw_args = true
|
||||
run = "go run ./cmd/ucind"
|
||||
|
||||
[tasks."ucind:image"]
|
||||
|
||||
+13
-5
@@ -18,14 +18,22 @@ npm run dev
|
||||
|
||||
`/docs` and `/blog` are built using [Docusaurus](https://docusaurus.io/), a modern static website generator.
|
||||
|
||||
### Local Development
|
||||
### Local development
|
||||
|
||||
```
|
||||
npm start
|
||||
To preview the documentation website, install its dependencies first:
|
||||
|
||||
```shell
|
||||
npm ci
|
||||
```
|
||||
|
||||
This command starts a local development server and opens up a browser window. Most changes are reflected live without
|
||||
having to restart the server.
|
||||
Then start the local development server:
|
||||
|
||||
```shell
|
||||
mise run docs:dev
|
||||
```
|
||||
|
||||
It opens up a browser window at http://localhost:3000/. Most changes are reflected live without having to restart the
|
||||
server.
|
||||
|
||||
## Deployment
|
||||
|
||||
|
||||
@@ -22,4 +22,5 @@ Manage images on machines in the cluster.
|
||||
* [uc](uc.md) - A CLI tool for managing Uncloud resources such as machines, services, and volumes.
|
||||
* [uc image ls](uc_image_ls.md) - List images on machines in the cluster.
|
||||
* [uc image push](uc_image_push.md) - Upload a local Docker image to the cluster.
|
||||
* [uc image rm](uc_image_rm.md) - Remove images from machines in the cluster.
|
||||
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
# uc image rm
|
||||
|
||||
Remove images from machines in the cluster.
|
||||
|
||||
## Synopsis
|
||||
|
||||
Remove images from all or selected machines in the cluster.
|
||||
|
||||
An image name without a tag selects all its tags. Specify a tag, such as myapp:latest, to remove
|
||||
only that tag.
|
||||
|
||||
Wildcard patterns are supported for image names and tags and should be quoted to prevent your
|
||||
shell from expanding them. Removing by image ID attempts to remove each name for that image
|
||||
independently.
|
||||
|
||||
Images used by running or stopped containers cannot be removed. Unused tags can be removed even
|
||||
when the same image is used under another tag. Failed removals do not prevent other removals.
|
||||
|
||||
```
|
||||
uc image rm IMAGE [IMAGE...] [flags]
|
||||
```
|
||||
|
||||
## Examples
|
||||
|
||||
```
|
||||
# Remove a tag from all machines after confirming the plan.
|
||||
uc image rm myapp:old
|
||||
|
||||
# Remove all tags for an image name from all machines.
|
||||
uc image rm myapp
|
||||
|
||||
# Remove matching tags from two machines without confirmation.
|
||||
uc image rm 'myapp:1.*' 'otherapp:*' -m machine1,machine2 --yes
|
||||
|
||||
# Remove all names for an image by ID from all machines.
|
||||
uc image rm ee8fed0e9618
|
||||
```
|
||||
|
||||
## Options
|
||||
|
||||
```
|
||||
-h, --help help for rm
|
||||
-m, --machine strings Machine names or IDs to remove images from. Can be specified multiple times or as a comma-separated list.
|
||||
If not specified, the matching images will be removed from all machines.
|
||||
-y, --yes Auto-confirm the removal plan. Should be explicitly set when running non-interactively,
|
||||
e.g., in CI/CD pipelines. [$UNCLOUD_AUTO_CONFIRM]
|
||||
```
|
||||
|
||||
## Options inherited from parent commands
|
||||
|
||||
```
|
||||
--connect string Connect to a remote cluster machine without using the Uncloud configuration file. [$UNCLOUD_CONNECT]
|
||||
Format: [ssh://]user@host[:port], ssh+go://user@host[:port], tcp://host:port, or unix:///path/to/uncloud.sock
|
||||
-c, --context string Name of the cluster context to use (default is the current context). [$UNCLOUD_CONTEXT]
|
||||
--uncloud-config string Path to the Uncloud configuration file. [$UNCLOUD_CONFIG] (default "~/.config/uncloud/config.yaml")
|
||||
```
|
||||
|
||||
## See also
|
||||
|
||||
* [uc image](uc_image.md) - Manage images on machines in the cluster.
|
||||
|
||||
Reference in New Issue
Block a user