// getMyDockerID returns id of the current container the process is running within, if any func getMyDockerID() (string, error) { if _, err := os.Stat("/proc/self/cgroup"); os.IsNotExist(err) { return "", nil } output, exitStatus, err := util.ExecPipe(&util.Cmd{ Args: []string{"/bin/bash", "-c", `cat /proc/self/cgroup | grep "docker" | sed s/\\//\\n/g | tail -1`}, }) if err != nil { return "", err } if exitStatus != 0 { return "", fmt.Errorf("Failed to obtain docker id due error: %s", output) } return strings.Trim(output, "\n"), nil }
func doGitCmd(dir string, args []string) (out string, err error) { gitBinary, err := exec.LookPath("git") if err != nil { return "", err } cmd := &util.Cmd{ Args: append([]string{gitBinary}, args...), Dir: dir, } out, exitCode, err := util.ExecPipe(cmd) if err != nil { return "", err } if exitCode != 0 { if strings.Contains(out, "Not a git repository") { return "", &ErrNotGitRepo{cmd, dir} } return "", fmt.Errorf("Cmd `%s` exited with code: %d, output: %s", cmd, exitCode, out) } return strings.Trim(out, "\n"), nil }