├── .editorconfig ├── .github └── workflows │ ├── main.yml │ └── update.yml ├── .golangci.yml ├── .ops ├── .uuid ├── go.mod ├── go.sum ├── ops.go └── ops_test.go ├── LICENSE ├── README.md ├── builder.go ├── checkpoint.go ├── clerk.sum ├── config.go ├── container.go ├── context.go ├── ctrctl.go ├── go.mod ├── go.sum ├── image.go ├── internal └── generate.go ├── main.go ├── manifest.go ├── network.go ├── node.go ├── plugin.go ├── secret.go ├── service.go ├── stack.go ├── swarm.go ├── system.go ├── trust.go └── volume.go /.editorconfig: -------------------------------------------------------------------------------- 1 | [*.go] 2 | tab_width = 4 3 | max_line_length = 80 4 | -------------------------------------------------------------------------------- /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | name: main 2 | on: [push] 3 | jobs: 4 | op: 5 | runs-on: ubuntu-latest 6 | steps: 7 | - uses: actions/checkout@v4 8 | - uses: actions/setup-go@v5 9 | - run: '"$(wget -O- lesiw.io/op | sh)"' 10 | -------------------------------------------------------------------------------- /.github/workflows/update.yml: -------------------------------------------------------------------------------- 1 | name: update 2 | on: 3 | schedule: 4 | - cron: "21 * * * *" 5 | workflow_dispatch: 6 | permissions: 7 | contents: write 8 | jobs: 9 | op: 10 | runs-on: ubuntu-latest 11 | steps: 12 | - uses: actions/checkout@v4 13 | with: 14 | fetch-tags: true 15 | fetch-depth: 0 # https://github.com/actions/checkout/issues/1471 16 | - uses: actions/setup-go@v5 17 | - run: '"$(wget -O- lesiw.io/op | sh)" update' 18 | -------------------------------------------------------------------------------- /.golangci.yml: -------------------------------------------------------------------------------- 1 | version: "2" 2 | linters: 3 | enable: 4 | - errname 5 | - gocheckcompilerdirectives 6 | - gocyclo 7 | - godot 8 | - lll 9 | - makezero 10 | - unparam 11 | settings: 12 | gocyclo: 13 | min-complexity: 15 14 | lll: 15 | line-length: 79 16 | tab-width: 4 17 | exclusions: 18 | generated: lax 19 | presets: 20 | - comments 21 | - common-false-positives 22 | - legacy 23 | - std-error-handling 24 | rules: 25 | - linters: 26 | - errcheck 27 | source: 'defer ' 28 | paths: 29 | - third_party$ 30 | - builtin$ 31 | - examples$ 32 | formatters: 33 | exclusions: 34 | generated: lax 35 | paths: 36 | - third_party$ 37 | - builtin$ 38 | - examples$ 39 | -------------------------------------------------------------------------------- /.ops/.uuid: -------------------------------------------------------------------------------- 1 | e54bf79f-7a93-44a5-b8b9-641492229bb6 2 | -------------------------------------------------------------------------------- /.ops/go.mod: -------------------------------------------------------------------------------- 1 | module ops.localhost 2 | 3 | go 1.23.2 4 | 5 | require ( 6 | github.com/google/go-cmp v0.7.0 7 | labs.lesiw.io/ops v0.0.0-20250529163852-5d4aa59d2214 8 | lesiw.io/cmdio v0.10.0 9 | lesiw.io/ops v0.14.0 10 | ) 11 | 12 | require ( 13 | golang.org/x/crypto v0.38.0 // indirect 14 | golang.org/x/sync v0.14.0 // indirect 15 | lesiw.io/clerk v0.2.0 // indirect 16 | lesiw.io/cmdio/x/busybox v0.1.0 // indirect 17 | lesiw.io/defers v0.9.0 // indirect 18 | lesiw.io/flag v0.7.0 // indirect 19 | lesiw.io/prefix v0.1.0 // indirect 20 | ) 21 | -------------------------------------------------------------------------------- /.ops/go.sum: -------------------------------------------------------------------------------- 1 | github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= 2 | github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= 3 | github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU= 4 | golang.org/x/crypto v0.38.0 h1:jt+WWG8IZlBnVbomuhg2Mdq0+BBQaHbtqHEFEigjUV8= 5 | golang.org/x/crypto v0.38.0/go.mod h1:MvrbAqul58NNYPKnOra203SB9vpuZW0e+RRZV+Ggqjw= 6 | golang.org/x/sync v0.14.0 h1:woo0S4Yywslg6hp4eUFjTVOyKt0RookbpAHG4c1HmhQ= 7 | golang.org/x/sync v0.14.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA= 8 | golang.org/x/sys v0.33.0 h1:q3i8TbbEz+JRD9ywIRlyRAQbM0qF7hu24q3teo2hbuw= 9 | golang.org/x/sys v0.33.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k= 10 | golang.org/x/term v0.32.0 h1:DR4lr0TjUs3epypdhTOkMmuF5CDFJ/8pOnbzMZPQ7bg= 11 | golang.org/x/term v0.32.0/go.mod h1:uZG1FhGx848Sqfsq4/DlJr3xGGsYMu/L5GW4abiaEPQ= 12 | gotest.tools/v3 v3.5.1 h1:EENdUnS3pdur5nybKYIh2Vfgc8IUNBjxDPSjtiJcOzU= 13 | gotest.tools/v3 v3.5.1/go.mod h1:isy3WKz7GK6uNw/sbHzfKBLvlvXwUyV06n6brMxxopU= 14 | labs.lesiw.io/ops v0.0.0-20250529163852-5d4aa59d2214 h1:imTwSkNhtMM9+1BZU4KN8F6YebyPvjas4bHP7Ty9S/I= 15 | labs.lesiw.io/ops v0.0.0-20250529163852-5d4aa59d2214/go.mod h1:C9Jk4AQOr5M0NGk2oTkNJwGdX7mISjG+tebn0n3SyII= 16 | lesiw.io/clerk v0.2.0 h1:Rcq19dHx9TRk4Rkpm9Sw/KGySUxrNmPhrcmU2EQhBYo= 17 | lesiw.io/clerk v0.2.0/go.mod h1:WMyvgTe+3Eob36b6KX86MOaxaeNMvv/HZTSsf2Dedhg= 18 | lesiw.io/cmdio v0.10.0 h1:YSc8+vdbpBTm9Pz2Tj2QneAEFoxvvAtJkc9S0UgCmEc= 19 | lesiw.io/cmdio v0.10.0/go.mod h1:RRxYqFsLgx3JpElt244AGmRdeFGnc/6fbh3fFgcNvnk= 20 | lesiw.io/cmdio/x/busybox v0.1.0 h1:e1G1JJttIcwpGuUki7oLQTx7Ve6BWExe2Cs4aw0kExM= 21 | lesiw.io/cmdio/x/busybox v0.1.0/go.mod h1:PkwZVzE2tTrNI4BNOgiz595SwwF8BAbvI9LSz1P5GJY= 22 | lesiw.io/defers v0.9.0 h1:Sg7RYbhxfHhXMHclO65MJ4oRbyhfSBSeHQw4YjLr6n0= 23 | lesiw.io/defers v0.9.0/go.mod h1:AP09yGFHxL5vmTVJxkPL33N1hWI4OzHwTEOzilbDZU4= 24 | lesiw.io/flag v0.7.0 h1:+8rTdoplDMBhOSKok5eKP6ZuLLPTodkDABRY7jfX5JU= 25 | lesiw.io/flag v0.7.0/go.mod h1:bJx6Hir8MAXkNiO6BbrvhwZuaJF4rQWthQ7pc1DlWZY= 26 | lesiw.io/ops v0.14.0 h1:WTdNxlqL2HjDgpDd5VqoaQwKOqvu1CeR1Wi1wk6wJ0E= 27 | lesiw.io/ops v0.14.0/go.mod h1:onq4+252Tz6+DzGMtUiibOm7+KJW+ty8v5OBJ91Yb7M= 28 | lesiw.io/prefix v0.1.0 h1:2Ors12avAiADgMbsQHh27wQmoSI+4aZSW2uTBdDmIZg= 29 | lesiw.io/prefix v0.1.0/go.mod h1:yrUaJpvikavNodwcL64crLnSf3t1NWeNi/vNu5hUi2Y= 30 | -------------------------------------------------------------------------------- /.ops/ops.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "bufio" 5 | "os" 6 | "strings" 7 | 8 | "labs.lesiw.io/ops/golib" 9 | "lesiw.io/cmdio/sys" 10 | "lesiw.io/ops" 11 | ) 12 | 13 | type Ops struct{ golib.Ops } 14 | 15 | var Runner = sys.Runner() 16 | 17 | func main() { 18 | if len(os.Args) < 2 { 19 | os.Args = append(os.Args, "check") 20 | } 21 | ops.Handle(Ops{}) 22 | } 23 | 24 | func (op Ops) Update() { 25 | if _, err := Runner.Get("which", "goimports"); err != nil { 26 | Runner.MustRun("go", "install", 27 | "golang.org/x/tools/cmd/goimports@latest") 28 | } 29 | Runner.MustRun("go", "generate", "./...") 30 | if Runner.MustGet("git", "status", "-s").Out == "" { 31 | return // Nothing changed. 32 | } 33 | if gitconfig("user.name") == "" { 34 | Runner.MustRun("git", "config", "--global", "user.name", "llbot") 35 | Runner.MustRun("git", "config", "--global", "user.email", 36 | "llbot@noreply.lesiwlabs.com") 37 | } 38 | Runner.MustRun("git", "commit", "-am", "Automated update") 39 | Runner.MustRun("op") // Validate changes. 40 | op.Bump() 41 | Runner.MustRun("git", "push") 42 | } 43 | 44 | func gitconfig(key string) string { 45 | cmd := Runner.Command("git", "config", "-l") 46 | scanner := bufio.NewScanner(cmd) 47 | for scanner.Scan() { 48 | k, v, ok := strings.Cut(scanner.Text(), "=") 49 | if ok && k == key { 50 | return v 51 | } 52 | } 53 | if err := scanner.Err(); err != nil { 54 | panic(err) 55 | } 56 | return "" 57 | } 58 | -------------------------------------------------------------------------------- /.ops/ops_test.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "bytes" 5 | "context" 6 | "fmt" 7 | "io" 8 | "slices" 9 | "testing" 10 | 11 | "github.com/google/go-cmp/cmp" 12 | "labs.lesiw.io/ops/git" 13 | "labs.lesiw.io/ops/golang" 14 | "lesiw.io/cmdio" 15 | ) 16 | 17 | var uniq = make(map[string]int) 18 | 19 | var bump func() 20 | 21 | func (Ops) Bump() { bump() } 22 | 23 | type testCdr struct { 24 | cmd [][]string 25 | gitChanged bool 26 | gitConfig string 27 | } 28 | 29 | func (c *testCdr) Command( 30 | _ context.Context, env map[string]string, args ...string, 31 | ) io.ReadWriter { 32 | c.cmd = append(c.cmd, args) 33 | s := fmt.Sprintf("%v", args) 34 | uniq[s]++ 35 | if uniq[s] > 1 { 36 | s = fmt.Sprintf("%s[%d]", s, uniq[s]) 37 | } 38 | if !c.gitChanged && slices.Equal(args, []string{"git", "status", "-s"}) { 39 | return bytes.NewBufferString("") 40 | } else if slices.Equal(args, []string{"git", "config", "-l"}) { 41 | return bytes.NewBufferString(c.gitConfig) 42 | } else { 43 | return bytes.NewBufferString(s + "\n") 44 | } 45 | } 46 | 47 | func TestUpdate(t *testing.T) { 48 | t.Cleanup(func() { clear(uniq) }) 49 | cdr := new(testCdr) 50 | cdr.gitChanged = true 51 | Runner = cmdio.NewRunner(context.Background(), nil, cdr) 52 | golang.Runner = func() *cmdio.Runner { return Runner } 53 | git.Runner = Runner 54 | 55 | bump = func() { Runner.MustRun("bump") } 56 | Ops{}.Update() 57 | 58 | expected := [][]string{ 59 | {"which", "goimports"}, 60 | {"go", "generate", "./..."}, 61 | {"git", "status", "-s"}, 62 | {"git", "config", "-l"}, 63 | {"git", "config", "--global", "user.name", "llbot"}, 64 | {"git", "config", "--global", "user.email", 65 | "llbot@noreply.lesiwlabs.com"}, 66 | {"git", "commit", "-am", "Automated update"}, 67 | {"op"}, 68 | {"bump"}, 69 | {"git", "push"}, 70 | } 71 | if got, want := cdr.cmd, expected; !cmp.Equal(got, want) { 72 | t.Errorf("commands -want +got:\n%s", cmp.Diff(got, want)) 73 | } 74 | } 75 | 76 | func TestNoChange(t *testing.T) { 77 | t.Cleanup(func() { clear(uniq) }) 78 | cdr := new(testCdr) 79 | Runner = cmdio.NewRunner(context.Background(), nil, cdr) 80 | golang.Runner = func() *cmdio.Runner { return Runner } 81 | git.Runner = Runner 82 | 83 | bump = func() { Runner.MustRun("bump") } 84 | Ops{}.Update() 85 | 86 | expected := [][]string{ 87 | {"which", "goimports"}, 88 | {"go", "generate", "./..."}, 89 | {"git", "status", "-s"}, 90 | } 91 | if got, want := cdr.cmd, expected; !cmp.Equal(got, want) { 92 | t.Errorf("commands -want +got:\n%s", cmp.Diff(got, want)) 93 | } 94 | } 95 | 96 | func TestGitUserExists(t *testing.T) { 97 | t.Cleanup(func() { clear(uniq) }) 98 | cdr := new(testCdr) 99 | cdr.gitChanged = true 100 | cdr.gitConfig = "user.name=example" 101 | Runner = cmdio.NewRunner(context.Background(), nil, cdr) 102 | golang.Runner = func() *cmdio.Runner { return Runner } 103 | git.Runner = Runner 104 | 105 | bump = func() { Runner.MustRun("bump") } 106 | Ops{}.Update() 107 | 108 | expected := [][]string{ 109 | {"which", "goimports"}, 110 | {"go", "generate", "./..."}, 111 | {"git", "status", "-s"}, 112 | {"git", "config", "-l"}, 113 | {"git", "commit", "-am", "Automated update"}, 114 | {"op"}, 115 | {"bump"}, 116 | {"git", "push"}, 117 | } 118 | if got, want := cdr.cmd, expected; !cmp.Equal(got, want) { 119 | t.Errorf("commands -want +got:\n%s", cmp.Diff(got, want)) 120 | } 121 | } 122 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2023 Chris Lesiw 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining 6 | a copy of this software and associated documentation files (the 7 | "Software"), to deal in the Software without restriction, including 8 | without limitation the rights to use, copy, modify, merge, publish, 9 | distribute, sublicense, and/or sell copies of the Software, and to 10 | permit persons to whom the Software is furnished to do so, subject to 11 | the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 20 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 21 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 22 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ctrctl 2 | 3 | [![Go Reference](https://pkg.go.dev/badge/lesiw.io/ctrctl.svg)](https://pkg.go.dev/lesiw.io/ctrctl) 4 | 5 | Package `ctrctl` wraps container CLIs. 6 | 7 | ## Example 8 | 9 | ```go 10 | package main 11 | 12 | import "lesiw.io/ctrctl" 13 | 14 | func main() { 15 | ctrctl.Cli = []string{"docker"} // or {"podman"}, or {"lima", "nerdctl"}... 16 | 17 | id, err := ctrctl.ContainerRun( 18 | &ctrctl.ContainerRunOpts{ 19 | Detach: true, 20 | Tty: true, 21 | }, 22 | "alpine", 23 | "cat", 24 | ) 25 | if err != nil { 26 | panic(err) 27 | } 28 | 29 | out, err := ctrctl.ContainerExec(nil, id, "echo", "Hello from alpine!") 30 | if err != nil { 31 | panic(err) 32 | } 33 | fmt.Println(out) 34 | 35 | _, err = ctrctl.ContainerRm(&ctrctl.ContainerRmOpts{Force: true}, id) 36 | if err != nil { 37 | panic(err) 38 | } 39 | } 40 | ``` 41 | 42 | ## Motivation 43 | 44 | Most container engines ship alongside a CLI that provides an experience similar 45 | to that of Docker on Linux. In the pursuit of this goal, they often hide several 46 | layers of indirection through internal APIs and VM boundaries while maintaining 47 | argument-for-argument compatibility with the [Docker 48 | CLI](https://docs.docker.com/engine/reference/commandline/cli/). 49 | 50 | Since the CLI is the primary interface that users and automation scripts 51 | interact with, it’s also the most likely interface where bugs will be noticed 52 | and, hopefully, fixed. Conversely, the primary consumer of engines’ internal 53 | APIs are their own command lines and a handful of plugins, so issues and 54 | documentation gaps in the API layer are less likely to be noticed and 55 | prioritized. 56 | 57 | For these reasons, Docker-compatible CLIs serve as excellent abstraction points 58 | for projects that manage containers. `docker`, `nerdctl`, `podman`, and even 59 | `kubectl` have more in common with one another than any of their internal APIs 60 | or SDKs do. However, working with `exec.Command` is verbose and lacks in-editor 61 | completion for container commands. 62 | 63 | `ctrctl` fills this gap by providing CLI wrapper functions and option structs 64 | automatically generated from the 65 | [Dockermentation](https://github.com/docker/docs). While no container engine 66 | implements Docker’s entire interface, generating `ctrctl` wrappers from Docker 67 | ensures that all potential shared functionality will be covered. 68 | 69 | To switch between `docker` and other Docker-compatible CLIs, just set 70 | `ctrctl.Cli` to the appropriate value. 71 | 72 | ## Simple usage 73 | 74 | All wrapper functions take an optional struct as the first argument. The format 75 | of the option struct is always `CommandOpts`, where `Command` is the name of the 76 | function being called. 77 | 78 | Commands return a `string` containing stdout and an optional `error`. `error` 79 | may be of type `ctrctl.CliError`, which contains a `Stderr` field for debugging 80 | purposes. 81 | 82 | Set `ctrctl.Verbose = true` to stream the exact commands being run, along with 83 | their output, to standard out. The format is similar to using `set +x` in a 84 | shell script. 85 | 86 | ## Advanced usage 87 | 88 | All wrapper functions’ options structs have a `Cmd` field. Set this to an 89 | `&exec.Cmd` to override the default command behavior. 90 | 91 | Note that setting `Cmd.Stdout` or `Cmd.Stderr` to an `io.Writer` will disable 92 | automatic capture of those outputs. Bypassing capture allows the underlying 93 | container CLI to work in interactive mode when they are attached to `os.Stdout` 94 | and `os.Stderr`, respectively. 95 | 96 | In this example, standard streams are overridden to expose the output of the 97 | `ImagePull` to the end user, then drop them into an interactive shell in an 98 | `alpine` container. Once they exit the shell, the container is removed. 99 | 100 | ```go 101 | package main 102 | 103 | import ( 104 | "os" 105 | "os/exec" 106 | 107 | "lesiw.io/ctrctl" 108 | ) 109 | 110 | func main() { 111 | _, err := ctrctl.ImagePull( 112 | &ctrctl.ImagePullOpts{ 113 | Cmd: &exec.Cmd{ 114 | Stdout: os.Stdout, 115 | Stderr: os.Stderr, 116 | }, 117 | }, 118 | "alpine:latest", 119 | ) 120 | if err != nil { 121 | panic(err) 122 | } 123 | 124 | id, err := ctrctl.ContainerRun( 125 | &ctrctl.ContainerRunOpts{ 126 | Detach: true, 127 | Tty: true, 128 | }, 129 | "alpine", 130 | "cat", 131 | ) 132 | if err != nil { 133 | panic(err) 134 | } 135 | 136 | _, _ = ctrctl.ContainerExec( 137 | &ctrctl.ContainerExecOpts{ 138 | Cmd: &exec.Cmd{ 139 | Stdin: os.Stdin, 140 | Stdout: os.Stdout, 141 | Stderr: os.Stderr, 142 | }, 143 | Interactive: true, 144 | Tty: true, 145 | }, 146 | id, 147 | "/bin/sh", 148 | ) 149 | 150 | _, err = ctrctl.ContainerRm(&ctrctl.ContainerRmOpts{Force: true}, id) 151 | if err != nil { 152 | panic(err) 153 | } 154 | } 155 | ``` 156 | 157 | ## Regenerating the interface 158 | 159 | Install [`gofmt`](https://pkg.go.dev/cmd/gofmt) and 160 | [`goimports`](https://pkg.go.dev/golang.org/x/tools/cmd/goimports), then run `go 161 | generate ./...` 162 | -------------------------------------------------------------------------------- /builder.go: -------------------------------------------------------------------------------- 1 | // Code generated by lesiw.io/ctrctl. DO NOT EDIT. 2 | package ctrctl 3 | 4 | import "os/exec" 5 | 6 | type BuilderBuildOpts struct { 7 | // Base exec.Cmd. 8 | Cmd *exec.Cmd 9 | 10 | // Add a custom host-to-IP mapping (`host:ip`). 11 | AddHost []string 12 | 13 | // Set build-time variables. 14 | BuildArg []string 15 | 16 | // Images to consider as cache sources. 17 | CacheFrom string 18 | 19 | // Set the parent cgroup for the `RUN` instructions during build. 20 | CgroupParent string 21 | 22 | // Compress the build context using gzip. 23 | Compress bool 24 | 25 | // Limit the CPU CFS (Completely Fair Scheduler) period. 26 | CpuPeriod string 27 | 28 | // Limit the CPU CFS (Completely Fair Scheduler) quota. 29 | CpuQuota string 30 | 31 | // CPU shares (relative weight). 32 | CpuShares string 33 | 34 | // CPUs in which to allow execution (0-3, 0,1). 35 | CpusetCpus string 36 | 37 | // MEMs in which to allow execution (0-3, 0,1). 38 | CpusetMems string 39 | 40 | // Skip image verification. 41 | DisableContentTrust bool 42 | 43 | // Name of the Dockerfile (Default is `PATH/Dockerfile`). 44 | File string 45 | 46 | // Always remove intermediate containers. 47 | ForceRm bool 48 | 49 | // Print usage. 50 | Help bool 51 | 52 | // Write the image ID to the file. 53 | Iidfile string 54 | 55 | // Container isolation technology. 56 | Isolation string 57 | 58 | // Set metadata for an image. 59 | Label []string 60 | 61 | // Memory limit. 62 | Memory string 63 | 64 | // Swap limit equal to memory plus swap: -1 to enable unlimited swap. 65 | MemorySwap string 66 | 67 | // Set the networking mode for the RUN instructions during build. 68 | Network string 69 | 70 | // Do not use cache when building the image. 71 | NoCache bool 72 | 73 | // Set platform if server is multi-platform capable. 74 | Platform string 75 | 76 | // Always attempt to pull a newer version of the image. 77 | Pull bool 78 | 79 | // Suppress the build output and print image ID on success. 80 | Quiet bool 81 | 82 | // Remove intermediate containers after a successful build. 83 | Rm bool 84 | 85 | // Security options. 86 | SecurityOpt string 87 | 88 | // Size of `/dev/shm`. 89 | ShmSize string 90 | 91 | // Squash newly built layers into a single new layer. 92 | Squash bool 93 | 94 | // Name and optionally a tag in the `name:tag` format. 95 | Tag []string 96 | 97 | // Set the target build stage to build. 98 | Target string 99 | 100 | // Ulimit options. 101 | Ulimit string 102 | } 103 | 104 | // Build an image from a Dockerfile. 105 | func BuilderBuild(opts *BuilderBuildOpts, pathUrl string) (string, error) { 106 | if err := findCli(); err != nil { 107 | return "", err 108 | } 109 | return runCtrCmd( 110 | []string{"builder", "build"}, 111 | []string{pathUrl}, 112 | opts, 113 | 0, 114 | ) 115 | } 116 | 117 | type BuilderPruneOpts struct { 118 | // Base exec.Cmd. 119 | Cmd *exec.Cmd 120 | 121 | // Remove all unused build cache, not just dangling ones. 122 | All bool 123 | 124 | // Provide filter values (e.g. `until=24h`). 125 | Filter string 126 | 127 | // Do not prompt for confirmation. 128 | Force bool 129 | 130 | // Print usage. 131 | Help bool 132 | 133 | // Amount of disk space to keep for cache. 134 | KeepStorage string 135 | } 136 | 137 | // Remove build cache. 138 | func BuilderPrune(opts *BuilderPruneOpts) (string, error) { 139 | if err := findCli(); err != nil { 140 | return "", err 141 | } 142 | return runCtrCmd( 143 | []string{"builder", "prune"}, 144 | []string{}, 145 | opts, 146 | -1, 147 | ) 148 | } 149 | -------------------------------------------------------------------------------- /checkpoint.go: -------------------------------------------------------------------------------- 1 | // Code generated by lesiw.io/ctrctl. DO NOT EDIT. 2 | package ctrctl 3 | 4 | import "os/exec" 5 | 6 | type CheckpointCreateOpts struct { 7 | // Base exec.Cmd. 8 | Cmd *exec.Cmd 9 | 10 | // Use a custom checkpoint storage directory. 11 | CheckpointDir string 12 | 13 | // Print usage. 14 | Help bool 15 | 16 | // Leave the container running after checkpoint. 17 | LeaveRunning bool 18 | } 19 | 20 | // Create a checkpoint from a running container. 21 | func CheckpointCreate(opts *CheckpointCreateOpts, container string, checkpoint string) (string, error) { 22 | if err := findCli(); err != nil { 23 | return "", err 24 | } 25 | return runCtrCmd( 26 | []string{"checkpoint", "create"}, 27 | []string{container, checkpoint}, 28 | opts, 29 | 0, 30 | ) 31 | } 32 | 33 | type CheckpointLsOpts struct { 34 | // Base exec.Cmd. 35 | Cmd *exec.Cmd 36 | 37 | // Use a custom checkpoint storage directory. 38 | CheckpointDir string 39 | 40 | // Print usage. 41 | Help bool 42 | } 43 | 44 | // List checkpoints for a container. 45 | func CheckpointLs(opts *CheckpointLsOpts, container string) (string, error) { 46 | if err := findCli(); err != nil { 47 | return "", err 48 | } 49 | return runCtrCmd( 50 | []string{"checkpoint", "ls"}, 51 | []string{container}, 52 | opts, 53 | 0, 54 | ) 55 | } 56 | 57 | type CheckpointRmOpts struct { 58 | // Base exec.Cmd. 59 | Cmd *exec.Cmd 60 | 61 | // Use a custom checkpoint storage directory. 62 | CheckpointDir string 63 | 64 | // Print usage. 65 | Help bool 66 | } 67 | 68 | // Remove a checkpoint. 69 | func CheckpointRm(opts *CheckpointRmOpts, container string, checkpoint string) (string, error) { 70 | if err := findCli(); err != nil { 71 | return "", err 72 | } 73 | return runCtrCmd( 74 | []string{"checkpoint", "rm"}, 75 | []string{container, checkpoint}, 76 | opts, 77 | 0, 78 | ) 79 | } 80 | -------------------------------------------------------------------------------- /clerk.sum: -------------------------------------------------------------------------------- 1 | .editorconfig 3632ddbf531e998e5990a3d4e88b547fea86dd00 2 | .github/workflows/main.yml 62efcdd9a8f00f489693e4f0f916429822dc311f 3 | .golangci.yml 0482b9ce2134a6ed15a7b94f54d111e65b89b0fd 4 | -------------------------------------------------------------------------------- /config.go: -------------------------------------------------------------------------------- 1 | // Code generated by lesiw.io/ctrctl. DO NOT EDIT. 2 | package ctrctl 3 | 4 | import ( 5 | "fmt" 6 | "os/exec" 7 | ) 8 | 9 | type ConfigCreateOpts struct { 10 | // Base exec.Cmd. 11 | Cmd *exec.Cmd 12 | 13 | // Print usage. 14 | Help bool 15 | 16 | // Config labels. 17 | Label []string 18 | 19 | // Template driver. 20 | TemplateDriver string 21 | } 22 | 23 | // Create a config from a file or STDIN. 24 | func ConfigCreate(opts *ConfigCreateOpts, config string, file string) (string, error) { 25 | if err := findCli(); err != nil { 26 | return "", err 27 | } 28 | return runCtrCmd( 29 | []string{"config", "create"}, 30 | []string{config, file}, 31 | opts, 32 | 0, 33 | ) 34 | } 35 | 36 | type ConfigInspectOpts struct { 37 | // Base exec.Cmd. 38 | Cmd *exec.Cmd 39 | 40 | // Format output using a custom template: 41 | // 'json': Print in JSON format. 42 | // 'TEMPLATE': Print output using the given Go template. 43 | // Refer to https://docs.docker.com/go/formatting/ for more information about formatting output with templates. 44 | Format string 45 | 46 | // Print usage. 47 | Help bool 48 | 49 | // Print the information in a human friendly format. 50 | Pretty bool 51 | } 52 | 53 | // Display detailed information on one or more configs. 54 | func ConfigInspect(opts *ConfigInspectOpts, config ...string) (string, error) { 55 | if err := findCli(); err != nil { 56 | return "", err 57 | } 58 | if len(config) == 0 { 59 | return "", fmt.Errorf("config must have at least one value") 60 | } 61 | return runCtrCmd( 62 | []string{"config", "inspect"}, 63 | config, 64 | opts, 65 | 0, 66 | ) 67 | } 68 | 69 | type ConfigLsOpts struct { 70 | // Base exec.Cmd. 71 | Cmd *exec.Cmd 72 | 73 | // Filter output based on conditions provided. 74 | Filter string 75 | 76 | // Format output using a custom template: 77 | // 'table': Print output in table format with column headers (default). 78 | // 'table TEMPLATE': Print output in table format using the given Go template. 79 | // 'json': Print in JSON format. 80 | // 'TEMPLATE': Print output using the given Go template. 81 | // Refer to https://docs.docker.com/go/formatting/ for more information about formatting output with templates. 82 | Format string 83 | 84 | // Print usage. 85 | Help bool 86 | 87 | // Only display IDs. 88 | Quiet bool 89 | } 90 | 91 | // List configs. 92 | func ConfigLs(opts *ConfigLsOpts) (string, error) { 93 | if err := findCli(); err != nil { 94 | return "", err 95 | } 96 | return runCtrCmd( 97 | []string{"config", "ls"}, 98 | []string{}, 99 | opts, 100 | 0, 101 | ) 102 | } 103 | 104 | type ConfigRmOpts struct { 105 | // Base exec.Cmd. 106 | Cmd *exec.Cmd 107 | 108 | // Print usage. 109 | Help bool 110 | } 111 | 112 | // Remove one or more configs. 113 | func ConfigRm(opts *ConfigRmOpts, config ...string) (string, error) { 114 | if err := findCli(); err != nil { 115 | return "", err 116 | } 117 | if len(config) == 0 { 118 | return "", fmt.Errorf("config must have at least one value") 119 | } 120 | return runCtrCmd( 121 | []string{"config", "rm"}, 122 | config, 123 | opts, 124 | -1, 125 | ) 126 | } 127 | -------------------------------------------------------------------------------- /container.go: -------------------------------------------------------------------------------- 1 | // Code generated by lesiw.io/ctrctl. DO NOT EDIT. 2 | package ctrctl 3 | 4 | import ( 5 | "fmt" 6 | "os/exec" 7 | ) 8 | 9 | type ContainerAttachOpts struct { 10 | // Base exec.Cmd. 11 | Cmd *exec.Cmd 12 | 13 | // Override the key sequence for detaching a container. 14 | DetachKeys string 15 | 16 | // Print usage. 17 | Help bool 18 | 19 | // Do not attach STDIN. 20 | NoStdin bool 21 | 22 | // Proxy all received signals to the process. 23 | SigProxy bool 24 | } 25 | 26 | // Attach local standard input, output, and error streams to a running container. 27 | func ContainerAttach(opts *ContainerAttachOpts, container string) (string, error) { 28 | if err := findCli(); err != nil { 29 | return "", err 30 | } 31 | return runCtrCmd( 32 | []string{"container", "attach"}, 33 | []string{container}, 34 | opts, 35 | 0, 36 | ) 37 | } 38 | 39 | type ContainerCommitOpts struct { 40 | // Base exec.Cmd. 41 | Cmd *exec.Cmd 42 | 43 | // Author (e.g., `John Hannibal Smith `). 44 | Author string 45 | 46 | // Apply Dockerfile instruction to the created image. 47 | Change []string 48 | 49 | // Print usage. 50 | Help bool 51 | 52 | // Commit message. 53 | Message string 54 | 55 | // Pause container during commit. 56 | Pause bool 57 | } 58 | 59 | // Create a new image from a container's changes. 60 | func ContainerCommit(opts *ContainerCommitOpts, container string, repositoryTag string) (string, error) { 61 | if err := findCli(); err != nil { 62 | return "", err 63 | } 64 | return runCtrCmd( 65 | []string{"container", "commit"}, 66 | []string{container, repositoryTag}, 67 | opts, 68 | 0, 69 | ) 70 | } 71 | 72 | type ContainerCpOpts struct { 73 | // Base exec.Cmd. 74 | Cmd *exec.Cmd 75 | 76 | // Archive mode (copy all uid/gid information). 77 | Archive bool 78 | 79 | // Always follow symbol link in SRC_PATH. 80 | FollowLink bool 81 | 82 | // Print usage. 83 | Help bool 84 | 85 | // Suppress progress output during copy. Progress output is automatically suppressed if no terminal is attached. 86 | Quiet bool 87 | } 88 | 89 | // Copy files/folders between a container and the local filesystem. 90 | func ContainerCp(opts *ContainerCpOpts, srcpath string, dstpath string) (string, error) { 91 | if err := findCli(); err != nil { 92 | return "", err 93 | } 94 | return runCtrCmd( 95 | []string{"container", "cp"}, 96 | []string{srcpath, dstpath}, 97 | opts, 98 | -1, 99 | ) 100 | } 101 | 102 | type ContainerCreateOpts struct { 103 | // Base exec.Cmd. 104 | Cmd *exec.Cmd 105 | 106 | // Add a custom host-to-IP mapping (host:ip). 107 | AddHost []string 108 | 109 | // Add an annotation to the container (passed through to the OCI runtime). 110 | Annotation string 111 | 112 | // Attach to STDIN, STDOUT or STDERR. 113 | Attach []string 114 | 115 | // Block IO (relative weight), between 10 and 1000, or 0 to disable (default 0). 116 | BlkioWeight string 117 | 118 | // Block IO weight (relative device weight). 119 | BlkioWeightDevice []string 120 | 121 | // Add Linux capabilities. 122 | CapAdd []string 123 | 124 | // Drop Linux capabilities. 125 | CapDrop []string 126 | 127 | // Optional parent cgroup for the container. 128 | CgroupParent string 129 | 130 | // Cgroup namespace to use (host|private). 131 | // 'host': Run the container in the Docker host's cgroup namespace. 132 | // 'private': Run the container in its own private cgroup namespace. 133 | // '': Use the cgroup namespace as configured by the. 134 | // default-cgroupns-mode option on the daemon (default). 135 | Cgroupns string 136 | 137 | // Write the container ID to the file. 138 | Cidfile string 139 | 140 | // CPU count (Windows only). 141 | CpuCount string 142 | 143 | // CPU percent (Windows only). 144 | CpuPercent string 145 | 146 | // Limit CPU CFS (Completely Fair Scheduler) period. 147 | CpuPeriod string 148 | 149 | // Limit CPU CFS (Completely Fair Scheduler) quota. 150 | CpuQuota string 151 | 152 | // Limit CPU real-time period in microseconds. 153 | CpuRtPeriod string 154 | 155 | // Limit CPU real-time runtime in microseconds. 156 | CpuRtRuntime string 157 | 158 | // CPU shares (relative weight). 159 | CpuShares string 160 | 161 | // Number of CPUs. 162 | Cpus string 163 | 164 | // CPUs in which to allow execution (0-3, 0,1). 165 | CpusetCpus string 166 | 167 | // MEMs in which to allow execution (0-3, 0,1). 168 | CpusetMems string 169 | 170 | // Add a host device to the container. 171 | Device []string 172 | 173 | // Add a rule to the cgroup allowed devices list. 174 | DeviceCgroupRule []string 175 | 176 | // Limit read rate (bytes per second) from a device. 177 | DeviceReadBps []string 178 | 179 | // Limit read rate (IO per second) from a device. 180 | DeviceReadIops []string 181 | 182 | // Limit write rate (bytes per second) to a device. 183 | DeviceWriteBps []string 184 | 185 | // Limit write rate (IO per second) to a device. 186 | DeviceWriteIops []string 187 | 188 | // Skip image verification. 189 | DisableContentTrust bool 190 | 191 | // Set custom DNS servers. 192 | Dns []string 193 | 194 | // Set DNS options. 195 | DnsOpt []string 196 | 197 | // Set DNS options. 198 | DnsOption []string 199 | 200 | // Set custom DNS search domains. 201 | DnsSearch []string 202 | 203 | // Container NIS domain name. 204 | Domainname string 205 | 206 | // Overwrite the default ENTRYPOINT of the image. 207 | Entrypoint string 208 | 209 | // Set environment variables. 210 | Env []string 211 | 212 | // Read in a file of environment variables. 213 | EnvFile []string 214 | 215 | // Expose a port or a range of ports. 216 | Expose []string 217 | 218 | // GPU devices to add to the container ('all' to pass all GPUs). 219 | Gpus string 220 | 221 | // Add additional groups to join. 222 | GroupAdd []string 223 | 224 | // Command to run to check health. 225 | HealthCmd string 226 | 227 | // Time between running the check (ms|s|m|h) (default 0s). 228 | HealthInterval string 229 | 230 | // Consecutive failures needed to report unhealthy. 231 | HealthRetries *int 232 | 233 | // Time between running the check during the start period (ms|s|m|h) (default 0s). 234 | HealthStartInterval string 235 | 236 | // Start period for the container to initialize before starting health-retries countdown (ms|s|m|h) (default 0s). 237 | HealthStartPeriod string 238 | 239 | // Maximum time to allow one check to run (ms|s|m|h) (default 0s). 240 | HealthTimeout string 241 | 242 | // Print usage. 243 | Help bool 244 | 245 | // Container host name. 246 | Hostname string 247 | 248 | // Run an init inside the container that forwards signals and reaps processes. 249 | Init bool 250 | 251 | // Keep STDIN open even if not attached. 252 | Interactive bool 253 | 254 | // Maximum IO bandwidth limit for the system drive (Windows only). 255 | IoMaxbandwidth string 256 | 257 | // Maximum IOps limit for the system drive (Windows only). 258 | IoMaxiops string 259 | 260 | // IPv4 address (e.g., 172.30.100.104). 261 | Ip string 262 | 263 | // IPv6 address (e.g., 2001:db8::33). 264 | Ip6 string 265 | 266 | // IPC mode to use. 267 | Ipc string 268 | 269 | // Container isolation technology. 270 | Isolation string 271 | 272 | // Kernel memory limit. 273 | KernelMemory string 274 | 275 | // Set meta data on a container. 276 | Label []string 277 | 278 | // Read in a line delimited file of labels. 279 | LabelFile []string 280 | 281 | // Add link to another container. 282 | Link []string 283 | 284 | // Container IPv4/IPv6 link-local addresses. 285 | LinkLocalIp []string 286 | 287 | // Logging driver for the container. 288 | LogDriver string 289 | 290 | // Log driver options. 291 | LogOpt []string 292 | 293 | // Container MAC address (e.g., 92:d0:c6:0a:29:33). 294 | MacAddress string 295 | 296 | // Memory limit. 297 | Memory string 298 | 299 | // Memory soft limit. 300 | MemoryReservation string 301 | 302 | // Swap limit equal to memory plus swap: '-1' to enable unlimited swap. 303 | MemorySwap string 304 | 305 | // Tune container memory swappiness (0 to 100). 306 | MemorySwappiness string 307 | 308 | // Attach a filesystem mount to the container. 309 | Mount string 310 | 311 | // Assign a name to the container. 312 | Name string 313 | 314 | // Connect a container to a network. 315 | Net string 316 | 317 | // Add network-scoped alias for the container. 318 | NetAlias []string 319 | 320 | // Connect a container to a network. 321 | Network string 322 | 323 | // Add network-scoped alias for the container. 324 | NetworkAlias []string 325 | 326 | // Disable any container-specified HEALTHCHECK. 327 | NoHealthcheck bool 328 | 329 | // Disable OOM Killer. 330 | OomKillDisable bool 331 | 332 | // Tune host's OOM preferences (-1000 to 1000). 333 | OomScoreAdj *int 334 | 335 | // PID namespace to use. 336 | Pid string 337 | 338 | // Tune container pids limit (set -1 for unlimited). 339 | PidsLimit string 340 | 341 | // Set platform if server is multi-platform capable. 342 | Platform string 343 | 344 | // Give extended privileges to this container. 345 | Privileged bool 346 | 347 | // Publish a container's port(s) to the host. 348 | Publish []string 349 | 350 | // Publish all exposed ports to random ports. 351 | PublishAll bool 352 | 353 | // Pull image before creating (`always`, `|missing`, `never`). 354 | Pull string 355 | 356 | // Suppress the pull output. 357 | Quiet bool 358 | 359 | // Mount the container's root filesystem as read only. 360 | ReadOnly bool 361 | 362 | // Restart policy to apply when a container exits. 363 | Restart string 364 | 365 | // Automatically remove the container and its associated anonymous volumes when it exits. 366 | Rm bool 367 | 368 | // Runtime to use for this container. 369 | Runtime string 370 | 371 | // Security Options. 372 | SecurityOpt []string 373 | 374 | // Size of /dev/shm. 375 | ShmSize string 376 | 377 | // Signal to stop the container. 378 | StopSignal string 379 | 380 | // Timeout (in seconds) to stop a container. 381 | StopTimeout *int 382 | 383 | // Storage driver options for the container. 384 | StorageOpt []string 385 | 386 | // Sysctl options. 387 | Sysctl string 388 | 389 | // Mount a tmpfs directory. 390 | Tmpfs []string 391 | 392 | // Allocate a pseudo-TTY. 393 | Tty bool 394 | 395 | // Ulimit options. 396 | Ulimit string 397 | 398 | // Bind mount Docker API socket and required auth. 399 | UseApiSocket bool 400 | 401 | // Username or UID (format: [:]). 402 | User string 403 | 404 | // User namespace to use. 405 | Userns string 406 | 407 | // UTS namespace to use. 408 | Uts string 409 | 410 | // Bind mount a volume. 411 | Volume []string 412 | 413 | // Optional volume driver for the container. 414 | VolumeDriver string 415 | 416 | // Mount volumes from the specified container(s). 417 | VolumesFrom []string 418 | 419 | // Working directory inside the container. 420 | Workdir string 421 | } 422 | 423 | // Create a new container. 424 | func ContainerCreate(opts *ContainerCreateOpts, image string, command string, arg ...string) (string, error) { 425 | if err := findCli(); err != nil { 426 | return "", err 427 | } 428 | return runCtrCmd( 429 | []string{"container", "create"}, 430 | append([]string{image, command}, arg...), 431 | opts, 432 | 0, 433 | ) 434 | } 435 | 436 | type ContainerDiffOpts struct { 437 | // Base exec.Cmd. 438 | Cmd *exec.Cmd 439 | 440 | // Print usage. 441 | Help bool 442 | } 443 | 444 | // Inspect changes to files or directories on a container's filesystem. 445 | func ContainerDiff(opts *ContainerDiffOpts, container string) (string, error) { 446 | if err := findCli(); err != nil { 447 | return "", err 448 | } 449 | return runCtrCmd( 450 | []string{"container", "diff"}, 451 | []string{container}, 452 | opts, 453 | -1, 454 | ) 455 | } 456 | 457 | type ContainerExecOpts struct { 458 | // Base exec.Cmd. 459 | Cmd *exec.Cmd 460 | 461 | // Detached mode: run command in the background. 462 | Detach bool 463 | 464 | // Override the key sequence for detaching a container. 465 | DetachKeys string 466 | 467 | // Set environment variables. 468 | Env []string 469 | 470 | // Read in a file of environment variables. 471 | EnvFile []string 472 | 473 | // Print usage. 474 | Help bool 475 | 476 | // Keep STDIN open even if not attached. 477 | Interactive bool 478 | 479 | // Give extended privileges to the command. 480 | Privileged bool 481 | 482 | // Allocate a pseudo-TTY. 483 | Tty bool 484 | 485 | // Username or UID (format: `[:]`). 486 | User string 487 | 488 | // Working directory inside the container. 489 | Workdir string 490 | } 491 | 492 | // Execute a command in a running container. 493 | func ContainerExec(opts *ContainerExecOpts, container string, command string, arg ...string) (string, error) { 494 | if err := findCli(); err != nil { 495 | return "", err 496 | } 497 | return runCtrCmd( 498 | []string{"container", "exec"}, 499 | append([]string{container, command}, arg...), 500 | opts, 501 | 0, 502 | ) 503 | } 504 | 505 | type ContainerExportOpts struct { 506 | // Base exec.Cmd. 507 | Cmd *exec.Cmd 508 | 509 | // Print usage. 510 | Help bool 511 | 512 | // Write to a file, instead of STDOUT. 513 | Output string 514 | } 515 | 516 | // Export a container's filesystem as a tar archive. 517 | func ContainerExport(opts *ContainerExportOpts, container string) (string, error) { 518 | if err := findCli(); err != nil { 519 | return "", err 520 | } 521 | return runCtrCmd( 522 | []string{"container", "export"}, 523 | []string{container}, 524 | opts, 525 | 0, 526 | ) 527 | } 528 | 529 | type ContainerInspectOpts struct { 530 | // Base exec.Cmd. 531 | Cmd *exec.Cmd 532 | 533 | // Format output using a custom template: 534 | // 'json': Print in JSON format. 535 | // 'TEMPLATE': Print output using the given Go template. 536 | // Refer to https://docs.docker.com/go/formatting/ for more information about formatting output with templates. 537 | Format string 538 | 539 | // Print usage. 540 | Help bool 541 | 542 | // Display total file sizes. 543 | Size bool 544 | } 545 | 546 | // Display detailed information on one or more containers. 547 | func ContainerInspect(opts *ContainerInspectOpts, container ...string) (string, error) { 548 | if err := findCli(); err != nil { 549 | return "", err 550 | } 551 | if len(container) == 0 { 552 | return "", fmt.Errorf("container must have at least one value") 553 | } 554 | return runCtrCmd( 555 | []string{"container", "inspect"}, 556 | container, 557 | opts, 558 | 0, 559 | ) 560 | } 561 | 562 | type ContainerKillOpts struct { 563 | // Base exec.Cmd. 564 | Cmd *exec.Cmd 565 | 566 | // Print usage. 567 | Help bool 568 | 569 | // Signal to send to the container. 570 | Signal string 571 | } 572 | 573 | // Kill one or more running containers. 574 | func ContainerKill(opts *ContainerKillOpts, container ...string) (string, error) { 575 | if err := findCli(); err != nil { 576 | return "", err 577 | } 578 | if len(container) == 0 { 579 | return "", fmt.Errorf("container must have at least one value") 580 | } 581 | return runCtrCmd( 582 | []string{"container", "kill"}, 583 | container, 584 | opts, 585 | 0, 586 | ) 587 | } 588 | 589 | type ContainerLogsOpts struct { 590 | // Base exec.Cmd. 591 | Cmd *exec.Cmd 592 | 593 | // Show extra details provided to logs. 594 | Details bool 595 | 596 | // Follow log output. 597 | Follow bool 598 | 599 | // Print usage. 600 | Help bool 601 | 602 | // Show logs since timestamp (e.g. `2013-01-02T13:23:37Z`) or relative (e.g. `42m` for 42 minutes). 603 | Since string 604 | 605 | // Number of lines to show from the end of the logs. 606 | Tail string 607 | 608 | // Show timestamps. 609 | Timestamps bool 610 | 611 | // Show logs before a timestamp (e.g. `2013-01-02T13:23:37Z`) or relative (e.g. `42m` for 42 minutes). 612 | Until string 613 | } 614 | 615 | // Fetch the logs of a container. 616 | func ContainerLogs(opts *ContainerLogsOpts, container string) (string, error) { 617 | if err := findCli(); err != nil { 618 | return "", err 619 | } 620 | return runCtrCmd( 621 | []string{"container", "logs"}, 622 | []string{container}, 623 | opts, 624 | 0, 625 | ) 626 | } 627 | 628 | type ContainerLsOpts struct { 629 | // Base exec.Cmd. 630 | Cmd *exec.Cmd 631 | 632 | // Show all containers (default shows just running). 633 | All bool 634 | 635 | // Filter output based on conditions provided. 636 | Filter string 637 | 638 | // Format output using a custom template: 639 | // 'table': Print output in table format with column headers (default). 640 | // 'table TEMPLATE': Print output in table format using the given Go template. 641 | // 'json': Print in JSON format. 642 | // 'TEMPLATE': Print output using the given Go template. 643 | // Refer to https://docs.docker.com/go/formatting/ for more information about formatting output with templates. 644 | Format string 645 | 646 | // Print usage. 647 | Help bool 648 | 649 | // Show n last created containers (includes all states). 650 | Last *int 651 | 652 | // Show the latest created container (includes all states). 653 | Latest bool 654 | 655 | // Don't truncate output. 656 | NoTrunc bool 657 | 658 | // Only display container IDs. 659 | Quiet bool 660 | 661 | // Display total file sizes. 662 | Size bool 663 | } 664 | 665 | // List containers. 666 | func ContainerLs(opts *ContainerLsOpts) (string, error) { 667 | if err := findCli(); err != nil { 668 | return "", err 669 | } 670 | return runCtrCmd( 671 | []string{"container", "ls"}, 672 | []string{}, 673 | opts, 674 | 0, 675 | ) 676 | } 677 | 678 | type ContainerPauseOpts struct { 679 | // Base exec.Cmd. 680 | Cmd *exec.Cmd 681 | 682 | // Print usage. 683 | Help bool 684 | } 685 | 686 | // Pause all processes within one or more containers. 687 | func ContainerPause(opts *ContainerPauseOpts, container ...string) (string, error) { 688 | if err := findCli(); err != nil { 689 | return "", err 690 | } 691 | if len(container) == 0 { 692 | return "", fmt.Errorf("container must have at least one value") 693 | } 694 | return runCtrCmd( 695 | []string{"container", "pause"}, 696 | container, 697 | opts, 698 | -1, 699 | ) 700 | } 701 | 702 | type ContainerPortOpts struct { 703 | // Base exec.Cmd. 704 | Cmd *exec.Cmd 705 | 706 | // Print usage. 707 | Help bool 708 | } 709 | 710 | // List port mappings or a specific mapping for the container. 711 | func ContainerPort(opts *ContainerPortOpts, container string, privatePortProto string) (string, error) { 712 | if err := findCli(); err != nil { 713 | return "", err 714 | } 715 | return runCtrCmd( 716 | []string{"container", "port"}, 717 | []string{container, privatePortProto}, 718 | opts, 719 | -1, 720 | ) 721 | } 722 | 723 | type ContainerPruneOpts struct { 724 | // Base exec.Cmd. 725 | Cmd *exec.Cmd 726 | 727 | // Provide filter values (e.g. `until=`). 728 | Filter string 729 | 730 | // Do not prompt for confirmation. 731 | Force bool 732 | 733 | // Print usage. 734 | Help bool 735 | } 736 | 737 | // Remove all stopped containers. 738 | func ContainerPrune(opts *ContainerPruneOpts) (string, error) { 739 | if err := findCli(); err != nil { 740 | return "", err 741 | } 742 | return runCtrCmd( 743 | []string{"container", "prune"}, 744 | []string{}, 745 | opts, 746 | 0, 747 | ) 748 | } 749 | 750 | type ContainerRenameOpts struct { 751 | // Base exec.Cmd. 752 | Cmd *exec.Cmd 753 | 754 | // Print usage. 755 | Help bool 756 | } 757 | 758 | // Rename a container. 759 | func ContainerRename(opts *ContainerRenameOpts, container string, newName string) (string, error) { 760 | if err := findCli(); err != nil { 761 | return "", err 762 | } 763 | return runCtrCmd( 764 | []string{"container", "rename"}, 765 | []string{container, newName}, 766 | opts, 767 | -1, 768 | ) 769 | } 770 | 771 | type ContainerRestartOpts struct { 772 | // Base exec.Cmd. 773 | Cmd *exec.Cmd 774 | 775 | // Print usage. 776 | Help bool 777 | 778 | // Signal to send to the container. 779 | Signal string 780 | 781 | // Seconds to wait before killing the container (deprecated: use --timeout). 782 | Time *int 783 | 784 | // Seconds to wait before killing the container. 785 | Timeout *int 786 | } 787 | 788 | // Restart one or more containers. 789 | func ContainerRestart(opts *ContainerRestartOpts, container ...string) (string, error) { 790 | if err := findCli(); err != nil { 791 | return "", err 792 | } 793 | if len(container) == 0 { 794 | return "", fmt.Errorf("container must have at least one value") 795 | } 796 | return runCtrCmd( 797 | []string{"container", "restart"}, 798 | container, 799 | opts, 800 | 0, 801 | ) 802 | } 803 | 804 | type ContainerRmOpts struct { 805 | // Base exec.Cmd. 806 | Cmd *exec.Cmd 807 | 808 | // Force the removal of a running container (uses SIGKILL). 809 | Force bool 810 | 811 | // Print usage. 812 | Help bool 813 | 814 | // Remove the specified link. 815 | Link bool 816 | 817 | // Remove anonymous volumes associated with the container. 818 | Volumes bool 819 | } 820 | 821 | // Remove one or more containers. 822 | func ContainerRm(opts *ContainerRmOpts, container ...string) (string, error) { 823 | if err := findCli(); err != nil { 824 | return "", err 825 | } 826 | if len(container) == 0 { 827 | return "", fmt.Errorf("container must have at least one value") 828 | } 829 | return runCtrCmd( 830 | []string{"container", "rm"}, 831 | container, 832 | opts, 833 | 0, 834 | ) 835 | } 836 | 837 | type ContainerRunOpts struct { 838 | // Base exec.Cmd. 839 | Cmd *exec.Cmd 840 | 841 | // Add a custom host-to-IP mapping (host:ip). 842 | AddHost []string 843 | 844 | // Add an annotation to the container (passed through to the OCI runtime). 845 | Annotation string 846 | 847 | // Attach to STDIN, STDOUT or STDERR. 848 | Attach []string 849 | 850 | // Block IO (relative weight), between 10 and 1000, or 0 to disable (default 0). 851 | BlkioWeight string 852 | 853 | // Block IO weight (relative device weight). 854 | BlkioWeightDevice []string 855 | 856 | // Add Linux capabilities. 857 | CapAdd []string 858 | 859 | // Drop Linux capabilities. 860 | CapDrop []string 861 | 862 | // Optional parent cgroup for the container. 863 | CgroupParent string 864 | 865 | // Cgroup namespace to use (host|private). 866 | // 'host': Run the container in the Docker host's cgroup namespace. 867 | // 'private': Run the container in its own private cgroup namespace. 868 | // '': Use the cgroup namespace as configured by the. 869 | // default-cgroupns-mode option on the daemon (default). 870 | Cgroupns string 871 | 872 | // Write the container ID to the file. 873 | Cidfile string 874 | 875 | // CPU count (Windows only). 876 | CpuCount string 877 | 878 | // CPU percent (Windows only). 879 | CpuPercent string 880 | 881 | // Limit CPU CFS (Completely Fair Scheduler) period. 882 | CpuPeriod string 883 | 884 | // Limit CPU CFS (Completely Fair Scheduler) quota. 885 | CpuQuota string 886 | 887 | // Limit CPU real-time period in microseconds. 888 | CpuRtPeriod string 889 | 890 | // Limit CPU real-time runtime in microseconds. 891 | CpuRtRuntime string 892 | 893 | // CPU shares (relative weight). 894 | CpuShares string 895 | 896 | // Number of CPUs. 897 | Cpus string 898 | 899 | // CPUs in which to allow execution (0-3, 0,1). 900 | CpusetCpus string 901 | 902 | // MEMs in which to allow execution (0-3, 0,1). 903 | CpusetMems string 904 | 905 | // Run container in background and print container ID. 906 | Detach bool 907 | 908 | // Override the key sequence for detaching a container. 909 | DetachKeys string 910 | 911 | // Add a host device to the container. 912 | Device []string 913 | 914 | // Add a rule to the cgroup allowed devices list. 915 | DeviceCgroupRule []string 916 | 917 | // Limit read rate (bytes per second) from a device. 918 | DeviceReadBps []string 919 | 920 | // Limit read rate (IO per second) from a device. 921 | DeviceReadIops []string 922 | 923 | // Limit write rate (bytes per second) to a device. 924 | DeviceWriteBps []string 925 | 926 | // Limit write rate (IO per second) to a device. 927 | DeviceWriteIops []string 928 | 929 | // Skip image verification. 930 | DisableContentTrust bool 931 | 932 | // Set custom DNS servers. 933 | Dns []string 934 | 935 | // Set DNS options. 936 | DnsOpt []string 937 | 938 | // Set DNS options. 939 | DnsOption []string 940 | 941 | // Set custom DNS search domains. 942 | DnsSearch []string 943 | 944 | // Container NIS domain name. 945 | Domainname string 946 | 947 | // Overwrite the default ENTRYPOINT of the image. 948 | Entrypoint string 949 | 950 | // Set environment variables. 951 | Env []string 952 | 953 | // Read in a file of environment variables. 954 | EnvFile []string 955 | 956 | // Expose a port or a range of ports. 957 | Expose []string 958 | 959 | // GPU devices to add to the container ('all' to pass all GPUs). 960 | Gpus string 961 | 962 | // Add additional groups to join. 963 | GroupAdd []string 964 | 965 | // Command to run to check health. 966 | HealthCmd string 967 | 968 | // Time between running the check (ms|s|m|h) (default 0s). 969 | HealthInterval string 970 | 971 | // Consecutive failures needed to report unhealthy. 972 | HealthRetries *int 973 | 974 | // Time between running the check during the start period (ms|s|m|h) (default 0s). 975 | HealthStartInterval string 976 | 977 | // Start period for the container to initialize before starting health-retries countdown (ms|s|m|h) (default 0s). 978 | HealthStartPeriod string 979 | 980 | // Maximum time to allow one check to run (ms|s|m|h) (default 0s). 981 | HealthTimeout string 982 | 983 | // Print usage. 984 | Help bool 985 | 986 | // Container host name. 987 | Hostname string 988 | 989 | // Run an init inside the container that forwards signals and reaps processes. 990 | Init bool 991 | 992 | // Keep STDIN open even if not attached. 993 | Interactive bool 994 | 995 | // Maximum IO bandwidth limit for the system drive (Windows only). 996 | IoMaxbandwidth string 997 | 998 | // Maximum IOps limit for the system drive (Windows only). 999 | IoMaxiops string 1000 | 1001 | // IPv4 address (e.g., 172.30.100.104). 1002 | Ip string 1003 | 1004 | // IPv6 address (e.g., 2001:db8::33). 1005 | Ip6 string 1006 | 1007 | // IPC mode to use. 1008 | Ipc string 1009 | 1010 | // Container isolation technology. 1011 | Isolation string 1012 | 1013 | // Kernel memory limit. 1014 | KernelMemory string 1015 | 1016 | // Set meta data on a container. 1017 | Label []string 1018 | 1019 | // Read in a line delimited file of labels. 1020 | LabelFile []string 1021 | 1022 | // Add link to another container. 1023 | Link []string 1024 | 1025 | // Container IPv4/IPv6 link-local addresses. 1026 | LinkLocalIp []string 1027 | 1028 | // Logging driver for the container. 1029 | LogDriver string 1030 | 1031 | // Log driver options. 1032 | LogOpt []string 1033 | 1034 | // Container MAC address (e.g., 92:d0:c6:0a:29:33). 1035 | MacAddress string 1036 | 1037 | // Memory limit. 1038 | Memory string 1039 | 1040 | // Memory soft limit. 1041 | MemoryReservation string 1042 | 1043 | // Swap limit equal to memory plus swap: '-1' to enable unlimited swap. 1044 | MemorySwap string 1045 | 1046 | // Tune container memory swappiness (0 to 100). 1047 | MemorySwappiness string 1048 | 1049 | // Attach a filesystem mount to the container. 1050 | Mount string 1051 | 1052 | // Assign a name to the container. 1053 | Name string 1054 | 1055 | // Connect a container to a network. 1056 | Net string 1057 | 1058 | // Add network-scoped alias for the container. 1059 | NetAlias []string 1060 | 1061 | // Connect a container to a network. 1062 | Network string 1063 | 1064 | // Add network-scoped alias for the container. 1065 | NetworkAlias []string 1066 | 1067 | // Disable any container-specified HEALTHCHECK. 1068 | NoHealthcheck bool 1069 | 1070 | // Disable OOM Killer. 1071 | OomKillDisable bool 1072 | 1073 | // Tune host's OOM preferences (-1000 to 1000). 1074 | OomScoreAdj *int 1075 | 1076 | // PID namespace to use. 1077 | Pid string 1078 | 1079 | // Tune container pids limit (set -1 for unlimited). 1080 | PidsLimit string 1081 | 1082 | // Set platform if server is multi-platform capable. 1083 | Platform string 1084 | 1085 | // Give extended privileges to this container. 1086 | Privileged bool 1087 | 1088 | // Publish a container's port(s) to the host. 1089 | Publish []string 1090 | 1091 | // Publish all exposed ports to random ports. 1092 | PublishAll bool 1093 | 1094 | // Pull image before running (`always`, `missing`, `never`). 1095 | Pull string 1096 | 1097 | // Suppress the pull output. 1098 | Quiet bool 1099 | 1100 | // Mount the container's root filesystem as read only. 1101 | ReadOnly bool 1102 | 1103 | // Restart policy to apply when a container exits. 1104 | Restart string 1105 | 1106 | // Automatically remove the container and its associated anonymous volumes when it exits. 1107 | Rm bool 1108 | 1109 | // Runtime to use for this container. 1110 | Runtime string 1111 | 1112 | // Security Options. 1113 | SecurityOpt []string 1114 | 1115 | // Size of /dev/shm. 1116 | ShmSize string 1117 | 1118 | // Proxy received signals to the process. 1119 | SigProxy bool 1120 | 1121 | // Signal to stop the container. 1122 | StopSignal string 1123 | 1124 | // Timeout (in seconds) to stop a container. 1125 | StopTimeout *int 1126 | 1127 | // Storage driver options for the container. 1128 | StorageOpt []string 1129 | 1130 | // Sysctl options. 1131 | Sysctl string 1132 | 1133 | // Mount a tmpfs directory. 1134 | Tmpfs []string 1135 | 1136 | // Allocate a pseudo-TTY. 1137 | Tty bool 1138 | 1139 | // Ulimit options. 1140 | Ulimit string 1141 | 1142 | // Bind mount Docker API socket and required auth. 1143 | UseApiSocket bool 1144 | 1145 | // Username or UID (format: [:]). 1146 | User string 1147 | 1148 | // User namespace to use. 1149 | Userns string 1150 | 1151 | // UTS namespace to use. 1152 | Uts string 1153 | 1154 | // Bind mount a volume. 1155 | Volume []string 1156 | 1157 | // Optional volume driver for the container. 1158 | VolumeDriver string 1159 | 1160 | // Mount volumes from the specified container(s). 1161 | VolumesFrom []string 1162 | 1163 | // Working directory inside the container. 1164 | Workdir string 1165 | } 1166 | 1167 | // Create and run a new container from an image. 1168 | func ContainerRun(opts *ContainerRunOpts, image string, command string, arg ...string) (string, error) { 1169 | if err := findCli(); err != nil { 1170 | return "", err 1171 | } 1172 | return runCtrCmd( 1173 | []string{"container", "run"}, 1174 | append([]string{image, command}, arg...), 1175 | opts, 1176 | 0, 1177 | ) 1178 | } 1179 | 1180 | type ContainerStartOpts struct { 1181 | // Base exec.Cmd. 1182 | Cmd *exec.Cmd 1183 | 1184 | // Attach STDOUT/STDERR and forward signals. 1185 | Attach bool 1186 | 1187 | // Restore from this checkpoint. 1188 | Checkpoint string 1189 | 1190 | // Use a custom checkpoint storage directory. 1191 | CheckpointDir string 1192 | 1193 | // Override the key sequence for detaching a container. 1194 | DetachKeys string 1195 | 1196 | // Print usage. 1197 | Help bool 1198 | 1199 | // Attach container's STDIN. 1200 | Interactive bool 1201 | } 1202 | 1203 | // Start one or more stopped containers. 1204 | func ContainerStart(opts *ContainerStartOpts, container ...string) (string, error) { 1205 | if err := findCli(); err != nil { 1206 | return "", err 1207 | } 1208 | if len(container) == 0 { 1209 | return "", fmt.Errorf("container must have at least one value") 1210 | } 1211 | return runCtrCmd( 1212 | []string{"container", "start"}, 1213 | container, 1214 | opts, 1215 | 0, 1216 | ) 1217 | } 1218 | 1219 | type ContainerStatsOpts struct { 1220 | // Base exec.Cmd. 1221 | Cmd *exec.Cmd 1222 | 1223 | // Show all containers (default shows just running). 1224 | All bool 1225 | 1226 | // Format output using a custom template: 1227 | // 'table': Print output in table format with column headers (default). 1228 | // 'table TEMPLATE': Print output in table format using the given Go template. 1229 | // 'json': Print in JSON format. 1230 | // 'TEMPLATE': Print output using the given Go template. 1231 | // Refer to https://docs.docker.com/go/formatting/ for more information about formatting output with templates. 1232 | Format string 1233 | 1234 | // Print usage. 1235 | Help bool 1236 | 1237 | // Disable streaming stats and only pull the first result. 1238 | NoStream bool 1239 | 1240 | // Do not truncate output. 1241 | NoTrunc bool 1242 | } 1243 | 1244 | // Display a live stream of container(s) resource usage statistics. 1245 | func ContainerStats(opts *ContainerStatsOpts, container ...string) (string, error) { 1246 | if err := findCli(); err != nil { 1247 | return "", err 1248 | } 1249 | return runCtrCmd( 1250 | []string{"container", "stats"}, 1251 | container, 1252 | opts, 1253 | 0, 1254 | ) 1255 | } 1256 | 1257 | type ContainerStopOpts struct { 1258 | // Base exec.Cmd. 1259 | Cmd *exec.Cmd 1260 | 1261 | // Print usage. 1262 | Help bool 1263 | 1264 | // Signal to send to the container. 1265 | Signal string 1266 | 1267 | // Seconds to wait before killing the container (deprecated: use --timeout). 1268 | Time *int 1269 | 1270 | // Seconds to wait before killing the container. 1271 | Timeout *int 1272 | } 1273 | 1274 | // Stop one or more running containers. 1275 | func ContainerStop(opts *ContainerStopOpts, container ...string) (string, error) { 1276 | if err := findCli(); err != nil { 1277 | return "", err 1278 | } 1279 | if len(container) == 0 { 1280 | return "", fmt.Errorf("container must have at least one value") 1281 | } 1282 | return runCtrCmd( 1283 | []string{"container", "stop"}, 1284 | container, 1285 | opts, 1286 | 0, 1287 | ) 1288 | } 1289 | 1290 | type ContainerTopOpts struct { 1291 | // Base exec.Cmd. 1292 | Cmd *exec.Cmd 1293 | 1294 | // Print usage. 1295 | Help bool 1296 | } 1297 | 1298 | // Display the running processes of a container. 1299 | func ContainerTop(opts *ContainerTopOpts, container string, psOptions string) (string, error) { 1300 | if err := findCli(); err != nil { 1301 | return "", err 1302 | } 1303 | return runCtrCmd( 1304 | []string{"container", "top"}, 1305 | []string{container, psOptions}, 1306 | opts, 1307 | -1, 1308 | ) 1309 | } 1310 | 1311 | type ContainerUnpauseOpts struct { 1312 | // Base exec.Cmd. 1313 | Cmd *exec.Cmd 1314 | 1315 | // Print usage. 1316 | Help bool 1317 | } 1318 | 1319 | // Unpause all processes within one or more containers. 1320 | func ContainerUnpause(opts *ContainerUnpauseOpts, container ...string) (string, error) { 1321 | if err := findCli(); err != nil { 1322 | return "", err 1323 | } 1324 | if len(container) == 0 { 1325 | return "", fmt.Errorf("container must have at least one value") 1326 | } 1327 | return runCtrCmd( 1328 | []string{"container", "unpause"}, 1329 | container, 1330 | opts, 1331 | -1, 1332 | ) 1333 | } 1334 | 1335 | type ContainerUpdateOpts struct { 1336 | // Base exec.Cmd. 1337 | Cmd *exec.Cmd 1338 | 1339 | // Block IO (relative weight), between 10 and 1000, or 0 to disable (default 0). 1340 | BlkioWeight string 1341 | 1342 | // Limit CPU CFS (Completely Fair Scheduler) period. 1343 | CpuPeriod string 1344 | 1345 | // Limit CPU CFS (Completely Fair Scheduler) quota. 1346 | CpuQuota string 1347 | 1348 | // Limit the CPU real-time period in microseconds. 1349 | CpuRtPeriod string 1350 | 1351 | // Limit the CPU real-time runtime in microseconds. 1352 | CpuRtRuntime string 1353 | 1354 | // CPU shares (relative weight). 1355 | CpuShares string 1356 | 1357 | // Number of CPUs. 1358 | Cpus string 1359 | 1360 | // CPUs in which to allow execution (0-3, 0,1). 1361 | CpusetCpus string 1362 | 1363 | // MEMs in which to allow execution (0-3, 0,1). 1364 | CpusetMems string 1365 | 1366 | // Print usage. 1367 | Help bool 1368 | 1369 | // Kernel memory limit (deprecated). 1370 | KernelMemory string 1371 | 1372 | // Memory limit. 1373 | Memory string 1374 | 1375 | // Memory soft limit. 1376 | MemoryReservation string 1377 | 1378 | // Swap limit equal to memory plus swap: -1 to enable unlimited swap. 1379 | MemorySwap string 1380 | 1381 | // Tune container pids limit (set -1 for unlimited). 1382 | PidsLimit string 1383 | 1384 | // Restart policy to apply when a container exits. 1385 | Restart string 1386 | } 1387 | 1388 | // Update configuration of one or more containers. 1389 | func ContainerUpdate(opts *ContainerUpdateOpts, container ...string) (string, error) { 1390 | if err := findCli(); err != nil { 1391 | return "", err 1392 | } 1393 | if len(container) == 0 { 1394 | return "", fmt.Errorf("container must have at least one value") 1395 | } 1396 | return runCtrCmd( 1397 | []string{"container", "update"}, 1398 | container, 1399 | opts, 1400 | 0, 1401 | ) 1402 | } 1403 | 1404 | type ContainerWaitOpts struct { 1405 | // Base exec.Cmd. 1406 | Cmd *exec.Cmd 1407 | 1408 | // Print usage. 1409 | Help bool 1410 | } 1411 | 1412 | // Block until one or more containers stop, then print their exit codes. 1413 | func ContainerWait(opts *ContainerWaitOpts, container ...string) (string, error) { 1414 | if err := findCli(); err != nil { 1415 | return "", err 1416 | } 1417 | if len(container) == 0 { 1418 | return "", fmt.Errorf("container must have at least one value") 1419 | } 1420 | return runCtrCmd( 1421 | []string{"container", "wait"}, 1422 | container, 1423 | opts, 1424 | -1, 1425 | ) 1426 | } 1427 | -------------------------------------------------------------------------------- /context.go: -------------------------------------------------------------------------------- 1 | // Code generated by lesiw.io/ctrctl. DO NOT EDIT. 2 | package ctrctl 3 | 4 | import ( 5 | "fmt" 6 | "os/exec" 7 | ) 8 | 9 | type ContextCreateOpts struct { 10 | // Base exec.Cmd. 11 | Cmd *exec.Cmd 12 | 13 | // Description of the context. 14 | Description string 15 | 16 | // set the docker endpoint. 17 | Docker string 18 | 19 | // create context from a named context. 20 | From string 21 | 22 | // Print usage. 23 | Help bool 24 | } 25 | 26 | // Create a context. 27 | func ContextCreate(opts *ContextCreateOpts, context string) (string, error) { 28 | if err := findCli(); err != nil { 29 | return "", err 30 | } 31 | return runCtrCmd( 32 | []string{"context", "create"}, 33 | []string{context}, 34 | opts, 35 | 0, 36 | ) 37 | } 38 | 39 | type ContextExportOpts struct { 40 | // Base exec.Cmd. 41 | Cmd *exec.Cmd 42 | 43 | // Print usage. 44 | Help bool 45 | } 46 | 47 | // Export a context to a tar archive FILE or a tar stream on STDOUT. 48 | func ContextExport(opts *ContextExportOpts, context string, file string) (string, error) { 49 | if err := findCli(); err != nil { 50 | return "", err 51 | } 52 | return runCtrCmd( 53 | []string{"context", "export"}, 54 | []string{context, file}, 55 | opts, 56 | 0, 57 | ) 58 | } 59 | 60 | type ContextImportOpts struct { 61 | // Base exec.Cmd. 62 | Cmd *exec.Cmd 63 | 64 | // Print usage. 65 | Help bool 66 | } 67 | 68 | // Import a context from a tar or zip file. 69 | func ContextImport(opts *ContextImportOpts, context string, file string) (string, error) { 70 | if err := findCli(); err != nil { 71 | return "", err 72 | } 73 | return runCtrCmd( 74 | []string{"context", "import"}, 75 | []string{context, file}, 76 | opts, 77 | -1, 78 | ) 79 | } 80 | 81 | type ContextInspectOpts struct { 82 | // Base exec.Cmd. 83 | Cmd *exec.Cmd 84 | 85 | // Format output using a custom template: 86 | // 'json': Print in JSON format. 87 | // 'TEMPLATE': Print output using the given Go template. 88 | // Refer to https://docs.docker.com/go/formatting/ for more information about formatting output with templates. 89 | Format string 90 | 91 | // Print usage. 92 | Help bool 93 | } 94 | 95 | // Display detailed information on one or more contexts. 96 | func ContextInspect(opts *ContextInspectOpts, context ...string) (string, error) { 97 | if err := findCli(); err != nil { 98 | return "", err 99 | } 100 | if len(context) == 0 { 101 | return "", fmt.Errorf("context must have at least one value") 102 | } 103 | return runCtrCmd( 104 | []string{"context", "inspect"}, 105 | context, 106 | opts, 107 | 0, 108 | ) 109 | } 110 | 111 | type ContextLsOpts struct { 112 | // Base exec.Cmd. 113 | Cmd *exec.Cmd 114 | 115 | // Format output using a custom template: 116 | // 'table': Print output in table format with column headers (default). 117 | // 'table TEMPLATE': Print output in table format using the given Go template. 118 | // 'json': Print in JSON format. 119 | // 'TEMPLATE': Print output using the given Go template. 120 | // Refer to https://docs.docker.com/go/formatting/ for more information about formatting output with templates. 121 | Format string 122 | 123 | // Print usage. 124 | Help bool 125 | 126 | // Only show context names. 127 | Quiet bool 128 | } 129 | 130 | // List contexts. 131 | func ContextLs(opts *ContextLsOpts) (string, error) { 132 | if err := findCli(); err != nil { 133 | return "", err 134 | } 135 | return runCtrCmd( 136 | []string{"context", "ls"}, 137 | []string{}, 138 | opts, 139 | 0, 140 | ) 141 | } 142 | 143 | type ContextRmOpts struct { 144 | // Base exec.Cmd. 145 | Cmd *exec.Cmd 146 | 147 | // Force the removal of a context in use. 148 | Force bool 149 | 150 | // Print usage. 151 | Help bool 152 | } 153 | 154 | // Remove one or more contexts. 155 | func ContextRm(opts *ContextRmOpts, context ...string) (string, error) { 156 | if err := findCli(); err != nil { 157 | return "", err 158 | } 159 | if len(context) == 0 { 160 | return "", fmt.Errorf("context must have at least one value") 161 | } 162 | return runCtrCmd( 163 | []string{"context", "rm"}, 164 | context, 165 | opts, 166 | -1, 167 | ) 168 | } 169 | 170 | type ContextShowOpts struct { 171 | // Base exec.Cmd. 172 | Cmd *exec.Cmd 173 | 174 | // Print usage. 175 | Help bool 176 | } 177 | 178 | // Print the name of the current context. 179 | func ContextShow(opts *ContextShowOpts) (string, error) { 180 | if err := findCli(); err != nil { 181 | return "", err 182 | } 183 | return runCtrCmd( 184 | []string{"context", "show"}, 185 | []string{}, 186 | opts, 187 | -1, 188 | ) 189 | } 190 | 191 | type ContextUpdateOpts struct { 192 | // Base exec.Cmd. 193 | Cmd *exec.Cmd 194 | 195 | // Description of the context. 196 | Description string 197 | 198 | // set the docker endpoint. 199 | Docker string 200 | 201 | // Print usage. 202 | Help bool 203 | } 204 | 205 | // Update a context. 206 | func ContextUpdate(opts *ContextUpdateOpts, context string) (string, error) { 207 | if err := findCli(); err != nil { 208 | return "", err 209 | } 210 | return runCtrCmd( 211 | []string{"context", "update"}, 212 | []string{context}, 213 | opts, 214 | 0, 215 | ) 216 | } 217 | 218 | type ContextUseOpts struct { 219 | // Base exec.Cmd. 220 | Cmd *exec.Cmd 221 | 222 | // Print usage. 223 | Help bool 224 | } 225 | 226 | // Set the current docker context. 227 | func ContextUse(opts *ContextUseOpts, context string) (string, error) { 228 | if err := findCli(); err != nil { 229 | return "", err 230 | } 231 | return runCtrCmd( 232 | []string{"context", "use"}, 233 | []string{context}, 234 | opts, 235 | -1, 236 | ) 237 | } 238 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module lesiw.io/ctrctl 2 | 3 | go 1.21.0 4 | 5 | require gopkg.in/yaml.v3 v3.0.1 6 | -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- 1 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= 2 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 3 | gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= 4 | gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= 5 | -------------------------------------------------------------------------------- /image.go: -------------------------------------------------------------------------------- 1 | // Code generated by lesiw.io/ctrctl. DO NOT EDIT. 2 | package ctrctl 3 | 4 | import ( 5 | "fmt" 6 | "os/exec" 7 | ) 8 | 9 | type ImageBuildOpts struct { 10 | // Base exec.Cmd. 11 | Cmd *exec.Cmd 12 | 13 | // Add a custom host-to-IP mapping (`host:ip`). 14 | AddHost []string 15 | 16 | // Set build-time variables. 17 | BuildArg []string 18 | 19 | // Images to consider as cache sources. 20 | CacheFrom string 21 | 22 | // Set the parent cgroup for the `RUN` instructions during build. 23 | CgroupParent string 24 | 25 | // Compress the build context using gzip. 26 | Compress bool 27 | 28 | // Limit the CPU CFS (Completely Fair Scheduler) period. 29 | CpuPeriod string 30 | 31 | // Limit the CPU CFS (Completely Fair Scheduler) quota. 32 | CpuQuota string 33 | 34 | // CPU shares (relative weight). 35 | CpuShares string 36 | 37 | // CPUs in which to allow execution (0-3, 0,1). 38 | CpusetCpus string 39 | 40 | // MEMs in which to allow execution (0-3, 0,1). 41 | CpusetMems string 42 | 43 | // Skip image verification. 44 | DisableContentTrust bool 45 | 46 | // Name of the Dockerfile (Default is `PATH/Dockerfile`). 47 | File string 48 | 49 | // Always remove intermediate containers. 50 | ForceRm bool 51 | 52 | // Print usage. 53 | Help bool 54 | 55 | // Write the image ID to the file. 56 | Iidfile string 57 | 58 | // Container isolation technology. 59 | Isolation string 60 | 61 | // Set metadata for an image. 62 | Label []string 63 | 64 | // Memory limit. 65 | Memory string 66 | 67 | // Swap limit equal to memory plus swap: -1 to enable unlimited swap. 68 | MemorySwap string 69 | 70 | // Set the networking mode for the RUN instructions during build. 71 | Network string 72 | 73 | // Do not use cache when building the image. 74 | NoCache bool 75 | 76 | // Set platform if server is multi-platform capable. 77 | Platform string 78 | 79 | // Always attempt to pull a newer version of the image. 80 | Pull bool 81 | 82 | // Suppress the build output and print image ID on success. 83 | Quiet bool 84 | 85 | // Remove intermediate containers after a successful build. 86 | Rm bool 87 | 88 | // Security options. 89 | SecurityOpt string 90 | 91 | // Size of `/dev/shm`. 92 | ShmSize string 93 | 94 | // Squash newly built layers into a single new layer. 95 | Squash bool 96 | 97 | // Name and optionally a tag in the `name:tag` format. 98 | Tag []string 99 | 100 | // Set the target build stage to build. 101 | Target string 102 | 103 | // Ulimit options. 104 | Ulimit string 105 | } 106 | 107 | // Build an image from a Dockerfile. 108 | func ImageBuild(opts *ImageBuildOpts, pathUrl string) (string, error) { 109 | if err := findCli(); err != nil { 110 | return "", err 111 | } 112 | return runCtrCmd( 113 | []string{"image", "build"}, 114 | []string{pathUrl}, 115 | opts, 116 | 0, 117 | ) 118 | } 119 | 120 | type ImageHistoryOpts struct { 121 | // Base exec.Cmd. 122 | Cmd *exec.Cmd 123 | 124 | // Format output using a custom template: 125 | // 'table': Print output in table format with column headers (default). 126 | // 'table TEMPLATE': Print output in table format using the given Go template. 127 | // 'json': Print in JSON format. 128 | // 'TEMPLATE': Print output using the given Go template. 129 | // Refer to https://docs.docker.com/go/formatting/ for more information about formatting output with templates. 130 | Format string 131 | 132 | // Print usage. 133 | Help bool 134 | 135 | // Print sizes and dates in human readable format. 136 | Human bool 137 | 138 | // Don't truncate output. 139 | NoTrunc bool 140 | 141 | // Show history for the given platform. Formatted as `os[/arch[/variant]]` (e.g., `linux/amd64`). 142 | Platform string 143 | 144 | // Only show image IDs. 145 | Quiet bool 146 | } 147 | 148 | // Show the history of an image. 149 | func ImageHistory(opts *ImageHistoryOpts, image string) (string, error) { 150 | if err := findCli(); err != nil { 151 | return "", err 152 | } 153 | return runCtrCmd( 154 | []string{"image", "history"}, 155 | []string{image}, 156 | opts, 157 | 0, 158 | ) 159 | } 160 | 161 | type ImageImportOpts struct { 162 | // Base exec.Cmd. 163 | Cmd *exec.Cmd 164 | 165 | // Apply Dockerfile instruction to the created image. 166 | Change []string 167 | 168 | // Print usage. 169 | Help bool 170 | 171 | // Set commit message for imported image. 172 | Message string 173 | 174 | // Set platform if server is multi-platform capable. 175 | Platform string 176 | } 177 | 178 | // Import the contents from a tarball to create a filesystem image. 179 | func ImageImport(opts *ImageImportOpts, fileUrl string, RepositoryTag string) (string, error) { 180 | if err := findCli(); err != nil { 181 | return "", err 182 | } 183 | return runCtrCmd( 184 | []string{"image", "import"}, 185 | []string{fileUrl, RepositoryTag}, 186 | opts, 187 | 0, 188 | ) 189 | } 190 | 191 | type ImageInspectOpts struct { 192 | // Base exec.Cmd. 193 | Cmd *exec.Cmd 194 | 195 | // Format output using a custom template: 196 | // 'json': Print in JSON format. 197 | // 'TEMPLATE': Print output using the given Go template. 198 | // Refer to https://docs.docker.com/go/formatting/ for more information about formatting output with templates. 199 | Format string 200 | 201 | // Print usage. 202 | Help bool 203 | 204 | // Inspect a specific platform of the multi-platform image. 205 | // If the image or the server is not multi-platform capable, the command will error out if the platform does not match. 206 | // 'os[/arch[/variant]]': Explicit platform (eg. linux/amd64). 207 | Platform string 208 | } 209 | 210 | // Display detailed information on one or more images. 211 | func ImageInspect(opts *ImageInspectOpts, image ...string) (string, error) { 212 | if err := findCli(); err != nil { 213 | return "", err 214 | } 215 | if len(image) == 0 { 216 | return "", fmt.Errorf("image must have at least one value") 217 | } 218 | return runCtrCmd( 219 | []string{"image", "inspect"}, 220 | image, 221 | opts, 222 | 0, 223 | ) 224 | } 225 | 226 | type ImageLoadOpts struct { 227 | // Base exec.Cmd. 228 | Cmd *exec.Cmd 229 | 230 | // Print usage. 231 | Help bool 232 | 233 | // Read from tar archive file, instead of STDIN. 234 | Input string 235 | 236 | // Load only the given platform variant. Formatted as `os[/arch[/variant]]` (e.g., `linux/amd64`). 237 | Platform string 238 | 239 | // Suppress the load output. 240 | Quiet bool 241 | } 242 | 243 | // Load an image from a tar archive or STDIN. 244 | func ImageLoad(opts *ImageLoadOpts) (string, error) { 245 | if err := findCli(); err != nil { 246 | return "", err 247 | } 248 | return runCtrCmd( 249 | []string{"image", "load"}, 250 | []string{}, 251 | opts, 252 | 0, 253 | ) 254 | } 255 | 256 | type ImageLsOpts struct { 257 | // Base exec.Cmd. 258 | Cmd *exec.Cmd 259 | 260 | // Show all images (default hides intermediate images). 261 | All bool 262 | 263 | // Show digests. 264 | Digests bool 265 | 266 | // Filter output based on conditions provided. 267 | Filter string 268 | 269 | // Format output using a custom template: 270 | // 'table': Print output in table format with column headers (default). 271 | // 'table TEMPLATE': Print output in table format using the given Go template. 272 | // 'json': Print in JSON format. 273 | // 'TEMPLATE': Print output using the given Go template. 274 | // Refer to https://docs.docker.com/go/formatting/ for more information about formatting output with templates. 275 | Format string 276 | 277 | // Print usage. 278 | Help bool 279 | 280 | // Don't truncate output. 281 | NoTrunc bool 282 | 283 | // Only show image IDs. 284 | Quiet bool 285 | 286 | // List multi-platform images as a tree (EXPERIMENTAL). 287 | Tree bool 288 | } 289 | 290 | // List images. 291 | func ImageLs(opts *ImageLsOpts, repositoryTag string) (string, error) { 292 | if err := findCli(); err != nil { 293 | return "", err 294 | } 295 | return runCtrCmd( 296 | []string{"image", "ls"}, 297 | []string{repositoryTag}, 298 | opts, 299 | 0, 300 | ) 301 | } 302 | 303 | type ImagePruneOpts struct { 304 | // Base exec.Cmd. 305 | Cmd *exec.Cmd 306 | 307 | // Remove all unused images, not just dangling ones. 308 | All bool 309 | 310 | // Provide filter values (e.g. `until=`). 311 | Filter string 312 | 313 | // Do not prompt for confirmation. 314 | Force bool 315 | 316 | // Print usage. 317 | Help bool 318 | } 319 | 320 | // Remove unused images. 321 | func ImagePrune(opts *ImagePruneOpts) (string, error) { 322 | if err := findCli(); err != nil { 323 | return "", err 324 | } 325 | return runCtrCmd( 326 | []string{"image", "prune"}, 327 | []string{}, 328 | opts, 329 | 0, 330 | ) 331 | } 332 | 333 | type ImagePullOpts struct { 334 | // Base exec.Cmd. 335 | Cmd *exec.Cmd 336 | 337 | // Download all tagged images in the repository. 338 | AllTags bool 339 | 340 | // Skip image verification. 341 | DisableContentTrust bool 342 | 343 | // Print usage. 344 | Help bool 345 | 346 | // Set platform if server is multi-platform capable. 347 | Platform string 348 | 349 | // Suppress verbose output. 350 | Quiet bool 351 | } 352 | 353 | // Download an image from a registry. 354 | func ImagePull(opts *ImagePullOpts, nameTagDigest string) (string, error) { 355 | if err := findCli(); err != nil { 356 | return "", err 357 | } 358 | return runCtrCmd( 359 | []string{"image", "pull"}, 360 | []string{nameTagDigest}, 361 | opts, 362 | 0, 363 | ) 364 | } 365 | 366 | type ImagePushOpts struct { 367 | // Base exec.Cmd. 368 | Cmd *exec.Cmd 369 | 370 | // Push all tags of an image to the repository. 371 | AllTags bool 372 | 373 | // Skip image signing. 374 | DisableContentTrust bool 375 | 376 | // Print usage. 377 | Help bool 378 | 379 | // Push a platform-specific manifest as a single-platform image to the registry. 380 | // Image index won't be pushed, meaning that other manifests, including attestations won't be preserved. 381 | // 'os[/arch[/variant]]': Explicit platform (eg. linux/amd64). 382 | Platform string 383 | 384 | // Suppress verbose output. 385 | Quiet bool 386 | } 387 | 388 | // Upload an image to a registry. 389 | func ImagePush(opts *ImagePushOpts, nameTag string) (string, error) { 390 | if err := findCli(); err != nil { 391 | return "", err 392 | } 393 | return runCtrCmd( 394 | []string{"image", "push"}, 395 | []string{nameTag}, 396 | opts, 397 | 0, 398 | ) 399 | } 400 | 401 | type ImageRmOpts struct { 402 | // Base exec.Cmd. 403 | Cmd *exec.Cmd 404 | 405 | // Force removal of the image. 406 | Force bool 407 | 408 | // Print usage. 409 | Help bool 410 | 411 | // Do not delete untagged parents. 412 | NoPrune bool 413 | 414 | // Remove only the given platform variant. Formatted as `os[/arch[/variant]]` (e.g., `linux/amd64`). 415 | Platform string 416 | } 417 | 418 | // Remove one or more images. 419 | func ImageRm(opts *ImageRmOpts, image ...string) (string, error) { 420 | if err := findCli(); err != nil { 421 | return "", err 422 | } 423 | if len(image) == 0 { 424 | return "", fmt.Errorf("image must have at least one value") 425 | } 426 | return runCtrCmd( 427 | []string{"image", "rm"}, 428 | image, 429 | opts, 430 | 0, 431 | ) 432 | } 433 | 434 | type ImageSaveOpts struct { 435 | // Base exec.Cmd. 436 | Cmd *exec.Cmd 437 | 438 | // Print usage. 439 | Help bool 440 | 441 | // Write to a file, instead of STDOUT. 442 | Output string 443 | 444 | // Save only the given platform variant. Formatted as `os[/arch[/variant]]` (e.g., `linux/amd64`). 445 | Platform string 446 | } 447 | 448 | // Save one or more images to a tar archive (streamed to STDOUT by default). 449 | func ImageSave(opts *ImageSaveOpts, image ...string) (string, error) { 450 | if err := findCli(); err != nil { 451 | return "", err 452 | } 453 | if len(image) == 0 { 454 | return "", fmt.Errorf("image must have at least one value") 455 | } 456 | return runCtrCmd( 457 | []string{"image", "save"}, 458 | image, 459 | opts, 460 | 0, 461 | ) 462 | } 463 | 464 | type ImageTagOpts struct { 465 | // Base exec.Cmd. 466 | Cmd *exec.Cmd 467 | 468 | // Print usage. 469 | Help bool 470 | } 471 | 472 | // Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE. 473 | func ImageTag(opts *ImageTagOpts, sourceImageTag string, targetImageTag string) (string, error) { 474 | if err := findCli(); err != nil { 475 | return "", err 476 | } 477 | return runCtrCmd( 478 | []string{"image", "tag"}, 479 | []string{sourceImageTag, targetImageTag}, 480 | opts, 481 | -1, 482 | ) 483 | } 484 | -------------------------------------------------------------------------------- /internal/generate.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "archive/zip" 5 | "bytes" 6 | "fmt" 7 | "io" 8 | "net/http" 9 | "os" 10 | "os/exec" 11 | "path/filepath" 12 | "reflect" 13 | "sort" 14 | "strings" 15 | "text/template" 16 | "unicode" 17 | 18 | yaml "gopkg.in/yaml.v3" 19 | ) 20 | 21 | const doczip = "https://github.com/docker/docs/archive/refs/heads/main.zip" 22 | 23 | type ctrCliCmd struct { 24 | Command string 25 | Short string 26 | Long string 27 | Usage string 28 | Pname string 29 | Plink string 30 | Deprecated bool 31 | MinApiVersion string 32 | Experimental bool 33 | Experimentalcli bool 34 | Kubernetes bool 35 | Swarm bool 36 | Subcommand []string 37 | Options []*ctrCliOpt 38 | InheritedOptions []*ctrCliOpt `yaml:"inherited_options"` 39 | Arguments []*ctrCliArg 40 | Varg *ctrCliArg 41 | } 42 | 43 | type ctrCliArg struct { 44 | Name string 45 | Optional bool 46 | Varg bool 47 | VargRequired bool 48 | } 49 | 50 | type ctrCliOpt struct { 51 | Option string 52 | ValueType string `yaml:"value_type"` 53 | Description string 54 | Deprecated bool 55 | Hidden bool 56 | Experimental bool 57 | Experimentalcli bool 58 | Kubernetes bool 59 | Swarm bool 60 | DefaultValue string `yaml:"default_value"` 61 | } 62 | 63 | var cmdOverrides = map[string]*ctrCliCmd{ 64 | "cp": { 65 | Arguments: []*ctrCliArg{ 66 | {Name: "srcpath"}, 67 | {Name: "dstpath"}, 68 | }, 69 | }, 70 | "container cp": { 71 | Arguments: []*ctrCliArg{ 72 | {Name: "srcpath"}, 73 | {Name: "dstpath"}, 74 | }, 75 | }, 76 | } 77 | 78 | //nolint:lll 79 | const cmdTemplate = `type {{ .FuncName }}Opts struct { 80 | // Base exec.Cmd. 81 | Cmd *exec.Cmd 82 | 83 | {{ .OptsStruct }} 84 | } 85 | 86 | // {{ .Short }} 87 | func {{ .FuncName }}(opts *{{ .FuncName }}Opts{{if .ArgsDefn}}, {{ .ArgsDefn }}{{end}}) (string, error) { 88 | if err := findCli(); err != nil { 89 | return "", err 90 | } 91 | {{if .VargRequired }} if len({{ .Varg }}) == 0 { 92 | return "", fmt.Errorf("{{ .Varg }} must have at least one value") 93 | } 94 | {{end}} return runCtrCmd( 95 | {{ .Subcommand }}, 96 | {{if .Args}} {{ .Args }}, 97 | {{end}} opts, 98 | {{ .OptsPos }}, 99 | ) 100 | } 101 | 102 | ` 103 | 104 | const header = `// Code generated by lesiw.io/ctrctl. DO NOT EDIT. 105 | package ctrctl 106 | 107 | ` 108 | 109 | func main() { 110 | if err := run(); err != nil { 111 | fmt.Fprintf(os.Stderr, "%s\n", err) 112 | os.Exit(1) 113 | } 114 | } 115 | 116 | func run() error { 117 | docdir, err := os.MkdirTemp("", "ctrctl.*") 118 | if err != nil { 119 | return fmt.Errorf("error creating temporary directory: %w", err) 120 | } 121 | defer os.RemoveAll(docdir) 122 | 123 | if err := clearGeneratedFiles(); err != nil { 124 | return fmt.Errorf("error clearing previously generated files: %w", err) 125 | } 126 | if err := fetchZip(doczip, docdir); err != nil { 127 | return fmt.Errorf("error fetching docker docs: %w", err) 128 | } 129 | 130 | tmpl, err := template.New("").Parse(cmdTemplate) 131 | if err != nil { 132 | return fmt.Errorf("error parsing template: %w", err) 133 | } 134 | 135 | cliDocsDir := filepath.Join(docdir, "docs-main", "data", "engine-cli") 136 | m, err := outfilemap(cliDocsDir) 137 | if err != nil { 138 | return fmt.Errorf("error mapping output files: %w", err) 139 | } 140 | for name, files := range m { 141 | out, err := os.Create(name + ".go") 142 | if err != nil { 143 | return fmt.Errorf("error creating file %s: %w", name+".go", err) 144 | } 145 | defer out.Close() 146 | if _, err := out.WriteString(header); err != nil { 147 | return fmt.Errorf("error writing file %s: %w", name+".go", err) 148 | } 149 | for _, file := range files { 150 | path := filepath.Join(cliDocsDir, file) 151 | in, err := os.ReadFile(path) 152 | if err != nil { 153 | return fmt.Errorf("error reading file %s: %w", path, err) 154 | } 155 | if err := addCliDefinition(in, out, tmpl); err != nil { 156 | return fmt.Errorf("error adding cli definition: %w", err) 157 | } 158 | } 159 | } 160 | 161 | cmd := exec.Command("gofmt", "-w", "-s", ".") 162 | if err := cmd.Run(); err != nil { 163 | return fmt.Errorf("error running gofmt: %w", err) 164 | } 165 | cmd = exec.Command("goimports", "-w", ".") 166 | if err := cmd.Run(); err != nil { 167 | return fmt.Errorf("error running goimports: %w", err) 168 | } 169 | 170 | return nil 171 | } 172 | 173 | func clearGeneratedFiles() error { 174 | files, err := os.ReadDir(".") 175 | if err != nil { 176 | return fmt.Errorf("error reading files in directory: %w", err) 177 | } 178 | for _, f := range files { 179 | if f.IsDir() { 180 | continue 181 | } 182 | if !strings.HasSuffix(f.Name(), ".go") { 183 | continue 184 | } 185 | if f.Name() == "main.go" { 186 | continue 187 | } 188 | err := os.Remove(f.Name()) 189 | if err != nil { 190 | return fmt.Errorf("failed to remove file: %w", err) 191 | } 192 | } 193 | return nil 194 | } 195 | 196 | func outfilemap(path string) (map[string][]string, error) { 197 | result := make(map[string][]string) 198 | files, err := os.ReadDir(path) 199 | if err != nil { 200 | return nil, fmt.Errorf("error reading %s: %w", path, err) 201 | } 202 | for _, f := range files { 203 | if f.IsDir() { 204 | continue 205 | } 206 | nameparts := strings.Split(f.Name(), "_") 207 | var key string 208 | if len(nameparts) < 3 { 209 | key = "ctrctl" 210 | } else { 211 | key = nameparts[1] 212 | } 213 | _, ok := result[key] 214 | if !ok { 215 | result[key] = []string{} 216 | } 217 | result[key] = append(result[key], f.Name()) 218 | } 219 | for name := range result { 220 | sort.Strings(result[name]) 221 | } 222 | return result, nil 223 | } 224 | 225 | func fetchZip(url string, dir string) error { 226 | resp, err := http.Get(url) 227 | if err != nil { 228 | return err 229 | } 230 | defer resp.Body.Close() 231 | 232 | buf, err := io.ReadAll(resp.Body) 233 | if err != nil { 234 | return fmt.Errorf("error reading downloaded file: %w", err) 235 | } 236 | 237 | archive, err := zip.NewReader(bytes.NewReader(buf), int64(len(buf))) 238 | if err != nil { 239 | return fmt.Errorf("error reading zip: %w", err) 240 | } 241 | 242 | err = extractZip(archive, dir) 243 | if err != nil { 244 | return fmt.Errorf("error extracting zip: %w", err) 245 | } 246 | 247 | return nil 248 | } 249 | 250 | func extractZip(archive *zip.Reader, dir string) error { 251 | for _, f := range archive.File { 252 | if f.FileInfo().IsDir() { 253 | continue 254 | } 255 | 256 | fpath := filepath.Join(dir, f.Name) 257 | dpath := filepath.Dir(fpath) 258 | 259 | err := os.MkdirAll(dpath, 0755) 260 | if err != nil { 261 | return fmt.Errorf("error creating dir (%s): %w", fpath, err) 262 | } 263 | 264 | file, err := os.Create(fpath) 265 | if err != nil { 266 | return err 267 | } 268 | 269 | freader, err := f.Open() 270 | if err != nil { 271 | return fmt.Errorf("error opening file (%s): %w", f.Name, err) 272 | } 273 | 274 | _, err = io.Copy(file, freader) 275 | if err != nil { 276 | return fmt.Errorf("error copying file (%s): %w", f.Name, err) 277 | } 278 | 279 | file.Close() 280 | freader.Close() 281 | } 282 | return nil 283 | } 284 | 285 | func addCliDefinition( 286 | in []byte, out io.Writer, tmpl *template.Template, 287 | ) error { 288 | cmd, err := cmdFromDefinition(in) 289 | if err != nil { 290 | return err 291 | } 292 | 293 | trimmedCmd := strings.TrimPrefix(cmd.Command, "docker ") 294 | if trimmedCmd == "" { 295 | return nil 296 | } 297 | 298 | var varg string 299 | if cmd.Varg != nil { 300 | varg = cmd.Varg.Name 301 | } 302 | 303 | return tmpl.Execute(out, struct { 304 | FuncName string 305 | OptsStruct string 306 | Short string 307 | ArgsDefn string 308 | Args string 309 | OptsPos int 310 | Subcommand string 311 | Varg string 312 | VargRequired bool 313 | }{ 314 | FuncName: cmd.methodName(), 315 | OptsStruct: cmd.optsStruct(), 316 | Short: ensureDot(strings.TrimSpace(cmd.Short)), 317 | ArgsDefn: cmd.argsDefn(), 318 | Args: cmd.argsSlice(), 319 | OptsPos: cmd.optsPos(), 320 | Subcommand: cmd.subcommandSlice(), 321 | Varg: varg, 322 | VargRequired: (cmd.Varg != nil && cmd.Varg.VargRequired), 323 | }) 324 | } 325 | 326 | func cmdFromDefinition(buf []byte) (*ctrCliCmd, error) { 327 | cmd := &ctrCliCmd{} 328 | err := yaml.Unmarshal(buf, &cmd) 329 | if err != nil { 330 | return nil, err 331 | } 332 | 333 | cmd.Options = append(cmd.Options, cmd.InheritedOptions...) 334 | cmd.convertOptNames() 335 | sort.Slice(cmd.Options, func(i, j int) bool { 336 | return cmd.Options[i].Option < cmd.Options[j].Option 337 | }) 338 | 339 | cmd.parseUsage(strings.TrimPrefix(cmd.Usage, "docker ") + " ") 340 | 341 | if err := cmd.deduplicateArgs(); err != nil { 342 | return nil, fmt.Errorf("failed to deduplicate '%s' args: %w", 343 | cmd.Command, err) 344 | } 345 | 346 | overrides, ok := cmdOverrides[strings.TrimPrefix(cmd.Command, "docker ")] 347 | if ok { 348 | overrideStruct(cmd, overrides) 349 | } 350 | 351 | return cmd, nil 352 | } 353 | 354 | //nolint:gocyclo 355 | func (cmd *ctrCliCmd) parseUsage(usage string) { 356 | var word []rune 357 | var depth int 358 | var dots int 359 | var subFinished bool 360 | var nextUpper bool 361 | arg := &ctrCliArg{} 362 | usage = strings.ReplaceAll(usage, " | ", "|") 363 | for _, r := range usage { 364 | if r != '.' { 365 | dots = 0 366 | } 367 | switch r { 368 | case ' ': 369 | if depth == 0 { 370 | if len(word) == 0 { 371 | nextUpper = false 372 | continue 373 | } 374 | if subFinished { 375 | arg.Name = string(word) 376 | cmd.Arguments = append(cmd.Arguments, arg) 377 | arg = &ctrCliArg{} 378 | } else { 379 | cmd.Subcommand = append(cmd.Subcommand, string(word)) 380 | } 381 | word = []rune{} 382 | } else { 383 | nextUpper = true 384 | } 385 | case '[': 386 | subFinished = true 387 | if depth == 0 { 388 | arg.Optional = true 389 | } 390 | depth++ 391 | case ']': 392 | depth-- 393 | case '.': 394 | dots++ 395 | if dots > 2 { 396 | arg.Varg = true 397 | } 398 | default: 399 | if subFinished && !unicode.IsLetter(r) && !unicode.IsNumber(r) { 400 | nextUpper = true 401 | continue 402 | } 403 | if unicode.IsUpper(r) { 404 | subFinished = true 405 | } 406 | if nextUpper { 407 | nextUpper = false 408 | r = unicode.ToUpper(r) 409 | } else { 410 | r = unicode.ToLower(r) 411 | } 412 | word = append(word, r) 413 | } 414 | } 415 | } 416 | 417 | func (cmd *ctrCliCmd) deduplicateArgs() error { 418 | names := make(map[string]bool) 419 | var lastarg *ctrCliArg 420 | var newargs []*ctrCliArg 421 | for _, arg := range cmd.Arguments { 422 | _, seen := names[arg.Name] 423 | if seen { 424 | if cmd.Varg != nil { 425 | return fmt.Errorf("multiple vargs: %s, %s", cmd.Varg.Name, 426 | arg.Name) 427 | } 428 | if lastarg != nil && lastarg.Name == arg.Name { 429 | cmd.Varg = lastarg 430 | lastarg.Varg = true 431 | lastarg.VargRequired = true 432 | continue 433 | } else { 434 | arg.Name = fmt.Sprintf("extra%s", capitalize(arg.Name)) 435 | } 436 | } 437 | if arg.Varg { 438 | cmd.Varg = arg 439 | } 440 | names[arg.Name] = true 441 | newargs = append(newargs, arg) 442 | lastarg = arg 443 | } 444 | cmd.Arguments = newargs 445 | return nil 446 | } 447 | 448 | func (cmd *ctrCliCmd) convertOptNames() { 449 | for i := 0; i < len(cmd.Options); i++ { 450 | var name []rune 451 | var nextUpper bool 452 | for _, r := range cmd.Options[i].Option { 453 | if unicode.IsLetter(r) || unicode.IsNumber(r) { 454 | if nextUpper { 455 | nextUpper = false 456 | r = unicode.ToUpper(r) 457 | } 458 | name = append(name, r) 459 | } else { 460 | nextUpper = true 461 | } 462 | } 463 | cmd.Options[i].Option = string(name) 464 | } 465 | } 466 | 467 | func (cmd *ctrCliCmd) methodName() string { 468 | parts := strings.Fields(strings.TrimPrefix(cmd.Command, "docker ")) 469 | var result []string 470 | 471 | for _, part := range parts { 472 | titled := []rune{} 473 | nextUpper := true 474 | for _, r := range part { 475 | if nextUpper { 476 | r = unicode.ToUpper(r) 477 | nextUpper = false 478 | } 479 | if !unicode.IsLetter(r) { 480 | nextUpper = true 481 | continue 482 | } 483 | titled = append(titled, r) 484 | } 485 | result = append(result, string(titled)) 486 | } 487 | 488 | return strings.Join(result, "") 489 | } 490 | 491 | func (cmd *ctrCliCmd) optsStruct() string { 492 | var s strings.Builder 493 | for _, opt := range cmd.Options { 494 | for _, line := range strings.Split(opt.Description, "\n") { 495 | line = strings.TrimSpace(line) 496 | if line == "" { 497 | continue 498 | } 499 | s.WriteString(fmt.Sprintf("\t// %s\n", ensureDot(line))) 500 | } 501 | s.WriteString(fmt.Sprintf("\t%s %s\n\n", capitalize(opt.Option), 502 | opt.structType())) 503 | } 504 | return strings.TrimRight(s.String(), "\n") 505 | } 506 | 507 | func (c *ctrCliCmd) optsPos() int { 508 | for i, arg := range c.Arguments { 509 | if arg.isOpts() { 510 | return i 511 | } 512 | } 513 | return -1 514 | } 515 | 516 | func (c *ctrCliCmd) argsDefn() string { 517 | var defns []string 518 | for _, arg := range c.Arguments { 519 | if arg.isOpts() { 520 | continue 521 | } 522 | var defn string 523 | if arg.Varg { 524 | defn = fmt.Sprintf("%s ...string", arg.Name) 525 | } else { 526 | defn = fmt.Sprintf("%s string", arg.Name) 527 | } 528 | defns = append(defns, defn) 529 | } 530 | return strings.Join(defns, ", ") 531 | } 532 | 533 | func (c *ctrCliCmd) argsSlice() string { 534 | var defns []string 535 | for _, arg := range c.Arguments { 536 | if arg.isOpts() { 537 | continue 538 | } 539 | if arg.Varg { 540 | continue 541 | } 542 | defns = append(defns, arg.Name) 543 | } 544 | if len(defns) == 0 && c.Varg != nil { 545 | return c.Varg.Name 546 | } else if len(defns) == 0 { 547 | return "[]string{}" 548 | } else if c.Varg != nil { 549 | return fmt.Sprintf("append([]string{%s}, %s...)", 550 | strings.Join(defns, ","), 551 | c.Varg.Name, 552 | ) 553 | } else { 554 | return fmt.Sprintf("[]string{%s}", strings.Join(defns, ", ")) 555 | } 556 | } 557 | 558 | func (c *ctrCliCmd) subcommandSlice() string { 559 | quoted := []string{} 560 | for _, part := range c.Subcommand { 561 | quoted = append(quoted, "\""+part+"\"") 562 | } 563 | return fmt.Sprintf("[]string{%s}", strings.Join(quoted, ", ")) 564 | } 565 | 566 | func (a *ctrCliArg) isOpts() bool { 567 | return a.Name == "options" 568 | } 569 | 570 | func (o *ctrCliOpt) structType() string { 571 | switch o.ValueType { 572 | case "bool": 573 | return "bool" 574 | case "int": 575 | return "*int" 576 | case "list": 577 | return "[]string" 578 | default: 579 | return "string" 580 | } 581 | } 582 | 583 | func capitalize(s string) string { 584 | var result []rune 585 | for i, r := range s { 586 | if i == 0 { 587 | r = unicode.ToUpper(r) 588 | } 589 | result = append(result, r) 590 | } 591 | return string(result) 592 | } 593 | 594 | func ensureDot(s string) string { 595 | if strings.HasSuffix(s, ".") || strings.HasSuffix(s, ":") { 596 | return s 597 | } 598 | return s + "." 599 | } 600 | 601 | func overrideStruct(src, dst interface{}) { 602 | srcv := reflect.ValueOf(src).Elem() 603 | dstv := reflect.ValueOf(dst).Elem() 604 | 605 | for i := 0; i < dstv.NumField(); i++ { 606 | srcf := srcv.Field(i) 607 | dstf := dstv.Field(i) 608 | 609 | if !dstf.IsZero() { 610 | srcf.Set(dstf) 611 | } 612 | } 613 | } 614 | -------------------------------------------------------------------------------- /main.go: -------------------------------------------------------------------------------- 1 | //go:generate go run internal/generate.go 2 | 3 | // Package ctrctl wraps container CLIs. 4 | package ctrctl 5 | 6 | import ( 7 | "fmt" 8 | "io" 9 | "os" 10 | "os/exec" 11 | "path/filepath" 12 | "reflect" 13 | "regexp" 14 | "strconv" 15 | "strings" 16 | "sync" 17 | "unicode" 18 | ) 19 | 20 | // Cli is the command prefix. 21 | var Cli []string 22 | 23 | var clis = [...][]string{ 24 | {"docker"}, 25 | {"podman"}, 26 | {"nerdctl"}, 27 | {"lima", "nerdctl"}, 28 | } 29 | 30 | var findCli = sync.OnceValue(func() error { 31 | if Cli != nil { 32 | return nil 33 | } 34 | for _, cli := range clis { 35 | if _, err := exec.LookPath(cli[0]); err == nil { 36 | Cli = cli 37 | return nil 38 | } 39 | } 40 | return fmt.Errorf("no container cli found. searched: %+v", clis) 41 | }) 42 | 43 | // Verbose mode prints the commands being run and streams their output to the 44 | // terminal. 45 | var Verbose bool 46 | 47 | var shUnsafe = regexp.MustCompile(`[^\w@%+=:,./-]`) 48 | 49 | type CliError struct { 50 | *os.ProcessState 51 | 52 | Stderr string 53 | } 54 | 55 | func (e *CliError) Error() string { 56 | if e.Stderr != "" { 57 | return e.Stderr 58 | } else { 59 | return e.String() 60 | } 61 | } 62 | 63 | func runCtrCmd( 64 | subcommand []string, args []string, opts any, optpos int, 65 | ) (string, error) { 66 | var strout strings.Builder 67 | var strerr strings.Builder 68 | var cmd *exec.Cmd 69 | 70 | cmdargs := append(Cli, subcommand...) 71 | for i := 0; i < len(args); i++ { 72 | if optpos > -1 && i == optpos { 73 | if !reflect.ValueOf(opts).IsNil() { 74 | cmdargs = append(cmdargs, optsToArgs(opts)...) 75 | } 76 | optpos = -1 77 | i-- 78 | } else if !reflect.ValueOf(args[i]).IsZero() { 79 | cmdargs = append(cmdargs, args[i]) 80 | } 81 | } 82 | 83 | if !reflect.ValueOf(opts).IsNil() { 84 | var ok bool 85 | cmd, ok = reflect.ValueOf(opts).Elem().FieldByName("Cmd"). 86 | Interface().(*exec.Cmd) 87 | if !ok { 88 | panic("exec.Cmd failed type assertion") 89 | } 90 | } 91 | 92 | if cmd == nil { 93 | cmd = &exec.Cmd{} 94 | } 95 | cmd.Path = cmdargs[0] 96 | cmd.Args = cmdargs 97 | if filepath.Base(cmd.Path) == cmd.Path { 98 | lp, err := exec.LookPath(cmd.Path) 99 | if lp != "" { 100 | cmd.Path = lp 101 | } 102 | if err != nil { 103 | cmd.Err = err 104 | } 105 | } 106 | 107 | prepareStreams(cmd, &strout, &strerr) 108 | 109 | if Verbose { 110 | fmt.Fprintf(os.Stderr, "+ %s\n", shJoin(cmdargs)) 111 | } 112 | 113 | err := cmd.Run() 114 | if ee, ok := err.(*exec.ExitError); ok { 115 | err = &CliError{ 116 | ProcessState: ee.ProcessState, 117 | Stderr: strings.TrimSpace(strerr.String()), 118 | } 119 | } 120 | 121 | return strings.TrimSpace(strout.String()), err 122 | } 123 | 124 | func optsToArgs(opts interface{}) []string { 125 | result := []string{} 126 | val := reflect.ValueOf(opts).Elem() 127 | typ := val.Type() 128 | 129 | for i := 0; i < typ.NumField(); i++ { 130 | value := val.Field(i) 131 | field := typ.Field(i) 132 | 133 | if field.Name == "Cmd" { 134 | continue 135 | } 136 | 137 | if field.Type.Kind() == reflect.Ptr { 138 | if value.IsNil() { 139 | continue 140 | } 141 | val = val.Elem() 142 | } 143 | 144 | if field.Type.Kind() == reflect.String && value.IsZero() { 145 | continue 146 | } 147 | if field.Type.Kind() == reflect.Bool && !value.Bool() { 148 | continue 149 | } 150 | if field.Type.Kind() == reflect.Slice { 151 | for j := 0; j < value.Len(); j++ { 152 | str := value.Index(j) 153 | result = append(result, fieldToFlag(field.Name), str.String()) 154 | } 155 | } else { 156 | result = append(result, fieldToFlag(field.Name)) 157 | switch field.Type.Kind() { 158 | case reflect.Int: 159 | result = append(result, strconv.FormatInt(value.Int(), 10)) 160 | case reflect.String: 161 | result = append(result, value.String()) 162 | } 163 | } 164 | } 165 | 166 | return result 167 | } 168 | 169 | func fieldToFlag(s string) string { 170 | var result []rune 171 | for i, r := range s { 172 | if unicode.IsUpper(r) { 173 | if i > 0 { 174 | result = append(result, '-') 175 | } 176 | } 177 | result = append(result, unicode.ToLower(r)) 178 | } 179 | if len(result) == 1 { 180 | return fmt.Sprintf("-%s", string(result)) 181 | } else { 182 | return fmt.Sprintf("--%s", string(result)) 183 | } 184 | } 185 | 186 | func shQuote(s string) string { 187 | if s == "" { 188 | return `''` 189 | } 190 | if !shUnsafe.MatchString(s) { 191 | return s 192 | } 193 | return `'` + strings.ReplaceAll(s, `'`, `\'`) + `'` 194 | } 195 | 196 | func shJoin(parts []string) string { 197 | quotedParts := make([]string, len(parts)) 198 | for i, part := range parts { 199 | quotedParts[i] = shQuote(part) 200 | } 201 | return strings.Join(quotedParts, " ") 202 | } 203 | 204 | func prepareStreams(cmd *exec.Cmd, out io.Writer, err io.Writer) { 205 | if cmd.Stdout == nil { 206 | cmd.Stdout = out 207 | } 208 | if Verbose && cmd.Stdout != os.Stdout { 209 | cmd.Stdout = io.MultiWriter(cmd.Stdout, os.Stdout) 210 | } 211 | if cmd.Stderr == nil { 212 | cmd.Stderr = err 213 | } 214 | if Verbose && cmd.Stderr != os.Stderr { 215 | cmd.Stderr = io.MultiWriter(cmd.Stderr, os.Stderr) 216 | } 217 | } 218 | -------------------------------------------------------------------------------- /manifest.go: -------------------------------------------------------------------------------- 1 | // Code generated by lesiw.io/ctrctl. DO NOT EDIT. 2 | package ctrctl 3 | 4 | import ( 5 | "fmt" 6 | "os/exec" 7 | ) 8 | 9 | type ManifestAnnotateOpts struct { 10 | // Base exec.Cmd. 11 | Cmd *exec.Cmd 12 | 13 | // Set architecture. 14 | Arch string 15 | 16 | // Print usage. 17 | Help bool 18 | 19 | // Set operating system. 20 | Os string 21 | 22 | // Set operating system feature. 23 | OsFeatures string 24 | 25 | // Set operating system version. 26 | OsVersion string 27 | 28 | // Set architecture variant. 29 | Variant string 30 | } 31 | 32 | // Add additional information to a local image manifest. 33 | func ManifestAnnotate(opts *ManifestAnnotateOpts, manifestList string, manifest string) (string, error) { 34 | if err := findCli(); err != nil { 35 | return "", err 36 | } 37 | return runCtrCmd( 38 | []string{"manifest", "annotate"}, 39 | []string{manifestList, manifest}, 40 | opts, 41 | 0, 42 | ) 43 | } 44 | 45 | type ManifestCreateOpts struct { 46 | // Base exec.Cmd. 47 | Cmd *exec.Cmd 48 | 49 | // Amend an existing manifest list. 50 | Amend bool 51 | 52 | // Print usage. 53 | Help bool 54 | 55 | // Allow communication with an insecure registry. 56 | Insecure bool 57 | } 58 | 59 | // Create a local manifest list for annotating and pushing to a registry. 60 | func ManifestCreate(opts *ManifestCreateOpts, manifestList string, manifest ...string) (string, error) { 61 | if err := findCli(); err != nil { 62 | return "", err 63 | } 64 | if len(manifest) == 0 { 65 | return "", fmt.Errorf("manifest must have at least one value") 66 | } 67 | return runCtrCmd( 68 | []string{"manifest", "create"}, 69 | append([]string{manifestList}, manifest...), 70 | opts, 71 | -1, 72 | ) 73 | } 74 | 75 | type ManifestInspectOpts struct { 76 | // Base exec.Cmd. 77 | Cmd *exec.Cmd 78 | 79 | // Print usage. 80 | Help bool 81 | 82 | // Allow communication with an insecure registry. 83 | Insecure bool 84 | 85 | // Output additional info including layers and platform. 86 | Verbose bool 87 | } 88 | 89 | // Display an image manifest, or manifest list. 90 | func ManifestInspect(opts *ManifestInspectOpts, manifestList string, manifest string) (string, error) { 91 | if err := findCli(); err != nil { 92 | return "", err 93 | } 94 | return runCtrCmd( 95 | []string{"manifest", "inspect"}, 96 | []string{manifestList, manifest}, 97 | opts, 98 | 0, 99 | ) 100 | } 101 | 102 | type ManifestPushOpts struct { 103 | // Base exec.Cmd. 104 | Cmd *exec.Cmd 105 | 106 | // Print usage. 107 | Help bool 108 | 109 | // Allow push to an insecure registry. 110 | Insecure bool 111 | 112 | // Remove the local manifest list after push. 113 | Purge bool 114 | } 115 | 116 | // Push a manifest list to a repository. 117 | func ManifestPush(opts *ManifestPushOpts, manifestList string) (string, error) { 118 | if err := findCli(); err != nil { 119 | return "", err 120 | } 121 | return runCtrCmd( 122 | []string{"manifest", "push"}, 123 | []string{manifestList}, 124 | opts, 125 | 0, 126 | ) 127 | } 128 | 129 | type ManifestRmOpts struct { 130 | // Base exec.Cmd. 131 | Cmd *exec.Cmd 132 | 133 | // Print usage. 134 | Help bool 135 | } 136 | 137 | // Delete one or more manifest lists from local storage. 138 | func ManifestRm(opts *ManifestRmOpts, manifestList ...string) (string, error) { 139 | if err := findCli(); err != nil { 140 | return "", err 141 | } 142 | if len(manifestList) == 0 { 143 | return "", fmt.Errorf("manifestList must have at least one value") 144 | } 145 | return runCtrCmd( 146 | []string{"manifest", "rm"}, 147 | manifestList, 148 | opts, 149 | -1, 150 | ) 151 | } 152 | -------------------------------------------------------------------------------- /network.go: -------------------------------------------------------------------------------- 1 | // Code generated by lesiw.io/ctrctl. DO NOT EDIT. 2 | package ctrctl 3 | 4 | import ( 5 | "fmt" 6 | "os/exec" 7 | ) 8 | 9 | type NetworkConnectOpts struct { 10 | // Base exec.Cmd. 11 | Cmd *exec.Cmd 12 | 13 | // Add network-scoped alias for the container. 14 | Alias string 15 | 16 | // driver options for the network. 17 | DriverOpt string 18 | 19 | // Highest gw-priority provides the default gateway. Accepts positive and negative values. 20 | GwPriority *int 21 | 22 | // Print usage. 23 | Help bool 24 | 25 | // IPv4 address (e.g., `172.30.100.104`). 26 | Ip string 27 | 28 | // IPv6 address (e.g., `2001:db8::33`). 29 | Ip6 string 30 | 31 | // Add link to another container. 32 | Link []string 33 | 34 | // Add a link-local address for the container. 35 | LinkLocalIp string 36 | } 37 | 38 | // Connect a container to a network. 39 | func NetworkConnect(opts *NetworkConnectOpts, network string, container string) (string, error) { 40 | if err := findCli(); err != nil { 41 | return "", err 42 | } 43 | return runCtrCmd( 44 | []string{"network", "connect"}, 45 | []string{network, container}, 46 | opts, 47 | 0, 48 | ) 49 | } 50 | 51 | type NetworkCreateOpts struct { 52 | // Base exec.Cmd. 53 | Cmd *exec.Cmd 54 | 55 | // Enable manual container attachment. 56 | Attachable bool 57 | 58 | // Auxiliary IPv4 or IPv6 addresses used by Network driver. 59 | AuxAddress string 60 | 61 | // The network from which to copy the configuration. 62 | ConfigFrom string 63 | 64 | // Create a configuration only network. 65 | ConfigOnly bool 66 | 67 | // Driver to manage the Network. 68 | Driver string 69 | 70 | // IPv4 or IPv6 Gateway for the master subnet. 71 | Gateway string 72 | 73 | // Print usage. 74 | Help bool 75 | 76 | // Create swarm routing-mesh network. 77 | Ingress bool 78 | 79 | // Restrict external access to the network. 80 | Internal bool 81 | 82 | // Allocate container ip from a sub-range. 83 | IpRange string 84 | 85 | // IP Address Management Driver. 86 | IpamDriver string 87 | 88 | // Set IPAM driver specific options. 89 | IpamOpt string 90 | 91 | // Enable or disable IPv4 address assignment. 92 | Ipv4 bool 93 | 94 | // Enable or disable IPv6 address assignment. 95 | Ipv6 bool 96 | 97 | // Set metadata on a network. 98 | Label []string 99 | 100 | // Set driver specific options. 101 | Opt string 102 | 103 | // Control the network's scope. 104 | Scope string 105 | 106 | // Subnet in CIDR format that represents a network segment. 107 | Subnet string 108 | } 109 | 110 | // Create a network. 111 | func NetworkCreate(opts *NetworkCreateOpts, network string) (string, error) { 112 | if err := findCli(); err != nil { 113 | return "", err 114 | } 115 | return runCtrCmd( 116 | []string{"network", "create"}, 117 | []string{network}, 118 | opts, 119 | 0, 120 | ) 121 | } 122 | 123 | type NetworkDisconnectOpts struct { 124 | // Base exec.Cmd. 125 | Cmd *exec.Cmd 126 | 127 | // Force the container to disconnect from a network. 128 | Force bool 129 | 130 | // Print usage. 131 | Help bool 132 | } 133 | 134 | // Disconnect a container from a network. 135 | func NetworkDisconnect(opts *NetworkDisconnectOpts, network string, container string) (string, error) { 136 | if err := findCli(); err != nil { 137 | return "", err 138 | } 139 | return runCtrCmd( 140 | []string{"network", "disconnect"}, 141 | []string{network, container}, 142 | opts, 143 | 0, 144 | ) 145 | } 146 | 147 | type NetworkInspectOpts struct { 148 | // Base exec.Cmd. 149 | Cmd *exec.Cmd 150 | 151 | // Format output using a custom template: 152 | // 'json': Print in JSON format. 153 | // 'TEMPLATE': Print output using the given Go template. 154 | // Refer to https://docs.docker.com/go/formatting/ for more information about formatting output with templates. 155 | Format string 156 | 157 | // Print usage. 158 | Help bool 159 | 160 | // Verbose output for diagnostics. 161 | Verbose bool 162 | } 163 | 164 | // Display detailed information on one or more networks. 165 | func NetworkInspect(opts *NetworkInspectOpts, network ...string) (string, error) { 166 | if err := findCli(); err != nil { 167 | return "", err 168 | } 169 | if len(network) == 0 { 170 | return "", fmt.Errorf("network must have at least one value") 171 | } 172 | return runCtrCmd( 173 | []string{"network", "inspect"}, 174 | network, 175 | opts, 176 | 0, 177 | ) 178 | } 179 | 180 | type NetworkLsOpts struct { 181 | // Base exec.Cmd. 182 | Cmd *exec.Cmd 183 | 184 | // Provide filter values (e.g. `driver=bridge`). 185 | Filter string 186 | 187 | // Format output using a custom template: 188 | // 'table': Print output in table format with column headers (default). 189 | // 'table TEMPLATE': Print output in table format using the given Go template. 190 | // 'json': Print in JSON format. 191 | // 'TEMPLATE': Print output using the given Go template. 192 | // Refer to https://docs.docker.com/go/formatting/ for more information about formatting output with templates. 193 | Format string 194 | 195 | // Print usage. 196 | Help bool 197 | 198 | // Do not truncate the output. 199 | NoTrunc bool 200 | 201 | // Only display network IDs. 202 | Quiet bool 203 | } 204 | 205 | // List networks. 206 | func NetworkLs(opts *NetworkLsOpts) (string, error) { 207 | if err := findCli(); err != nil { 208 | return "", err 209 | } 210 | return runCtrCmd( 211 | []string{"network", "ls"}, 212 | []string{}, 213 | opts, 214 | 0, 215 | ) 216 | } 217 | 218 | type NetworkPruneOpts struct { 219 | // Base exec.Cmd. 220 | Cmd *exec.Cmd 221 | 222 | // Provide filter values (e.g. `until=`). 223 | Filter string 224 | 225 | // Do not prompt for confirmation. 226 | Force bool 227 | 228 | // Print usage. 229 | Help bool 230 | } 231 | 232 | // Remove all unused networks. 233 | func NetworkPrune(opts *NetworkPruneOpts) (string, error) { 234 | if err := findCli(); err != nil { 235 | return "", err 236 | } 237 | return runCtrCmd( 238 | []string{"network", "prune"}, 239 | []string{}, 240 | opts, 241 | 0, 242 | ) 243 | } 244 | 245 | type NetworkRmOpts struct { 246 | // Base exec.Cmd. 247 | Cmd *exec.Cmd 248 | 249 | // Do not error if the network does not exist. 250 | Force bool 251 | 252 | // Print usage. 253 | Help bool 254 | } 255 | 256 | // Remove one or more networks. 257 | func NetworkRm(opts *NetworkRmOpts, network ...string) (string, error) { 258 | if err := findCli(); err != nil { 259 | return "", err 260 | } 261 | if len(network) == 0 { 262 | return "", fmt.Errorf("network must have at least one value") 263 | } 264 | return runCtrCmd( 265 | []string{"network", "rm"}, 266 | network, 267 | opts, 268 | -1, 269 | ) 270 | } 271 | -------------------------------------------------------------------------------- /node.go: -------------------------------------------------------------------------------- 1 | // Code generated by lesiw.io/ctrctl. DO NOT EDIT. 2 | package ctrctl 3 | 4 | import ( 5 | "fmt" 6 | "os/exec" 7 | ) 8 | 9 | type NodeDemoteOpts struct { 10 | // Base exec.Cmd. 11 | Cmd *exec.Cmd 12 | 13 | // Print usage. 14 | Help bool 15 | } 16 | 17 | // Demote one or more nodes from manager in the swarm. 18 | func NodeDemote(opts *NodeDemoteOpts, node ...string) (string, error) { 19 | if err := findCli(); err != nil { 20 | return "", err 21 | } 22 | if len(node) == 0 { 23 | return "", fmt.Errorf("node must have at least one value") 24 | } 25 | return runCtrCmd( 26 | []string{"node", "demote"}, 27 | node, 28 | opts, 29 | -1, 30 | ) 31 | } 32 | 33 | type NodeInspectOpts struct { 34 | // Base exec.Cmd. 35 | Cmd *exec.Cmd 36 | 37 | // Format output using a custom template: 38 | // 'json': Print in JSON format. 39 | // 'TEMPLATE': Print output using the given Go template. 40 | // Refer to https://docs.docker.com/go/formatting/ for more information about formatting output with templates. 41 | Format string 42 | 43 | // Print usage. 44 | Help bool 45 | 46 | // Print the information in a human friendly format. 47 | Pretty bool 48 | } 49 | 50 | // Display detailed information on one or more nodes. 51 | func NodeInspect(opts *NodeInspectOpts, selfNode string, node ...string) (string, error) { 52 | if err := findCli(); err != nil { 53 | return "", err 54 | } 55 | return runCtrCmd( 56 | []string{"node", "inspect"}, 57 | append([]string{selfNode}, node...), 58 | opts, 59 | 0, 60 | ) 61 | } 62 | 63 | type NodeLsOpts struct { 64 | // Base exec.Cmd. 65 | Cmd *exec.Cmd 66 | 67 | // Filter output based on conditions provided. 68 | Filter string 69 | 70 | // Format output using a custom template: 71 | // 'table': Print output in table format with column headers (default). 72 | // 'table TEMPLATE': Print output in table format using the given Go template. 73 | // 'json': Print in JSON format. 74 | // 'TEMPLATE': Print output using the given Go template. 75 | // Refer to https://docs.docker.com/go/formatting/ for more information about formatting output with templates. 76 | Format string 77 | 78 | // Print usage. 79 | Help bool 80 | 81 | // Only display IDs. 82 | Quiet bool 83 | } 84 | 85 | // List nodes in the swarm. 86 | func NodeLs(opts *NodeLsOpts) (string, error) { 87 | if err := findCli(); err != nil { 88 | return "", err 89 | } 90 | return runCtrCmd( 91 | []string{"node", "ls"}, 92 | []string{}, 93 | opts, 94 | 0, 95 | ) 96 | } 97 | 98 | type NodePromoteOpts struct { 99 | // Base exec.Cmd. 100 | Cmd *exec.Cmd 101 | 102 | // Print usage. 103 | Help bool 104 | } 105 | 106 | // Promote one or more nodes to manager in the swarm. 107 | func NodePromote(opts *NodePromoteOpts, node ...string) (string, error) { 108 | if err := findCli(); err != nil { 109 | return "", err 110 | } 111 | if len(node) == 0 { 112 | return "", fmt.Errorf("node must have at least one value") 113 | } 114 | return runCtrCmd( 115 | []string{"node", "promote"}, 116 | node, 117 | opts, 118 | -1, 119 | ) 120 | } 121 | 122 | type NodePsOpts struct { 123 | // Base exec.Cmd. 124 | Cmd *exec.Cmd 125 | 126 | // Filter output based on conditions provided. 127 | Filter string 128 | 129 | // Pretty-print tasks using a Go template. 130 | Format string 131 | 132 | // Print usage. 133 | Help bool 134 | 135 | // Do not map IDs to Names. 136 | NoResolve bool 137 | 138 | // Do not truncate output. 139 | NoTrunc bool 140 | 141 | // Only display task IDs. 142 | Quiet bool 143 | } 144 | 145 | // List tasks running on one or more nodes, defaults to current node. 146 | func NodePs(opts *NodePsOpts, node ...string) (string, error) { 147 | if err := findCli(); err != nil { 148 | return "", err 149 | } 150 | return runCtrCmd( 151 | []string{"node", "ps"}, 152 | node, 153 | opts, 154 | 0, 155 | ) 156 | } 157 | 158 | type NodeRmOpts struct { 159 | // Base exec.Cmd. 160 | Cmd *exec.Cmd 161 | 162 | // Force remove a node from the swarm. 163 | Force bool 164 | 165 | // Print usage. 166 | Help bool 167 | } 168 | 169 | // Remove one or more nodes from the swarm. 170 | func NodeRm(opts *NodeRmOpts, node ...string) (string, error) { 171 | if err := findCli(); err != nil { 172 | return "", err 173 | } 174 | if len(node) == 0 { 175 | return "", fmt.Errorf("node must have at least one value") 176 | } 177 | return runCtrCmd( 178 | []string{"node", "rm"}, 179 | node, 180 | opts, 181 | 0, 182 | ) 183 | } 184 | 185 | type NodeUpdateOpts struct { 186 | // Base exec.Cmd. 187 | Cmd *exec.Cmd 188 | 189 | // Availability of the node (`active`, `pause`, `drain`). 190 | Availability string 191 | 192 | // Print usage. 193 | Help bool 194 | 195 | // Add or update a node label (`key=value`). 196 | LabelAdd []string 197 | 198 | // Remove a node label if exists. 199 | LabelRm []string 200 | 201 | // Role of the node (`worker`, `manager`). 202 | Role string 203 | } 204 | 205 | // Update a node. 206 | func NodeUpdate(opts *NodeUpdateOpts, node string) (string, error) { 207 | if err := findCli(); err != nil { 208 | return "", err 209 | } 210 | return runCtrCmd( 211 | []string{"node", "update"}, 212 | []string{node}, 213 | opts, 214 | 0, 215 | ) 216 | } 217 | -------------------------------------------------------------------------------- /plugin.go: -------------------------------------------------------------------------------- 1 | // Code generated by lesiw.io/ctrctl. DO NOT EDIT. 2 | package ctrctl 3 | 4 | import ( 5 | "fmt" 6 | "os/exec" 7 | ) 8 | 9 | type PluginCreateOpts struct { 10 | // Base exec.Cmd. 11 | Cmd *exec.Cmd 12 | 13 | // Compress the context using gzip. 14 | Compress bool 15 | 16 | // Print usage. 17 | Help bool 18 | } 19 | 20 | // Create a plugin from a rootfs and configuration. Plugin data directory must contain config.json and rootfs directory. 21 | func PluginCreate(opts *PluginCreateOpts, plugin string, pluginDataDir string) (string, error) { 22 | if err := findCli(); err != nil { 23 | return "", err 24 | } 25 | return runCtrCmd( 26 | []string{"plugin", "create"}, 27 | []string{plugin, pluginDataDir}, 28 | opts, 29 | 0, 30 | ) 31 | } 32 | 33 | type PluginDisableOpts struct { 34 | // Base exec.Cmd. 35 | Cmd *exec.Cmd 36 | 37 | // Force the disable of an active plugin. 38 | Force bool 39 | 40 | // Print usage. 41 | Help bool 42 | } 43 | 44 | // Disable a plugin. 45 | func PluginDisable(opts *PluginDisableOpts, plugin string) (string, error) { 46 | if err := findCli(); err != nil { 47 | return "", err 48 | } 49 | return runCtrCmd( 50 | []string{"plugin", "disable"}, 51 | []string{plugin}, 52 | opts, 53 | 0, 54 | ) 55 | } 56 | 57 | type PluginEnableOpts struct { 58 | // Base exec.Cmd. 59 | Cmd *exec.Cmd 60 | 61 | // Print usage. 62 | Help bool 63 | 64 | // HTTP client timeout (in seconds). 65 | Timeout *int 66 | } 67 | 68 | // Enable a plugin. 69 | func PluginEnable(opts *PluginEnableOpts, plugin string) (string, error) { 70 | if err := findCli(); err != nil { 71 | return "", err 72 | } 73 | return runCtrCmd( 74 | []string{"plugin", "enable"}, 75 | []string{plugin}, 76 | opts, 77 | 0, 78 | ) 79 | } 80 | 81 | type PluginInspectOpts struct { 82 | // Base exec.Cmd. 83 | Cmd *exec.Cmd 84 | 85 | // Format output using a custom template: 86 | // 'json': Print in JSON format. 87 | // 'TEMPLATE': Print output using the given Go template. 88 | // Refer to https://docs.docker.com/go/formatting/ for more information about formatting output with templates. 89 | Format string 90 | 91 | // Print usage. 92 | Help bool 93 | } 94 | 95 | // Display detailed information on one or more plugins. 96 | func PluginInspect(opts *PluginInspectOpts, plugin ...string) (string, error) { 97 | if err := findCli(); err != nil { 98 | return "", err 99 | } 100 | if len(plugin) == 0 { 101 | return "", fmt.Errorf("plugin must have at least one value") 102 | } 103 | return runCtrCmd( 104 | []string{"plugin", "inspect"}, 105 | plugin, 106 | opts, 107 | 0, 108 | ) 109 | } 110 | 111 | type PluginInstallOpts struct { 112 | // Base exec.Cmd. 113 | Cmd *exec.Cmd 114 | 115 | // Local name for plugin. 116 | Alias string 117 | 118 | // Do not enable the plugin on install. 119 | Disable bool 120 | 121 | // Skip image verification. 122 | DisableContentTrust bool 123 | 124 | // Grant all permissions necessary to run the plugin. 125 | GrantAllPermissions bool 126 | 127 | // Print usage. 128 | Help bool 129 | } 130 | 131 | // Install a plugin. 132 | func PluginInstall(opts *PluginInstallOpts, plugin string, keyValue ...string) (string, error) { 133 | if err := findCli(); err != nil { 134 | return "", err 135 | } 136 | return runCtrCmd( 137 | []string{"plugin", "install"}, 138 | append([]string{plugin}, keyValue...), 139 | opts, 140 | 0, 141 | ) 142 | } 143 | 144 | type PluginLsOpts struct { 145 | // Base exec.Cmd. 146 | Cmd *exec.Cmd 147 | 148 | // Provide filter values (e.g. `enabled=true`). 149 | Filter string 150 | 151 | // Format output using a custom template: 152 | // 'table': Print output in table format with column headers (default). 153 | // 'table TEMPLATE': Print output in table format using the given Go template. 154 | // 'json': Print in JSON format. 155 | // 'TEMPLATE': Print output using the given Go template. 156 | // Refer to https://docs.docker.com/go/formatting/ for more information about formatting output with templates. 157 | Format string 158 | 159 | // Print usage. 160 | Help bool 161 | 162 | // Don't truncate output. 163 | NoTrunc bool 164 | 165 | // Only display plugin IDs. 166 | Quiet bool 167 | } 168 | 169 | // List plugins. 170 | func PluginLs(opts *PluginLsOpts) (string, error) { 171 | if err := findCli(); err != nil { 172 | return "", err 173 | } 174 | return runCtrCmd( 175 | []string{"plugin", "ls"}, 176 | []string{}, 177 | opts, 178 | 0, 179 | ) 180 | } 181 | 182 | type PluginPushOpts struct { 183 | // Base exec.Cmd. 184 | Cmd *exec.Cmd 185 | 186 | // Skip image signing. 187 | DisableContentTrust bool 188 | 189 | // Print usage. 190 | Help bool 191 | } 192 | 193 | // Push a plugin to a registry. 194 | func PluginPush(opts *PluginPushOpts, pluginTag string) (string, error) { 195 | if err := findCli(); err != nil { 196 | return "", err 197 | } 198 | return runCtrCmd( 199 | []string{"plugin", "push"}, 200 | []string{pluginTag}, 201 | opts, 202 | 0, 203 | ) 204 | } 205 | 206 | type PluginRmOpts struct { 207 | // Base exec.Cmd. 208 | Cmd *exec.Cmd 209 | 210 | // Force the removal of an active plugin. 211 | Force bool 212 | 213 | // Print usage. 214 | Help bool 215 | } 216 | 217 | // Remove one or more plugins. 218 | func PluginRm(opts *PluginRmOpts, plugin ...string) (string, error) { 219 | if err := findCli(); err != nil { 220 | return "", err 221 | } 222 | if len(plugin) == 0 { 223 | return "", fmt.Errorf("plugin must have at least one value") 224 | } 225 | return runCtrCmd( 226 | []string{"plugin", "rm"}, 227 | plugin, 228 | opts, 229 | 0, 230 | ) 231 | } 232 | 233 | type PluginSetOpts struct { 234 | // Base exec.Cmd. 235 | Cmd *exec.Cmd 236 | 237 | // Print usage. 238 | Help bool 239 | } 240 | 241 | // Change settings for a plugin. 242 | func PluginSet(opts *PluginSetOpts, plugin string, keyValue ...string) (string, error) { 243 | if err := findCli(); err != nil { 244 | return "", err 245 | } 246 | if len(keyValue) == 0 { 247 | return "", fmt.Errorf("keyValue must have at least one value") 248 | } 249 | return runCtrCmd( 250 | []string{"plugin", "set"}, 251 | append([]string{plugin}, keyValue...), 252 | opts, 253 | -1, 254 | ) 255 | } 256 | 257 | type PluginUpgradeOpts struct { 258 | // Base exec.Cmd. 259 | Cmd *exec.Cmd 260 | 261 | // Skip image verification. 262 | DisableContentTrust bool 263 | 264 | // Grant all permissions necessary to run the plugin. 265 | GrantAllPermissions bool 266 | 267 | // Print usage. 268 | Help bool 269 | 270 | // Do not check if specified remote plugin matches existing plugin image. 271 | SkipRemoteCheck bool 272 | } 273 | 274 | // Upgrade an existing plugin. 275 | func PluginUpgrade(opts *PluginUpgradeOpts, plugin string, remote string) (string, error) { 276 | if err := findCli(); err != nil { 277 | return "", err 278 | } 279 | return runCtrCmd( 280 | []string{"plugin", "upgrade"}, 281 | []string{plugin, remote}, 282 | opts, 283 | 0, 284 | ) 285 | } 286 | -------------------------------------------------------------------------------- /secret.go: -------------------------------------------------------------------------------- 1 | // Code generated by lesiw.io/ctrctl. DO NOT EDIT. 2 | package ctrctl 3 | 4 | import ( 5 | "fmt" 6 | "os/exec" 7 | ) 8 | 9 | type SecretCreateOpts struct { 10 | // Base exec.Cmd. 11 | Cmd *exec.Cmd 12 | 13 | // Secret driver. 14 | Driver string 15 | 16 | // Print usage. 17 | Help bool 18 | 19 | // Secret labels. 20 | Label []string 21 | 22 | // Template driver. 23 | TemplateDriver string 24 | } 25 | 26 | // Create a secret from a file or STDIN as content. 27 | func SecretCreate(opts *SecretCreateOpts, secret string, file string) (string, error) { 28 | if err := findCli(); err != nil { 29 | return "", err 30 | } 31 | return runCtrCmd( 32 | []string{"secret", "create"}, 33 | []string{secret, file}, 34 | opts, 35 | 0, 36 | ) 37 | } 38 | 39 | type SecretInspectOpts struct { 40 | // Base exec.Cmd. 41 | Cmd *exec.Cmd 42 | 43 | // Format output using a custom template: 44 | // 'json': Print in JSON format. 45 | // 'TEMPLATE': Print output using the given Go template. 46 | // Refer to https://docs.docker.com/go/formatting/ for more information about formatting output with templates. 47 | Format string 48 | 49 | // Print usage. 50 | Help bool 51 | 52 | // Print the information in a human friendly format. 53 | Pretty bool 54 | } 55 | 56 | // Display detailed information on one or more secrets. 57 | func SecretInspect(opts *SecretInspectOpts, secret ...string) (string, error) { 58 | if err := findCli(); err != nil { 59 | return "", err 60 | } 61 | if len(secret) == 0 { 62 | return "", fmt.Errorf("secret must have at least one value") 63 | } 64 | return runCtrCmd( 65 | []string{"secret", "inspect"}, 66 | secret, 67 | opts, 68 | 0, 69 | ) 70 | } 71 | 72 | type SecretLsOpts struct { 73 | // Base exec.Cmd. 74 | Cmd *exec.Cmd 75 | 76 | // Filter output based on conditions provided. 77 | Filter string 78 | 79 | // Format output using a custom template: 80 | // 'table': Print output in table format with column headers (default). 81 | // 'table TEMPLATE': Print output in table format using the given Go template. 82 | // 'json': Print in JSON format. 83 | // 'TEMPLATE': Print output using the given Go template. 84 | // Refer to https://docs.docker.com/go/formatting/ for more information about formatting output with templates. 85 | Format string 86 | 87 | // Print usage. 88 | Help bool 89 | 90 | // Only display IDs. 91 | Quiet bool 92 | } 93 | 94 | // List secrets. 95 | func SecretLs(opts *SecretLsOpts) (string, error) { 96 | if err := findCli(); err != nil { 97 | return "", err 98 | } 99 | return runCtrCmd( 100 | []string{"secret", "ls"}, 101 | []string{}, 102 | opts, 103 | 0, 104 | ) 105 | } 106 | 107 | type SecretRmOpts struct { 108 | // Base exec.Cmd. 109 | Cmd *exec.Cmd 110 | 111 | // Print usage. 112 | Help bool 113 | } 114 | 115 | // Remove one or more secrets. 116 | func SecretRm(opts *SecretRmOpts, secret ...string) (string, error) { 117 | if err := findCli(); err != nil { 118 | return "", err 119 | } 120 | if len(secret) == 0 { 121 | return "", fmt.Errorf("secret must have at least one value") 122 | } 123 | return runCtrCmd( 124 | []string{"secret", "rm"}, 125 | secret, 126 | opts, 127 | -1, 128 | ) 129 | } 130 | -------------------------------------------------------------------------------- /service.go: -------------------------------------------------------------------------------- 1 | // Code generated by lesiw.io/ctrctl. DO NOT EDIT. 2 | package ctrctl 3 | 4 | import ( 5 | "fmt" 6 | "os/exec" 7 | ) 8 | 9 | type ServiceCreateOpts struct { 10 | // Base exec.Cmd. 11 | Cmd *exec.Cmd 12 | 13 | // Add Linux capabilities. 14 | CapAdd []string 15 | 16 | // Drop Linux capabilities. 17 | CapDrop []string 18 | 19 | // Specify configurations to expose to the service. 20 | Config string 21 | 22 | // Placement constraints. 23 | Constraint []string 24 | 25 | // Container labels. 26 | ContainerLabel []string 27 | 28 | // Credential spec for managed service account (Windows only). 29 | CredentialSpec string 30 | 31 | // Exit immediately instead of waiting for the service to converge. 32 | Detach bool 33 | 34 | // Set custom DNS servers. 35 | Dns []string 36 | 37 | // Set DNS options. 38 | DnsOption []string 39 | 40 | // Set custom DNS search domains. 41 | DnsSearch []string 42 | 43 | // Endpoint mode (vip or dnsrr). 44 | EndpointMode string 45 | 46 | // Overwrite the default ENTRYPOINT of the image. 47 | Entrypoint string 48 | 49 | // Set environment variables. 50 | Env []string 51 | 52 | // Read in a file of environment variables. 53 | EnvFile []string 54 | 55 | // User defined resources. 56 | GenericResource []string 57 | 58 | // Set one or more supplementary user groups for the container. 59 | Group []string 60 | 61 | // Command to run to check health. 62 | HealthCmd string 63 | 64 | // Time between running the check (ms|s|m|h). 65 | HealthInterval string 66 | 67 | // Consecutive failures needed to report unhealthy. 68 | HealthRetries *int 69 | 70 | // Time between running the check during the start period (ms|s|m|h). 71 | HealthStartInterval string 72 | 73 | // Start period for the container to initialize before counting retries towards unstable (ms|s|m|h). 74 | HealthStartPeriod string 75 | 76 | // Maximum time to allow one check to run (ms|s|m|h). 77 | HealthTimeout string 78 | 79 | // Print usage. 80 | Help bool 81 | 82 | // Set one or more custom host-to-IP mappings (host:ip). 83 | Host []string 84 | 85 | // Container hostname. 86 | Hostname string 87 | 88 | // Use an init inside each service container to forward signals and reap processes. 89 | Init bool 90 | 91 | // Service container isolation mode. 92 | Isolation string 93 | 94 | // Service labels. 95 | Label []string 96 | 97 | // Limit CPUs. 98 | LimitCpu string 99 | 100 | // Limit Memory. 101 | LimitMemory string 102 | 103 | // Limit maximum number of processes (default 0 = unlimited). 104 | LimitPids string 105 | 106 | // Logging driver for service. 107 | LogDriver string 108 | 109 | // Logging driver options. 110 | LogOpt []string 111 | 112 | // Number of job tasks to run concurrently (default equal to --replicas). 113 | MaxConcurrent string 114 | 115 | // Service mode (`replicated`, `global`, `replicated-job`, `global-job`). 116 | Mode string 117 | 118 | // Attach a filesystem mount to the service. 119 | Mount string 120 | 121 | // Service name. 122 | Name string 123 | 124 | // Network attachments. 125 | Network string 126 | 127 | // Disable any container-specified HEALTHCHECK. 128 | NoHealthcheck bool 129 | 130 | // Do not query the registry to resolve image digest and supported platforms. 131 | NoResolveImage bool 132 | 133 | // Tune host's OOM preferences (-1000 to 1000). 134 | OomScoreAdj string 135 | 136 | // Add a placement preference. 137 | PlacementPref string 138 | 139 | // Publish a port as a node port. 140 | Publish string 141 | 142 | // Suppress progress output. 143 | Quiet bool 144 | 145 | // Mount the container's root filesystem as read only. 146 | ReadOnly bool 147 | 148 | // Number of tasks. 149 | Replicas string 150 | 151 | // Maximum number of tasks per node (default 0 = unlimited). 152 | ReplicasMaxPerNode string 153 | 154 | // Reserve CPUs. 155 | ReserveCpu string 156 | 157 | // Reserve Memory. 158 | ReserveMemory string 159 | 160 | // Restart when condition is met (`none`, `on-failure`, `any`) (default `any`). 161 | RestartCondition string 162 | 163 | // Delay between restart attempts (ns|us|ms|s|m|h) (default 5s). 164 | RestartDelay string 165 | 166 | // Maximum number of restarts before giving up. 167 | RestartMaxAttempts string 168 | 169 | // Window used to evaluate the restart policy (ns|us|ms|s|m|h). 170 | RestartWindow string 171 | 172 | // Delay between task rollbacks (ns|us|ms|s|m|h) (default 0s). 173 | RollbackDelay string 174 | 175 | // Action on rollback failure (`pause`, `continue`) (default `pause`). 176 | RollbackFailureAction string 177 | 178 | // Failure rate to tolerate during a rollback (default 0). 179 | RollbackMaxFailureRatio string 180 | 181 | // Duration after each task rollback to monitor for failure (ns|us|ms|s|m|h) (default 5s). 182 | RollbackMonitor string 183 | 184 | // Rollback order (`start-first`, `stop-first`) (default `stop-first`). 185 | RollbackOrder string 186 | 187 | // Maximum number of tasks rolled back simultaneously (0 to roll back all at once). 188 | RollbackParallelism string 189 | 190 | // Specify secrets to expose to the service. 191 | Secret string 192 | 193 | // Time to wait before force killing a container (ns|us|ms|s|m|h) (default 10s). 194 | StopGracePeriod string 195 | 196 | // Signal to stop the container. 197 | StopSignal string 198 | 199 | // Sysctl options. 200 | Sysctl []string 201 | 202 | // Allocate a pseudo-TTY. 203 | Tty bool 204 | 205 | // Ulimit options. 206 | Ulimit string 207 | 208 | // Delay between updates (ns|us|ms|s|m|h) (default 0s). 209 | UpdateDelay string 210 | 211 | // Action on update failure (`pause`, `continue`, `rollback`) (default `pause`). 212 | UpdateFailureAction string 213 | 214 | // Failure rate to tolerate during an update (default 0). 215 | UpdateMaxFailureRatio string 216 | 217 | // Duration after each task update to monitor for failure (ns|us|ms|s|m|h) (default 5s). 218 | UpdateMonitor string 219 | 220 | // Update order (`start-first`, `stop-first`) (default `stop-first`). 221 | UpdateOrder string 222 | 223 | // Maximum number of tasks updated simultaneously (0 to update all at once). 224 | UpdateParallelism string 225 | 226 | // Username or UID (format: [:]). 227 | User string 228 | 229 | // Send registry authentication details to swarm agents. 230 | WithRegistryAuth bool 231 | 232 | // Working directory inside the container. 233 | Workdir string 234 | } 235 | 236 | // Create a new service. 237 | func ServiceCreate(opts *ServiceCreateOpts, image string, command string, arg ...string) (string, error) { 238 | if err := findCli(); err != nil { 239 | return "", err 240 | } 241 | return runCtrCmd( 242 | []string{"service", "create"}, 243 | append([]string{image, command}, arg...), 244 | opts, 245 | 0, 246 | ) 247 | } 248 | 249 | type ServiceInspectOpts struct { 250 | // Base exec.Cmd. 251 | Cmd *exec.Cmd 252 | 253 | // Format output using a custom template: 254 | // 'json': Print in JSON format. 255 | // 'TEMPLATE': Print output using the given Go template. 256 | // Refer to https://docs.docker.com/go/formatting/ for more information about formatting output with templates. 257 | Format string 258 | 259 | // Print usage. 260 | Help bool 261 | 262 | // Print the information in a human friendly format. 263 | Pretty bool 264 | } 265 | 266 | // Display detailed information on one or more services. 267 | func ServiceInspect(opts *ServiceInspectOpts, service ...string) (string, error) { 268 | if err := findCli(); err != nil { 269 | return "", err 270 | } 271 | if len(service) == 0 { 272 | return "", fmt.Errorf("service must have at least one value") 273 | } 274 | return runCtrCmd( 275 | []string{"service", "inspect"}, 276 | service, 277 | opts, 278 | 0, 279 | ) 280 | } 281 | 282 | type ServiceLogsOpts struct { 283 | // Base exec.Cmd. 284 | Cmd *exec.Cmd 285 | 286 | // Show extra details provided to logs. 287 | Details bool 288 | 289 | // Follow log output. 290 | Follow bool 291 | 292 | // Print usage. 293 | Help bool 294 | 295 | // Do not map IDs to Names in output. 296 | NoResolve bool 297 | 298 | // Do not include task IDs in output. 299 | NoTaskIds bool 300 | 301 | // Do not truncate output. 302 | NoTrunc bool 303 | 304 | // Do not neatly format logs. 305 | Raw bool 306 | 307 | // Show logs since timestamp (e.g. `2013-01-02T13:23:37Z`) or relative (e.g. `42m` for 42 minutes). 308 | Since string 309 | 310 | // Number of lines to show from the end of the logs. 311 | Tail string 312 | 313 | // Show timestamps. 314 | Timestamps bool 315 | } 316 | 317 | // Fetch the logs of a service or task. 318 | func ServiceLogs(opts *ServiceLogsOpts, serviceTask string) (string, error) { 319 | if err := findCli(); err != nil { 320 | return "", err 321 | } 322 | return runCtrCmd( 323 | []string{"service", "logs"}, 324 | []string{serviceTask}, 325 | opts, 326 | 0, 327 | ) 328 | } 329 | 330 | type ServiceLsOpts struct { 331 | // Base exec.Cmd. 332 | Cmd *exec.Cmd 333 | 334 | // Filter output based on conditions provided. 335 | Filter string 336 | 337 | // Format output using a custom template: 338 | // 'table': Print output in table format with column headers (default). 339 | // 'table TEMPLATE': Print output in table format using the given Go template. 340 | // 'json': Print in JSON format. 341 | // 'TEMPLATE': Print output using the given Go template. 342 | // Refer to https://docs.docker.com/go/formatting/ for more information about formatting output with templates. 343 | Format string 344 | 345 | // Print usage. 346 | Help bool 347 | 348 | // Only display IDs. 349 | Quiet bool 350 | } 351 | 352 | // List services. 353 | func ServiceLs(opts *ServiceLsOpts) (string, error) { 354 | if err := findCli(); err != nil { 355 | return "", err 356 | } 357 | return runCtrCmd( 358 | []string{"service", "ls"}, 359 | []string{}, 360 | opts, 361 | 0, 362 | ) 363 | } 364 | 365 | type ServicePsOpts struct { 366 | // Base exec.Cmd. 367 | Cmd *exec.Cmd 368 | 369 | // Filter output based on conditions provided. 370 | Filter string 371 | 372 | // Pretty-print tasks using a Go template. 373 | Format string 374 | 375 | // Print usage. 376 | Help bool 377 | 378 | // Do not map IDs to Names. 379 | NoResolve bool 380 | 381 | // Do not truncate output. 382 | NoTrunc bool 383 | 384 | // Only display task IDs. 385 | Quiet bool 386 | } 387 | 388 | // List the tasks of one or more services. 389 | func ServicePs(opts *ServicePsOpts, service ...string) (string, error) { 390 | if err := findCli(); err != nil { 391 | return "", err 392 | } 393 | if len(service) == 0 { 394 | return "", fmt.Errorf("service must have at least one value") 395 | } 396 | return runCtrCmd( 397 | []string{"service", "ps"}, 398 | service, 399 | opts, 400 | 0, 401 | ) 402 | } 403 | 404 | type ServiceRmOpts struct { 405 | // Base exec.Cmd. 406 | Cmd *exec.Cmd 407 | 408 | // Print usage. 409 | Help bool 410 | } 411 | 412 | // Remove one or more services. 413 | func ServiceRm(opts *ServiceRmOpts, service ...string) (string, error) { 414 | if err := findCli(); err != nil { 415 | return "", err 416 | } 417 | if len(service) == 0 { 418 | return "", fmt.Errorf("service must have at least one value") 419 | } 420 | return runCtrCmd( 421 | []string{"service", "rm"}, 422 | service, 423 | opts, 424 | -1, 425 | ) 426 | } 427 | 428 | type ServiceRollbackOpts struct { 429 | // Base exec.Cmd. 430 | Cmd *exec.Cmd 431 | 432 | // Exit immediately instead of waiting for the service to converge. 433 | Detach bool 434 | 435 | // Print usage. 436 | Help bool 437 | 438 | // Suppress progress output. 439 | Quiet bool 440 | } 441 | 442 | // Revert changes to a service's configuration. 443 | func ServiceRollback(opts *ServiceRollbackOpts, service string) (string, error) { 444 | if err := findCli(); err != nil { 445 | return "", err 446 | } 447 | return runCtrCmd( 448 | []string{"service", "rollback"}, 449 | []string{service}, 450 | opts, 451 | 0, 452 | ) 453 | } 454 | 455 | type ServiceScaleOpts struct { 456 | // Base exec.Cmd. 457 | Cmd *exec.Cmd 458 | 459 | // Exit immediately instead of waiting for the service to converge. 460 | Detach bool 461 | 462 | // Print usage. 463 | Help bool 464 | } 465 | 466 | // Scale one or multiple replicated services. 467 | func ServiceScale(opts *ServiceScaleOpts, serviceReplicas ...string) (string, error) { 468 | if err := findCli(); err != nil { 469 | return "", err 470 | } 471 | if len(serviceReplicas) == 0 { 472 | return "", fmt.Errorf("serviceReplicas must have at least one value") 473 | } 474 | return runCtrCmd( 475 | []string{"service", "scale"}, 476 | serviceReplicas, 477 | opts, 478 | -1, 479 | ) 480 | } 481 | 482 | type ServiceUpdateOpts struct { 483 | // Base exec.Cmd. 484 | Cmd *exec.Cmd 485 | 486 | // Service command args. 487 | Args string 488 | 489 | // Add Linux capabilities. 490 | CapAdd []string 491 | 492 | // Drop Linux capabilities. 493 | CapDrop []string 494 | 495 | // Add or update a config file on a service. 496 | ConfigAdd string 497 | 498 | // Remove a configuration file. 499 | ConfigRm []string 500 | 501 | // Add or update a placement constraint. 502 | ConstraintAdd []string 503 | 504 | // Remove a constraint. 505 | ConstraintRm []string 506 | 507 | // Add or update a container label. 508 | ContainerLabelAdd []string 509 | 510 | // Remove a container label by its key. 511 | ContainerLabelRm []string 512 | 513 | // Credential spec for managed service account (Windows only). 514 | CredentialSpec string 515 | 516 | // Exit immediately instead of waiting for the service to converge. 517 | Detach bool 518 | 519 | // Add or update a custom DNS server. 520 | DnsAdd []string 521 | 522 | // Add or update a DNS option. 523 | DnsOptionAdd []string 524 | 525 | // Remove a DNS option. 526 | DnsOptionRm []string 527 | 528 | // Remove a custom DNS server. 529 | DnsRm []string 530 | 531 | // Add or update a custom DNS search domain. 532 | DnsSearchAdd []string 533 | 534 | // Remove a DNS search domain. 535 | DnsSearchRm []string 536 | 537 | // Endpoint mode (vip or dnsrr). 538 | EndpointMode string 539 | 540 | // Overwrite the default ENTRYPOINT of the image. 541 | Entrypoint string 542 | 543 | // Add or update an environment variable. 544 | EnvAdd []string 545 | 546 | // Remove an environment variable. 547 | EnvRm []string 548 | 549 | // Force update even if no changes require it. 550 | Force bool 551 | 552 | // Add a Generic resource. 553 | GenericResourceAdd []string 554 | 555 | // Remove a Generic resource. 556 | GenericResourceRm []string 557 | 558 | // Add an additional supplementary user group to the container. 559 | GroupAdd []string 560 | 561 | // Remove a previously added supplementary user group from the container. 562 | GroupRm []string 563 | 564 | // Command to run to check health. 565 | HealthCmd string 566 | 567 | // Time between running the check (ms|s|m|h). 568 | HealthInterval string 569 | 570 | // Consecutive failures needed to report unhealthy. 571 | HealthRetries *int 572 | 573 | // Time between running the check during the start period (ms|s|m|h). 574 | HealthStartInterval string 575 | 576 | // Start period for the container to initialize before counting retries towards unstable (ms|s|m|h). 577 | HealthStartPeriod string 578 | 579 | // Maximum time to allow one check to run (ms|s|m|h). 580 | HealthTimeout string 581 | 582 | // Print usage. 583 | Help bool 584 | 585 | // Add a custom host-to-IP mapping (`host:ip`). 586 | HostAdd []string 587 | 588 | // Remove a custom host-to-IP mapping (`host:ip`). 589 | HostRm []string 590 | 591 | // Container hostname. 592 | Hostname string 593 | 594 | // Service image tag. 595 | Image string 596 | 597 | // Use an init inside each service container to forward signals and reap processes. 598 | Init bool 599 | 600 | // Service container isolation mode. 601 | Isolation string 602 | 603 | // Add or update a service label. 604 | LabelAdd []string 605 | 606 | // Remove a label by its key. 607 | LabelRm []string 608 | 609 | // Limit CPUs. 610 | LimitCpu string 611 | 612 | // Limit Memory. 613 | LimitMemory string 614 | 615 | // Limit maximum number of processes (default 0 = unlimited). 616 | LimitPids string 617 | 618 | // Logging driver for service. 619 | LogDriver string 620 | 621 | // Logging driver options. 622 | LogOpt []string 623 | 624 | // Number of job tasks to run concurrently (default equal to --replicas). 625 | MaxConcurrent string 626 | 627 | // Add or update a mount on a service. 628 | MountAdd string 629 | 630 | // Remove a mount by its target path. 631 | MountRm []string 632 | 633 | // Add a network. 634 | NetworkAdd string 635 | 636 | // Remove a network. 637 | NetworkRm []string 638 | 639 | // Disable any container-specified HEALTHCHECK. 640 | NoHealthcheck bool 641 | 642 | // Do not query the registry to resolve image digest and supported platforms. 643 | NoResolveImage bool 644 | 645 | // Tune host's OOM preferences (-1000 to 1000). 646 | OomScoreAdj string 647 | 648 | // Add a placement preference. 649 | PlacementPrefAdd string 650 | 651 | // Remove a placement preference. 652 | PlacementPrefRm string 653 | 654 | // Add or update a published port. 655 | PublishAdd string 656 | 657 | // Remove a published port by its target port. 658 | PublishRm string 659 | 660 | // Suppress progress output. 661 | Quiet bool 662 | 663 | // Mount the container's root filesystem as read only. 664 | ReadOnly bool 665 | 666 | // Number of tasks. 667 | Replicas string 668 | 669 | // Maximum number of tasks per node (default 0 = unlimited). 670 | ReplicasMaxPerNode string 671 | 672 | // Reserve CPUs. 673 | ReserveCpu string 674 | 675 | // Reserve Memory. 676 | ReserveMemory string 677 | 678 | // Restart when condition is met (`none`, `on-failure`, `any`). 679 | RestartCondition string 680 | 681 | // Delay between restart attempts (ns|us|ms|s|m|h). 682 | RestartDelay string 683 | 684 | // Maximum number of restarts before giving up. 685 | RestartMaxAttempts string 686 | 687 | // Window used to evaluate the restart policy (ns|us|ms|s|m|h). 688 | RestartWindow string 689 | 690 | // Rollback to previous specification. 691 | Rollback bool 692 | 693 | // Delay between task rollbacks (ns|us|ms|s|m|h). 694 | RollbackDelay string 695 | 696 | // Action on rollback failure (`pause`, `continue`). 697 | RollbackFailureAction string 698 | 699 | // Failure rate to tolerate during a rollback. 700 | RollbackMaxFailureRatio string 701 | 702 | // Duration after each task rollback to monitor for failure (ns|us|ms|s|m|h). 703 | RollbackMonitor string 704 | 705 | // Rollback order (`start-first`, `stop-first`). 706 | RollbackOrder string 707 | 708 | // Maximum number of tasks rolled back simultaneously (0 to roll back all at once). 709 | RollbackParallelism string 710 | 711 | // Add or update a secret on a service. 712 | SecretAdd string 713 | 714 | // Remove a secret. 715 | SecretRm []string 716 | 717 | // Time to wait before force killing a container (ns|us|ms|s|m|h). 718 | StopGracePeriod string 719 | 720 | // Signal to stop the container. 721 | StopSignal string 722 | 723 | // Add or update a Sysctl option. 724 | SysctlAdd []string 725 | 726 | // Remove a Sysctl option. 727 | SysctlRm []string 728 | 729 | // Allocate a pseudo-TTY. 730 | Tty bool 731 | 732 | // Add or update a ulimit option. 733 | UlimitAdd string 734 | 735 | // Remove a ulimit option. 736 | UlimitRm []string 737 | 738 | // Delay between updates (ns|us|ms|s|m|h). 739 | UpdateDelay string 740 | 741 | // Action on update failure (`pause`, `continue`, `rollback`). 742 | UpdateFailureAction string 743 | 744 | // Failure rate to tolerate during an update. 745 | UpdateMaxFailureRatio string 746 | 747 | // Duration after each task update to monitor for failure (ns|us|ms|s|m|h). 748 | UpdateMonitor string 749 | 750 | // Update order (`start-first`, `stop-first`). 751 | UpdateOrder string 752 | 753 | // Maximum number of tasks updated simultaneously (0 to update all at once). 754 | UpdateParallelism string 755 | 756 | // Username or UID (format: [:]). 757 | User string 758 | 759 | // Send registry authentication details to swarm agents. 760 | WithRegistryAuth bool 761 | 762 | // Working directory inside the container. 763 | Workdir string 764 | } 765 | 766 | // Update a service. 767 | func ServiceUpdate(opts *ServiceUpdateOpts, service string) (string, error) { 768 | if err := findCli(); err != nil { 769 | return "", err 770 | } 771 | return runCtrCmd( 772 | []string{"service", "update"}, 773 | []string{service}, 774 | opts, 775 | 0, 776 | ) 777 | } 778 | -------------------------------------------------------------------------------- /stack.go: -------------------------------------------------------------------------------- 1 | // Code generated by lesiw.io/ctrctl. DO NOT EDIT. 2 | package ctrctl 3 | 4 | import ( 5 | "fmt" 6 | "os/exec" 7 | ) 8 | 9 | type StackConfigOpts struct { 10 | // Base exec.Cmd. 11 | Cmd *exec.Cmd 12 | 13 | // Path to a Compose file, or `-` to read from stdin. 14 | ComposeFile string 15 | 16 | // Print usage. 17 | Help bool 18 | 19 | // Orchestrator to use (swarm|all). 20 | Orchestrator string 21 | 22 | // Skip interpolation and output only merged config. 23 | SkipInterpolation bool 24 | } 25 | 26 | // Outputs the final config file, after doing merges and interpolations. 27 | func StackConfig(opts *StackConfigOpts) (string, error) { 28 | if err := findCli(); err != nil { 29 | return "", err 30 | } 31 | return runCtrCmd( 32 | []string{"stack", "config"}, 33 | []string{}, 34 | opts, 35 | 0, 36 | ) 37 | } 38 | 39 | type StackDeployOpts struct { 40 | // Base exec.Cmd. 41 | Cmd *exec.Cmd 42 | 43 | // Path to a Compose file, or `-` to read from stdin. 44 | ComposeFile string 45 | 46 | // Exit immediately instead of waiting for the stack services to converge. 47 | Detach bool 48 | 49 | // Print usage. 50 | Help bool 51 | 52 | // Orchestrator to use (swarm|all). 53 | Orchestrator string 54 | 55 | // Prune services that are no longer referenced. 56 | Prune bool 57 | 58 | // Suppress progress output. 59 | Quiet bool 60 | 61 | // Query the registry to resolve image digest and supported platforms (`always`, `changed`, `never`). 62 | ResolveImage string 63 | 64 | // Send registry authentication details to Swarm agents. 65 | WithRegistryAuth bool 66 | } 67 | 68 | // Deploy a new stack or update an existing stack. 69 | func StackDeploy(opts *StackDeployOpts, stack string) (string, error) { 70 | if err := findCli(); err != nil { 71 | return "", err 72 | } 73 | return runCtrCmd( 74 | []string{"stack", "deploy"}, 75 | []string{stack}, 76 | opts, 77 | 0, 78 | ) 79 | } 80 | 81 | type StackLsOpts struct { 82 | // Base exec.Cmd. 83 | Cmd *exec.Cmd 84 | 85 | // Format output using a custom template: 86 | // 'table': Print output in table format with column headers (default). 87 | // 'table TEMPLATE': Print output in table format using the given Go template. 88 | // 'json': Print in JSON format. 89 | // 'TEMPLATE': Print output using the given Go template. 90 | // Refer to https://docs.docker.com/go/formatting/ for more information about formatting output with templates. 91 | Format string 92 | 93 | // Print usage. 94 | Help bool 95 | 96 | // Orchestrator to use (swarm|all). 97 | Orchestrator string 98 | } 99 | 100 | // List stacks. 101 | func StackLs(opts *StackLsOpts) (string, error) { 102 | if err := findCli(); err != nil { 103 | return "", err 104 | } 105 | return runCtrCmd( 106 | []string{"stack", "ls"}, 107 | []string{}, 108 | opts, 109 | 0, 110 | ) 111 | } 112 | 113 | type StackPsOpts struct { 114 | // Base exec.Cmd. 115 | Cmd *exec.Cmd 116 | 117 | // Filter output based on conditions provided. 118 | Filter string 119 | 120 | // Format output using a custom template: 121 | // 'table': Print output in table format with column headers (default). 122 | // 'table TEMPLATE': Print output in table format using the given Go template. 123 | // 'json': Print in JSON format. 124 | // 'TEMPLATE': Print output using the given Go template. 125 | // Refer to https://docs.docker.com/go/formatting/ for more information about formatting output with templates. 126 | Format string 127 | 128 | // Print usage. 129 | Help bool 130 | 131 | // Do not map IDs to Names. 132 | NoResolve bool 133 | 134 | // Do not truncate output. 135 | NoTrunc bool 136 | 137 | // Orchestrator to use (swarm|all). 138 | Orchestrator string 139 | 140 | // Only display task IDs. 141 | Quiet bool 142 | } 143 | 144 | // List the tasks in the stack. 145 | func StackPs(opts *StackPsOpts, stack string) (string, error) { 146 | if err := findCli(); err != nil { 147 | return "", err 148 | } 149 | return runCtrCmd( 150 | []string{"stack", "ps"}, 151 | []string{stack}, 152 | opts, 153 | 0, 154 | ) 155 | } 156 | 157 | type StackRmOpts struct { 158 | // Base exec.Cmd. 159 | Cmd *exec.Cmd 160 | 161 | // Do not wait for stack removal. 162 | Detach bool 163 | 164 | // Print usage. 165 | Help bool 166 | 167 | // Orchestrator to use (swarm|all). 168 | Orchestrator string 169 | } 170 | 171 | // Remove one or more stacks. 172 | func StackRm(opts *StackRmOpts, stack ...string) (string, error) { 173 | if err := findCli(); err != nil { 174 | return "", err 175 | } 176 | if len(stack) == 0 { 177 | return "", fmt.Errorf("stack must have at least one value") 178 | } 179 | return runCtrCmd( 180 | []string{"stack", "rm"}, 181 | stack, 182 | opts, 183 | 0, 184 | ) 185 | } 186 | 187 | type StackServicesOpts struct { 188 | // Base exec.Cmd. 189 | Cmd *exec.Cmd 190 | 191 | // Filter output based on conditions provided. 192 | Filter string 193 | 194 | // Format output using a custom template: 195 | // 'table': Print output in table format with column headers (default). 196 | // 'table TEMPLATE': Print output in table format using the given Go template. 197 | // 'json': Print in JSON format. 198 | // 'TEMPLATE': Print output using the given Go template. 199 | // Refer to https://docs.docker.com/go/formatting/ for more information about formatting output with templates. 200 | Format string 201 | 202 | // Print usage. 203 | Help bool 204 | 205 | // Orchestrator to use (swarm|all). 206 | Orchestrator string 207 | 208 | // Only display IDs. 209 | Quiet bool 210 | } 211 | 212 | // List the services in the stack. 213 | func StackServices(opts *StackServicesOpts, stack string) (string, error) { 214 | if err := findCli(); err != nil { 215 | return "", err 216 | } 217 | return runCtrCmd( 218 | []string{"stack", "services"}, 219 | []string{stack}, 220 | opts, 221 | 0, 222 | ) 223 | } 224 | -------------------------------------------------------------------------------- /swarm.go: -------------------------------------------------------------------------------- 1 | // Code generated by lesiw.io/ctrctl. DO NOT EDIT. 2 | package ctrctl 3 | 4 | import "os/exec" 5 | 6 | type SwarmCaOpts struct { 7 | // Base exec.Cmd. 8 | Cmd *exec.Cmd 9 | 10 | // Path to the PEM-formatted root CA certificate to use for the new cluster. 11 | CaCert string 12 | 13 | // Path to the PEM-formatted root CA key to use for the new cluster. 14 | CaKey string 15 | 16 | // Validity period for node certificates (ns|us|ms|s|m|h). 17 | CertExpiry string 18 | 19 | // Exit immediately instead of waiting for the root rotation to converge. 20 | Detach bool 21 | 22 | // Specifications of one or more certificate signing endpoints. 23 | ExternalCa string 24 | 25 | // Print usage. 26 | Help bool 27 | 28 | // Suppress progress output. 29 | Quiet bool 30 | 31 | // Rotate the swarm CA - if no certificate or key are provided, new ones will be generated. 32 | Rotate bool 33 | } 34 | 35 | // Display and rotate the root CA. 36 | func SwarmCa(opts *SwarmCaOpts) (string, error) { 37 | if err := findCli(); err != nil { 38 | return "", err 39 | } 40 | return runCtrCmd( 41 | []string{"swarm", "ca"}, 42 | []string{}, 43 | opts, 44 | 0, 45 | ) 46 | } 47 | 48 | type SwarmInitOpts struct { 49 | // Base exec.Cmd. 50 | Cmd *exec.Cmd 51 | 52 | // Advertised address (format: `[:port]`). 53 | AdvertiseAddr string 54 | 55 | // Enable manager autolocking (requiring an unlock key to start a stopped manager). 56 | Autolock bool 57 | 58 | // Availability of the node (`active`, `pause`, `drain`). 59 | Availability string 60 | 61 | // Validity period for node certificates (ns|us|ms|s|m|h). 62 | CertExpiry string 63 | 64 | // Address or interface to use for data path traffic (format: ``). 65 | DataPathAddr string 66 | 67 | // Port number to use for data path traffic (1024 - 49151). If no value is set or is set to 0, the default port (4789) is used. 68 | DataPathPort string 69 | 70 | // default address pool in CIDR format. 71 | DefaultAddrPool string 72 | 73 | // default address pool subnet mask length. 74 | DefaultAddrPoolMaskLength string 75 | 76 | // Dispatcher heartbeat period (ns|us|ms|s|m|h). 77 | DispatcherHeartbeat string 78 | 79 | // Specifications of one or more certificate signing endpoints. 80 | ExternalCa string 81 | 82 | // Force create a new cluster from current state. 83 | ForceNewCluster bool 84 | 85 | // Print usage. 86 | Help bool 87 | 88 | // Listen address (format: `[:port]`). 89 | ListenAddr string 90 | 91 | // Number of additional Raft snapshots to retain. 92 | MaxSnapshots string 93 | 94 | // Number of log entries between Raft snapshots. 95 | SnapshotInterval string 96 | 97 | // Task history retention limit. 98 | TaskHistoryLimit string 99 | } 100 | 101 | // Initialize a swarm. 102 | func SwarmInit(opts *SwarmInitOpts) (string, error) { 103 | if err := findCli(); err != nil { 104 | return "", err 105 | } 106 | return runCtrCmd( 107 | []string{"swarm", "init"}, 108 | []string{}, 109 | opts, 110 | 0, 111 | ) 112 | } 113 | 114 | type SwarmJoinTokenOpts struct { 115 | // Base exec.Cmd. 116 | Cmd *exec.Cmd 117 | 118 | // Print usage. 119 | Help bool 120 | 121 | // Only display token. 122 | Quiet bool 123 | 124 | // Rotate join token. 125 | Rotate bool 126 | } 127 | 128 | // Manage join tokens. 129 | func SwarmJoinToken(opts *SwarmJoinTokenOpts, WorkerManager string) (string, error) { 130 | if err := findCli(); err != nil { 131 | return "", err 132 | } 133 | return runCtrCmd( 134 | []string{"swarm", "join-token"}, 135 | []string{WorkerManager}, 136 | opts, 137 | 0, 138 | ) 139 | } 140 | 141 | type SwarmJoinOpts struct { 142 | // Base exec.Cmd. 143 | Cmd *exec.Cmd 144 | 145 | // Advertised address (format: `[:port]`). 146 | AdvertiseAddr string 147 | 148 | // Availability of the node (`active`, `pause`, `drain`). 149 | Availability string 150 | 151 | // Address or interface to use for data path traffic (format: ``). 152 | DataPathAddr string 153 | 154 | // Print usage. 155 | Help bool 156 | 157 | // Listen address (format: `[:port]`). 158 | ListenAddr string 159 | 160 | // Token for entry into the swarm. 161 | Token string 162 | } 163 | 164 | // Join a swarm as a node and/or manager. 165 | func SwarmJoin(opts *SwarmJoinOpts, hostPort string) (string, error) { 166 | if err := findCli(); err != nil { 167 | return "", err 168 | } 169 | return runCtrCmd( 170 | []string{"swarm", "join"}, 171 | []string{hostPort}, 172 | opts, 173 | 0, 174 | ) 175 | } 176 | 177 | type SwarmLeaveOpts struct { 178 | // Base exec.Cmd. 179 | Cmd *exec.Cmd 180 | 181 | // Force this node to leave the swarm, ignoring warnings. 182 | Force bool 183 | 184 | // Print usage. 185 | Help bool 186 | } 187 | 188 | // Leave the swarm. 189 | func SwarmLeave(opts *SwarmLeaveOpts) (string, error) { 190 | if err := findCli(); err != nil { 191 | return "", err 192 | } 193 | return runCtrCmd( 194 | []string{"swarm", "leave"}, 195 | []string{}, 196 | opts, 197 | 0, 198 | ) 199 | } 200 | 201 | type SwarmUnlockKeyOpts struct { 202 | // Base exec.Cmd. 203 | Cmd *exec.Cmd 204 | 205 | // Print usage. 206 | Help bool 207 | 208 | // Only display token. 209 | Quiet bool 210 | 211 | // Rotate unlock key. 212 | Rotate bool 213 | } 214 | 215 | // Manage the unlock key. 216 | func SwarmUnlockKey(opts *SwarmUnlockKeyOpts) (string, error) { 217 | if err := findCli(); err != nil { 218 | return "", err 219 | } 220 | return runCtrCmd( 221 | []string{"swarm", "unlock-key"}, 222 | []string{}, 223 | opts, 224 | 0, 225 | ) 226 | } 227 | 228 | type SwarmUnlockOpts struct { 229 | // Base exec.Cmd. 230 | Cmd *exec.Cmd 231 | 232 | // Print usage. 233 | Help bool 234 | } 235 | 236 | // Unlock swarm. 237 | func SwarmUnlock(opts *SwarmUnlockOpts) (string, error) { 238 | if err := findCli(); err != nil { 239 | return "", err 240 | } 241 | return runCtrCmd( 242 | []string{"swarm", "unlock"}, 243 | []string{}, 244 | opts, 245 | -1, 246 | ) 247 | } 248 | 249 | type SwarmUpdateOpts struct { 250 | // Base exec.Cmd. 251 | Cmd *exec.Cmd 252 | 253 | // Change manager autolocking setting (true|false). 254 | Autolock bool 255 | 256 | // Validity period for node certificates (ns|us|ms|s|m|h). 257 | CertExpiry string 258 | 259 | // Dispatcher heartbeat period (ns|us|ms|s|m|h). 260 | DispatcherHeartbeat string 261 | 262 | // Specifications of one or more certificate signing endpoints. 263 | ExternalCa string 264 | 265 | // Print usage. 266 | Help bool 267 | 268 | // Number of additional Raft snapshots to retain. 269 | MaxSnapshots string 270 | 271 | // Number of log entries between Raft snapshots. 272 | SnapshotInterval string 273 | 274 | // Task history retention limit. 275 | TaskHistoryLimit string 276 | } 277 | 278 | // Update the swarm. 279 | func SwarmUpdate(opts *SwarmUpdateOpts) (string, error) { 280 | if err := findCli(); err != nil { 281 | return "", err 282 | } 283 | return runCtrCmd( 284 | []string{"swarm", "update"}, 285 | []string{}, 286 | opts, 287 | 0, 288 | ) 289 | } 290 | -------------------------------------------------------------------------------- /system.go: -------------------------------------------------------------------------------- 1 | // Code generated by lesiw.io/ctrctl. DO NOT EDIT. 2 | package ctrctl 3 | 4 | import "os/exec" 5 | 6 | type SystemDfOpts struct { 7 | // Base exec.Cmd. 8 | Cmd *exec.Cmd 9 | 10 | // Format output using a custom template: 11 | // 'table': Print output in table format with column headers (default). 12 | // 'table TEMPLATE': Print output in table format using the given Go template. 13 | // 'json': Print in JSON format. 14 | // 'TEMPLATE': Print output using the given Go template. 15 | // Refer to https://docs.docker.com/go/formatting/ for more information about formatting output with templates. 16 | Format string 17 | 18 | // Print usage. 19 | Help bool 20 | 21 | // Show detailed information on space usage. 22 | Verbose bool 23 | } 24 | 25 | // Show docker disk usage. 26 | func SystemDf(opts *SystemDfOpts) (string, error) { 27 | if err := findCli(); err != nil { 28 | return "", err 29 | } 30 | return runCtrCmd( 31 | []string{"system", "df"}, 32 | []string{}, 33 | opts, 34 | 0, 35 | ) 36 | } 37 | 38 | type SystemDialStdioOpts struct { 39 | // Base exec.Cmd. 40 | Cmd *exec.Cmd 41 | 42 | // Print usage. 43 | Help bool 44 | } 45 | 46 | // Proxy the stdio stream to the daemon connection. Should not be invoked manually. 47 | func SystemDialStdio(opts *SystemDialStdioOpts) (string, error) { 48 | if err := findCli(); err != nil { 49 | return "", err 50 | } 51 | return runCtrCmd( 52 | []string{"system", "dial-stdio"}, 53 | []string{}, 54 | opts, 55 | -1, 56 | ) 57 | } 58 | 59 | type SystemEventsOpts struct { 60 | // Base exec.Cmd. 61 | Cmd *exec.Cmd 62 | 63 | // Filter output based on conditions provided. 64 | Filter string 65 | 66 | // Format output using a custom template: 67 | // 'json': Print in JSON format. 68 | // 'TEMPLATE': Print output using the given Go template. 69 | // Refer to https://docs.docker.com/go/formatting/ for more information about formatting output with templates. 70 | Format string 71 | 72 | // Print usage. 73 | Help bool 74 | 75 | // Show all events created since timestamp. 76 | Since string 77 | 78 | // Stream events until this timestamp. 79 | Until string 80 | } 81 | 82 | // Get real time events from the server. 83 | func SystemEvents(opts *SystemEventsOpts) (string, error) { 84 | if err := findCli(); err != nil { 85 | return "", err 86 | } 87 | return runCtrCmd( 88 | []string{"system", "events"}, 89 | []string{}, 90 | opts, 91 | 0, 92 | ) 93 | } 94 | 95 | type SystemInfoOpts struct { 96 | // Base exec.Cmd. 97 | Cmd *exec.Cmd 98 | 99 | // Format output using a custom template: 100 | // 'json': Print in JSON format. 101 | // 'TEMPLATE': Print output using the given Go template. 102 | // Refer to https://docs.docker.com/go/formatting/ for more information about formatting output with templates. 103 | Format string 104 | 105 | // Print usage. 106 | Help bool 107 | } 108 | 109 | // Display system-wide information. 110 | func SystemInfo(opts *SystemInfoOpts) (string, error) { 111 | if err := findCli(); err != nil { 112 | return "", err 113 | } 114 | return runCtrCmd( 115 | []string{"system", "info"}, 116 | []string{}, 117 | opts, 118 | 0, 119 | ) 120 | } 121 | 122 | type SystemPruneOpts struct { 123 | // Base exec.Cmd. 124 | Cmd *exec.Cmd 125 | 126 | // Remove all unused images not just dangling ones. 127 | All bool 128 | 129 | // Provide filter values (e.g. `label==`). 130 | Filter string 131 | 132 | // Do not prompt for confirmation. 133 | Force bool 134 | 135 | // Print usage. 136 | Help bool 137 | 138 | // Prune anonymous volumes. 139 | Volumes bool 140 | } 141 | 142 | // Remove unused data. 143 | func SystemPrune(opts *SystemPruneOpts) (string, error) { 144 | if err := findCli(); err != nil { 145 | return "", err 146 | } 147 | return runCtrCmd( 148 | []string{"system", "prune"}, 149 | []string{}, 150 | opts, 151 | 0, 152 | ) 153 | } 154 | -------------------------------------------------------------------------------- /trust.go: -------------------------------------------------------------------------------- 1 | // Code generated by lesiw.io/ctrctl. DO NOT EDIT. 2 | package ctrctl 3 | 4 | import ( 5 | "fmt" 6 | "os/exec" 7 | ) 8 | 9 | type TrustInspectOpts struct { 10 | // Base exec.Cmd. 11 | Cmd *exec.Cmd 12 | 13 | // Print usage. 14 | Help bool 15 | 16 | // Print the information in a human friendly format. 17 | Pretty bool 18 | } 19 | 20 | // Return low-level information about keys and signatures. 21 | func TrustInspect(opts *TrustInspectOpts, imageTag ...string) (string, error) { 22 | if err := findCli(); err != nil { 23 | return "", err 24 | } 25 | if len(imageTag) == 0 { 26 | return "", fmt.Errorf("imageTag must have at least one value") 27 | } 28 | return runCtrCmd( 29 | []string{"trust", "inspect"}, 30 | imageTag, 31 | opts, 32 | -1, 33 | ) 34 | } 35 | 36 | type TrustKeyOpts struct { 37 | // Base exec.Cmd. 38 | Cmd *exec.Cmd 39 | 40 | // Print usage. 41 | Help bool 42 | } 43 | 44 | // Manage keys for signing Docker images. 45 | func TrustKey(opts *TrustKeyOpts) (string, error) { 46 | if err := findCli(); err != nil { 47 | return "", err 48 | } 49 | return runCtrCmd( 50 | []string{"trust", "key"}, 51 | []string{}, 52 | opts, 53 | -1, 54 | ) 55 | } 56 | 57 | type TrustKeyGenerateOpts struct { 58 | // Base exec.Cmd. 59 | Cmd *exec.Cmd 60 | 61 | // Directory to generate key in, defaults to current directory. 62 | Dir string 63 | 64 | // Print usage. 65 | Help bool 66 | } 67 | 68 | // Generate and load a signing key-pair. 69 | func TrustKeyGenerate(opts *TrustKeyGenerateOpts, name string) (string, error) { 70 | if err := findCli(); err != nil { 71 | return "", err 72 | } 73 | return runCtrCmd( 74 | []string{"trust", "key", "generate"}, 75 | []string{name}, 76 | opts, 77 | -1, 78 | ) 79 | } 80 | 81 | type TrustKeyLoadOpts struct { 82 | // Base exec.Cmd. 83 | Cmd *exec.Cmd 84 | 85 | // Print usage. 86 | Help bool 87 | 88 | // Name for the loaded key. 89 | Name string 90 | } 91 | 92 | // Load a private key file for signing. 93 | func TrustKeyLoad(opts *TrustKeyLoadOpts, keyfile string) (string, error) { 94 | if err := findCli(); err != nil { 95 | return "", err 96 | } 97 | return runCtrCmd( 98 | []string{"trust", "key", "load"}, 99 | []string{keyfile}, 100 | opts, 101 | 0, 102 | ) 103 | } 104 | 105 | type TrustRevokeOpts struct { 106 | // Base exec.Cmd. 107 | Cmd *exec.Cmd 108 | 109 | // Print usage. 110 | Help bool 111 | 112 | // Do not prompt for confirmation. 113 | Yes bool 114 | } 115 | 116 | // Remove trust for an image. 117 | func TrustRevoke(opts *TrustRevokeOpts, imageTag string) (string, error) { 118 | if err := findCli(); err != nil { 119 | return "", err 120 | } 121 | return runCtrCmd( 122 | []string{"trust", "revoke"}, 123 | []string{imageTag}, 124 | opts, 125 | 0, 126 | ) 127 | } 128 | 129 | type TrustSignOpts struct { 130 | // Base exec.Cmd. 131 | Cmd *exec.Cmd 132 | 133 | // Print usage. 134 | Help bool 135 | 136 | // Sign a locally tagged image. 137 | Local bool 138 | } 139 | 140 | // Sign an image. 141 | func TrustSign(opts *TrustSignOpts, imageTag string) (string, error) { 142 | if err := findCli(); err != nil { 143 | return "", err 144 | } 145 | return runCtrCmd( 146 | []string{"trust", "sign"}, 147 | []string{imageTag}, 148 | opts, 149 | -1, 150 | ) 151 | } 152 | 153 | type TrustSignerOpts struct { 154 | // Base exec.Cmd. 155 | Cmd *exec.Cmd 156 | 157 | // Print usage. 158 | Help bool 159 | } 160 | 161 | // Manage entities who can sign Docker images. 162 | func TrustSigner(opts *TrustSignerOpts) (string, error) { 163 | if err := findCli(); err != nil { 164 | return "", err 165 | } 166 | return runCtrCmd( 167 | []string{"trust", "signer"}, 168 | []string{}, 169 | opts, 170 | -1, 171 | ) 172 | } 173 | 174 | type TrustSignerAddOpts struct { 175 | // Base exec.Cmd. 176 | Cmd *exec.Cmd 177 | 178 | // Print usage. 179 | Help bool 180 | 181 | // Path to the signer's public key file. 182 | Key []string 183 | } 184 | 185 | // Add a signer. 186 | func TrustSignerAdd(opts *TrustSignerAddOpts, name string, repository ...string) (string, error) { 187 | if err := findCli(); err != nil { 188 | return "", err 189 | } 190 | if len(repository) == 0 { 191 | return "", fmt.Errorf("repository must have at least one value") 192 | } 193 | return runCtrCmd( 194 | []string{"trust", "signer", "add"}, 195 | append([]string{name}, repository...), 196 | opts, 197 | 0, 198 | ) 199 | } 200 | 201 | type TrustSignerRemoveOpts struct { 202 | // Base exec.Cmd. 203 | Cmd *exec.Cmd 204 | 205 | // Do not prompt for confirmation before removing the most recent signer. 206 | Force bool 207 | 208 | // Print usage. 209 | Help bool 210 | } 211 | 212 | // Remove a signer. 213 | func TrustSignerRemove(opts *TrustSignerRemoveOpts, name string, repository ...string) (string, error) { 214 | if err := findCli(); err != nil { 215 | return "", err 216 | } 217 | if len(repository) == 0 { 218 | return "", fmt.Errorf("repository must have at least one value") 219 | } 220 | return runCtrCmd( 221 | []string{"trust", "signer", "remove"}, 222 | append([]string{name}, repository...), 223 | opts, 224 | 0, 225 | ) 226 | } 227 | -------------------------------------------------------------------------------- /volume.go: -------------------------------------------------------------------------------- 1 | // Code generated by lesiw.io/ctrctl. DO NOT EDIT. 2 | package ctrctl 3 | 4 | import ( 5 | "fmt" 6 | "os/exec" 7 | ) 8 | 9 | type VolumeCreateOpts struct { 10 | // Base exec.Cmd. 11 | Cmd *exec.Cmd 12 | 13 | // Cluster Volume availability (`active`, `pause`, `drain`). 14 | Availability string 15 | 16 | // Specify volume driver name. 17 | Driver string 18 | 19 | // Cluster Volume group (cluster volumes). 20 | Group string 21 | 22 | // Print usage. 23 | Help bool 24 | 25 | // Set metadata for a volume. 26 | Label []string 27 | 28 | // Minimum size of the Cluster Volume in bytes. 29 | LimitBytes string 30 | 31 | // Specify volume name. 32 | Name string 33 | 34 | // Set driver specific options. 35 | Opt string 36 | 37 | // Maximum size of the Cluster Volume in bytes. 38 | RequiredBytes string 39 | 40 | // Cluster Volume access scope (`single`, `multi`). 41 | Scope string 42 | 43 | // Cluster Volume secrets. 44 | Secret string 45 | 46 | // Cluster Volume access sharing (`none`, `readonly`, `onewriter`, `all`). 47 | Sharing string 48 | 49 | // A topology that the Cluster Volume would be preferred in. 50 | TopologyPreferred []string 51 | 52 | // A topology that the Cluster Volume must be accessible from. 53 | TopologyRequired []string 54 | 55 | // Cluster Volume access type (`mount`, `block`). 56 | Type string 57 | } 58 | 59 | // Create a volume. 60 | func VolumeCreate(opts *VolumeCreateOpts, volume string) (string, error) { 61 | if err := findCli(); err != nil { 62 | return "", err 63 | } 64 | return runCtrCmd( 65 | []string{"volume", "create"}, 66 | []string{volume}, 67 | opts, 68 | 0, 69 | ) 70 | } 71 | 72 | type VolumeInspectOpts struct { 73 | // Base exec.Cmd. 74 | Cmd *exec.Cmd 75 | 76 | // Format output using a custom template: 77 | // 'json': Print in JSON format. 78 | // 'TEMPLATE': Print output using the given Go template. 79 | // Refer to https://docs.docker.com/go/formatting/ for more information about formatting output with templates. 80 | Format string 81 | 82 | // Print usage. 83 | Help bool 84 | } 85 | 86 | // Display detailed information on one or more volumes. 87 | func VolumeInspect(opts *VolumeInspectOpts, volume ...string) (string, error) { 88 | if err := findCli(); err != nil { 89 | return "", err 90 | } 91 | if len(volume) == 0 { 92 | return "", fmt.Errorf("volume must have at least one value") 93 | } 94 | return runCtrCmd( 95 | []string{"volume", "inspect"}, 96 | volume, 97 | opts, 98 | 0, 99 | ) 100 | } 101 | 102 | type VolumeLsOpts struct { 103 | // Base exec.Cmd. 104 | Cmd *exec.Cmd 105 | 106 | // Display only cluster volumes, and use cluster volume list formatting. 107 | Cluster bool 108 | 109 | // Provide filter values (e.g. `dangling=true`). 110 | Filter string 111 | 112 | // Format output using a custom template: 113 | // 'table': Print output in table format with column headers (default). 114 | // 'table TEMPLATE': Print output in table format using the given Go template. 115 | // 'json': Print in JSON format. 116 | // 'TEMPLATE': Print output using the given Go template. 117 | // Refer to https://docs.docker.com/go/formatting/ for more information about formatting output with templates. 118 | Format string 119 | 120 | // Print usage. 121 | Help bool 122 | 123 | // Only display volume names. 124 | Quiet bool 125 | } 126 | 127 | // List volumes. 128 | func VolumeLs(opts *VolumeLsOpts) (string, error) { 129 | if err := findCli(); err != nil { 130 | return "", err 131 | } 132 | return runCtrCmd( 133 | []string{"volume", "ls"}, 134 | []string{}, 135 | opts, 136 | 0, 137 | ) 138 | } 139 | 140 | type VolumePruneOpts struct { 141 | // Base exec.Cmd. 142 | Cmd *exec.Cmd 143 | 144 | // Remove all unused volumes, not just anonymous ones. 145 | All bool 146 | 147 | // Provide filter values (e.g. `label=