docker

package
v1.1.20210707 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 7, 2021 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Orchestrator = "orchestrator"
	Image        = "image"
	Container    = "container"
	Port         = "port"
	DockerType   = "docker_type"
)
View Source
const RemoteImage = "remote_image"

Variables

View Source
var ExtraCommands = []environments.Command{
	{
		Text:         "x-batch",
		Provider:     DockerType,
		Description:  "Batch management of containers and images",
		Environments: []environments.Environment{environments.Docker},
		MatchFn:      environments.StartWithMatch,
		Fn: func(args []string, writer io.Writer) {

			if len(args) < 2 || (args[1] != "container" && args[1] != "image") {
				_, _ = writer.Write([]byte("The container or image type should be provided in the parameter\n" +
					"Try \"x-batch container\" or \"x-batch image\" again\n"))
				return
			}

			resources := map[string]struct {
				fn  suggestions.Provider
				ops []string
			}{
				"container": {
					fn:  provideContainerSuggestion,
					ops: []string{"rm", "rm -f", "start", "stop", "restart", "pause", "unpause", "kill"},
				},
				"image": {
					fn:  provideImagesSuggestion,
					ops: []string{"rmi", "rmi -f", "create", "run"},
				},
			}

			resource := resources[args[1]]
			var opts []string
			col := int(util.GetWindowWidth() - 15)
			for _, v := range resource.fn() {
				opts = append(opts, v.Text+" | "+util.SubString(v.Description, 0, col-len(v.Text)))
			}
			var qs = []*survey.Question{
				{
					Name: "objective",
					Prompt: &survey.MultiSelect{
						Message:  "Which resource you want to operate ?",
						Options:  opts,
						PageSize: 25,
					},
					Validate: func(val interface{}) error {
						if ans, ok := val.([]survey.OptionAnswer); !ok || len(ans) == 0 {
							return errors.New("please select a least one resource")
						}
						return nil
					},
				},
				{
					Name: "operation",
					Prompt: &survey.Select{
						Message: "What you want to do with the these resources ?",
						Options: resource.ops,
					},
				},
				{
					Name: "confirm",
					Prompt: &survey.Confirm{
						Message: "Are you sure you want to continue ?",
					},
				},
			}
			answers := struct {
				Objective []string
				Operation string
				Confirm   bool
			}{}

			err := survey.Ask(qs, &answers, survey.WithKeepFilter(true))
			if err == terminal.InterruptErr {
				_, _ = writer.Write([]byte("operation interrupted\n"))
			} else if err != nil {
				_, _ = writer.Write([]byte(err.Error() + "\n"))
			}

			if answers.Confirm {
				for _, o := range answers.Objective {
					environments.Executor("docker", answers.Operation+" "+strings.TrimSpace(strings.Split(o, "|")[0]))
				}
			}
		},
	},
}

Functions

func New added in v1.1.20210626

func RegisterEnv

func RegisterEnv() (*environments.Runtime, error)

Types

type HubResult added in v1.1.20210626

type HubResult struct {
	PageCount        *int                    `json:"num_pages,omitempty"`
	ResultCount      *int                    `json:"num_results,omitempty"`
	ItemCountPerPage *int                    `json:"page_size,omitempty"`
	CurrentPage      *int                    `json:"page,omitempty"`
	Query            *string                 `json:"query,omitempty"`
	Items            []registry.SearchResult `json:"results,omitempty"`
}

HubResult : Wrap DockerHub API call

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL