testing out moving off bash
Signed-off-by: James Strong <james.strong@chainguard.dev>
This commit is contained in:
parent
5bfc56618e
commit
3a8cccc469
5 changed files with 233 additions and 0 deletions
46
ingressctl/cmd/docker.go
Normal file
46
ingressctl/cmd/docker.go
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
package cmd
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/client"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var dockerCmd = &cobra.Command{
|
||||
Use: "docker",
|
||||
Short: "Access to docker client",
|
||||
}
|
||||
|
||||
var dockerListCmd = &cobra.Command{
|
||||
Use: "list",
|
||||
Short: "list out all docker images",
|
||||
Long: "List out all docker images available to us",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
dockerList()
|
||||
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(dockerCmd)
|
||||
dockerCmd.AddCommand(dockerListCmd)
|
||||
}
|
||||
|
||||
func dockerList() {
|
||||
cli, err := client.NewClientWithOpts(client.FromEnv)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
containers, err := cli.ContainerList(context.Background(), types.ContainerListOptions{})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
for _, container := range containers {
|
||||
fmt.Printf("%s %s\n", container.ID[:10], container.Image)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue