GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — cli/cmd/docker.go at main · PastureStack/cli Expand file tree/ Copy pathdocker.goMore file actions 138 lines (114 loc) · 3.09 KB / Copy pathdocker.goFile metadata and controls138 lines (114 loc) · 3.09 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 package cmd import ( "fmt" "io" "os" "os/exec" "os/signal" "strconv" "strings" cli "github.com/PastureStack/cli/internal/legacycli" "github.com/PastureStack/cli/internal/rancherclient/v2" "github.com/sirupsen/logrus" ) func DockerCommand() cli.Command { return cli.Command{ Name: "docker", Usage: "Run docker CLI on a host", Description: "\nUses $PLATFORM_DOCKER_HOST to run Docker commands. Use `--host <hostID>` or `--host <hostName>` to select a different host.\n\nExample:\n\t$ pasturestack --host 1h1 docker ps\n", Action: hostDocker, Flags: []cli.Flag{ cli.BoolFlag{ Name: "help-docker", Usage: "Display the 'docker --help'", }, }, SkipFlagParsing: true, } } func hostDocker(ctx *cli.Context) error { return processExitCode(doDocker(ctx)) } func doDocker(ctx *cli.Context) error { args := ctx.Args() if len(args) > 0 && (args[0] == "-h" || args[0] == "--help") { return cli.ShowCommandHelp(ctx, "docker") } if len(args) > 0 && args[0] == "--help-docker" { return runDockerHelp("") } hostname := ctx.GlobalString("host") if hostname == "" { return fmt.Errorf("--host is required") } c, err := GetClient(ctx) if err != nil { return err } return runDocker(hostname, c, args) } func runDockerCommand(hostname string, c *client.RancherClient, command string, args []string) error { return runDocker(hostname, c, append([]string{command}, args...)) } func runDocker(hostname string, c *client.RancherClient, args []string) error { return runDockerWithOutput(hostname, c, args, os.Stdout, os.Stderr) } func determineAPIVersion(host *client.Host) string { version := host.Labels["io.rancher.host.docker_version"] parts := strings.Split(fmt.Sprint(version), ".") if len(parts) != 2 { return "" } num, err := strconv.Atoi(parts[1]) if err != nil { return "" } return fmt.Sprintf("1.%d", num+12) } func runDockerWithOutput(hostname string, c *client.RancherClient, args []string, out, outErr io.Writer) error { resource, err := Lookup(c, hostname, "host") if err != nil { return err } host, err := c.Host.ById(resource.Id) if err != nil { return err } state := getHostState(host) if state != "active" && state != "inactive" && state != "disconnected" { return fmt.Errorf("Can not contact host %s in state %s", hostname, state) } apiVersion := determineAPIVersion(host) dockerHost, proxy, err := getDockerHost(c, host.Id) if err != nil { return err } if err := proxy.Listen(); err != nil { return err } go func() { logrus.Fatal(proxy.Serve()) }() var cmd *exec.Cmd if len(args) > 0 && args[0] == "--" { if len(args) > 1 { cmd = exec.Command(args[1], args[2:]...) } else { cmd = exec.Command(os.Getenv("SHELL")) } cmd.Env = append(os.Environ(), "debian_chroot=docker:"+hostname) } else { cmd = exec.Command("docker", args...) cmd.Env = os.Environ() } cmd.Env = append(cmd.Env, "DOCKER_HOST="+dockerHost) if apiVersion != "" { cmd.Env = append(cmd.Env, "DOCKER_API_VERSION="+apiVersion) } cmd.Stdin = os.Stdin cmd.Stdout = out cmd.Stderr = outErr signal.Ignore(os.Interrupt) return cmd.Run() } |
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |