Documentation
¶
Overview ¶
Package uninstall removes each item that the CLI made: the container, the volumes, the images, the entries in the files of the apps, the keys of the instance in the key file, the legacy keychain items of the instance, the folders of the CLI, and at the end the binary. It also removes a 2.x install on request.
The functions take an engine interface and folder paths, so that the tests use fakes.
Index ¶
- Constants
- Variables
- func Confirm(in io.Reader, out io.Writer, yes bool) bool
- func DataVolume(instance string) string
- func EndLeases(ctx context.Context, hc *http.Client, base string, ks KeySource, ...) string
- func ExecOutput(ctx context.Context, e Engine, container string, cmd []string) ([]byte, []byte, int, error)
- func Failed(rs []Result) bool
- func FindLegacyEntries(file string) []string
- func HumanSize(n int64) string
- func IsNotFound(err error) bool
- func LegacyAppFiles(home, goos string) []string
- func Report(w io.Writer, rs []Result)
- func SelectContainer(ctx context.Context, e Engine) (string, error)
- func SpoolVolume(instance string) string
- func WriteBackup(ctx context.Context, e Engine, container, dest string) error
- type Binary
- type Config
- type Engine
- type KeySource
- type Legacy
- type LegacyPlan
- type NotFoundError
- type Plan
- type Result
- type Uninstaller
Constants ¶
const ( LabelManagedBy = "dev.mai.managed-by" ManagedByValue = "mai-cli" LabelInstance = "dev.mai.instance" LabelCompose = "com.docker.compose.project" )
Labels of the objects that the CLI makes.
const ( LegacyContainer = "mai" LegacyProject = "mai" LegacyRepo = "ghcr.io/monorithm/mai" )
Names of the 2.x install.
const ( Gone = "gone" Failure = "failure" Kept = "kept" Skipped = "skipped" )
States of a result.
const ConfigFile = "config.json"
ConfigFile is the name of the configuration file in the configuration folder.
const DefaultInstance = "mai"
DefaultInstance is the instance of a command with no --instance and no config.json.
Variables ¶
var IsKept func(error) bool
IsKept reports if an error of RemoveAppEntry means that the entry stays, because other content of the file needs it. nil counts each error as a failure.
var LegacyVolumes = []string{"mai_mai-data", "mai_mai-spool", "mai_mai-volume"}
LegacyVolumes are the named volumes of the 2.x compose files.
var RemoveAppEntry func(manifest.Item) error
RemoveAppEntry removes one entry that mai connect wrote in a file of an app. The part of the CLI that writes the entries sets it. When it is nil, the uninstall keeps each entry and shows a warning.
var RemoveCreatedAppFile func(manifest.Item) (bool, error)
RemoveCreatedAppFile removes a file of an app that mai connect made, only when the file holds nothing of the user after the remove of the entries. The result is false for a file that stays. The part of the CLI that writes app entries sets it; nil keeps each such file.
Functions ¶
func DataVolume ¶
DataVolume is the name of the data volume of an instance.
func EndLeases ¶
func EndLeases(ctx context.Context, hc *http.Client, base string, ks KeySource, instance string) string
EndLeases ends each lease of the server through the owner API. It never fails: it gives a line of text that tells what it did. The bridges stop at their next call.
func ExecOutput ¶
func ExecOutput(ctx context.Context, e Engine, container string, cmd []string) ([]byte, []byte, int, error)
ExecOutput runs a command in the container and gives its standard output and exit code.
func FindLegacyEntries ¶
FindLegacyEntries reads one configuration file of an app and gives each 2.x MCP entry in it. It never changes the file.
func IsNotFound ¶
IsNotFound tells if an engine error means that the object does not exist. The client keeps the error class out of reach without a further module, thus the text of the answer of the engine is also examined.
func LegacyAppFiles ¶
LegacyAppFiles gives the configuration files of the apps that can hold a 2.x MCP entry.
func SelectContainer ¶
SelectContainer gives the ID of the 2.x container "mai", or "". It selects a container only when it has the compose project label "mai" and no label of the 3.0 CLI.
func SpoolVolume ¶
SpoolVolume is the name of the spool volume of an instance.
Types ¶
type Binary ¶
type Binary struct {
Path string // the executable, with the symbolic links resolved
GOOS string
// Run runs a package manager and waits for it.
Run func(name string, args ...string) error
// Start starts a process that continues after the exit of mai.
Start func(name string, args ...string) error
}
Binary removes the executable of the CLI as the last step.
type Config ¶
type Config struct {
Instance string `json:"instance"`
Port int `json:"port"`
Image string `json:"image"`
DataDir string `json:"data_dir"`
}
Config is the part of config.json that the uninstall reads. A missing file or field gives the default value.
func LoadConfig ¶
LoadConfig reads <dir>/config.json and sets the defaults.
type Engine ¶
type Engine interface {
ContainerList(ctx context.Context, opts client.ContainerListOptions) (client.ContainerListResult, error)
ContainerInspect(ctx context.Context, id string, opts client.ContainerInspectOptions) (client.ContainerInspectResult, error)
ContainerRemove(ctx context.Context, id string, opts client.ContainerRemoveOptions) (client.ContainerRemoveResult, error)
VolumeList(ctx context.Context, opts client.VolumeListOptions) (client.VolumeListResult, error)
VolumeInspect(ctx context.Context, id string, opts client.VolumeInspectOptions) (client.VolumeInspectResult, error)
VolumeRemove(ctx context.Context, id string, opts client.VolumeRemoveOptions) (client.VolumeRemoveResult, error)
ImageList(ctx context.Context, opts client.ImageListOptions) (client.ImageListResult, error)
ImageInspect(ctx context.Context, id string, opts ...client.ImageInspectOption) (client.ImageInspectResult, error)
ImageRemove(ctx context.Context, id string, opts client.ImageRemoveOptions) (client.ImageRemoveResult, error)
DiskUsage(ctx context.Context, opts client.DiskUsageOptions) (client.DiskUsageResult, error)
ExecCreate(ctx context.Context, id string, opts client.ExecCreateOptions) (client.ExecCreateResult, error)
ExecAttach(ctx context.Context, id string, opts client.ExecAttachOptions) (client.ExecAttachResult, error)
ExecInspect(ctx context.Context, id string, opts client.ExecInspectOptions) (client.ExecInspectResult, error)
CopyFromContainer(ctx context.Context, id string, opts client.CopyFromContainerOptions) (client.CopyFromContainerResult, error)
}
Engine is the part of the Engine API that the uninstall uses. *client.Client satisfies it.
type KeySource ¶ added in v3.2.0
KeySource gives the key of an account. The key file of the CLI (keys.File) is one.
type Legacy ¶
type Legacy struct {
Engine Engine
Home string // the home folder; the 2.x folder is <Home>/.mai
AppFiles []string // configuration files of the apps; the uninstall only reads them
Yes bool
In io.Reader
Out io.Writer
}
Legacy removes a 2.x install. It never changes the files of the apps.
func (*Legacy) MakePlan ¶
func (l *Legacy) MakePlan(ctx context.Context) (*LegacyPlan, error)
MakePlan finds the 2.x items.
func (*Legacy) Remove ¶
func (l *Legacy) Remove(ctx context.Context, p *LegacyPlan) []Result
Remove removes the items of the plan and does a check of each one.
type LegacyPlan ¶
type LegacyPlan struct {
Container string // ID of the compose container; empty = none
Volumes []string
Images []string // references with a 2.x tag
Folder string // empty = none
Entries []string // 2.x MCP entries in files of the apps
}
LegacyPlan is the list of 2.x items.
func (*LegacyPlan) Empty ¶
func (p *LegacyPlan) Empty() bool
Empty tells if the plan has no item to remove.
type NotFoundError ¶
type NotFoundError struct{ What string }
NotFoundError is an engine error for a missing object. The fake engine of the tests uses it.
func (NotFoundError) Error ¶
func (e NotFoundError) Error() string
func (NotFoundError) NotFound ¶
func (NotFoundError) NotFound()
NotFound marks the error as a missing object.
type Plan ¶
type Plan struct {
Instance string
Containers []string
Volumes []string
Images []manifest.Item
AppEntries []manifest.Item
AppFiles []manifest.Item // files of apps that mai connect made
// KeptEntries and KeptFiles hold the app entries and the files of apps of the instance that
// stay, because a different instance has keys or records. An entry names no instance, thus
// it serves the instance of config.json at each start of its bridge. Their records get the
// instance EntryOwner, thus the uninstall of the last instance removes them.
KeptEntries []manifest.Item
KeptFiles []manifest.Item
EntryOwner string
Keys []string // accounts of the instance in the key file
Legacy []string // accounts of the instance with a legacy keychain item
LegacyErr error // the error of the examination of the legacy keychain
Paths []string
DataDirs []string // the data folders of the instance in Paths
// Unowned holds each data folder of a record of mai 3.0 or 3.1 whose instance is not
// known. It stays.
Unowned []string
Manifest *manifest.Manifest
Config Config
// Others holds each different instance with a key in the key file or a record in the
// manifest, sorted. MakePlan sets it, and Remove sets it again after the remove. While
// it is not empty, the files of the CLI that the other instances use stay.
Others []string
// contains filtered or unexported fields
}
Plan is the list of items that the uninstall removes.
type Uninstaller ¶
type Uninstaller struct {
Engine Engine
Keys *keys.File // the key file, with the legacy keychain; nil = no key is removed
Dirs paths.Dirs
Instance string // empty = the instance of config.json
Yes bool
Backup string // path of a backup archive; empty = no backup
In io.Reader
Out io.Writer
HTTP *http.Client
BaseURL string // base URL of the server; empty = the host port of the container of the instance
Binary *Binary // nil = keep the binary
}
Uninstaller removes one instance and the files of the CLI. The files of the CLI that the other instances of the same folders use stay: the key file, the manifest, the configuration file of a different instance, and the binary.
func (*Uninstaller) MakePlan ¶
func (u *Uninstaller) MakePlan() (*Plan, error)
MakePlan reads config.json and the manifest and gives the items to remove. The plan holds only the items of the instance. The records of a different instance stay out of the plan.
func (*Uninstaller) Remove ¶
func (u *Uninstaller) Remove(ctx context.Context, p *Plan) []Result
Remove removes each item of the plan, and does a check of each one after its remove.
func (*Uninstaller) Run ¶
func (u *Uninstaller) Run(ctx context.Context) int
Run does the complete uninstall and returns the exit code.