(containerConfig *container.Config, addNewLineAfterPull bool, copyToPaths []dockerCopyToPath, copyFromPaths []dockerCopyFromPath)
| 53 | } |
| 54 | |
| 55 | func runManager(containerConfig *container.Config, addNewLineAfterPull bool, copyToPaths []dockerCopyToPath, copyFromPaths []dockerCopyFromPath) (string, *int, error) { |
| 56 | containerConfig.Env = append(containerConfig.Env, "CORTEX_CLI_VERSION="+consts.CortexVersion) |
| 57 | |
| 58 | // Add a slight delay before running the command to ensure logs don't start until after the container is attached |
| 59 | containerConfig.Cmd[0] = "sleep 0.1 && /root/check_cortex_version.sh && " + containerConfig.Cmd[0] |
| 60 | |
| 61 | dockerClient, err := docker.GetDockerClient() |
| 62 | if err != nil { |
| 63 | return "", nil, err |
| 64 | } |
| 65 | |
| 66 | pulledImage, err := docker.PullImage(containerConfig.Image, docker.NoAuth, docker.PrintDots) |
| 67 | if err != nil { |
| 68 | if strings.Contains(err.Error(), "auth") { |
| 69 | err = errors.Append(err, fmt.Sprintf("\n\nif your manager image is stored in a private repository: run `docker login` (if you haven't already), download your image with `docker pull %s`, and try this command again)", containerConfig.Image)) |
| 70 | } |
| 71 | return "", nil, err |
| 72 | } |
| 73 | |
| 74 | if pulledImage && addNewLineAfterPull { |
| 75 | fmt.Println() |
| 76 | } |
| 77 | |
| 78 | containerInfo, err := dockerClient.ContainerCreate(context.Background(), containerConfig, nil, nil, "") |
| 79 | if err != nil { |
| 80 | return "", nil, docker.WrapDockerError(err) |
| 81 | } |
| 82 | |
| 83 | removeContainer := func() { |
| 84 | _ = dockerClient.ContainerRemove(context.Background(), containerInfo.ID, dockertypes.ContainerRemoveOptions{ |
| 85 | RemoveVolumes: true, |
| 86 | Force: true, |
| 87 | }) |
| 88 | } |
| 89 | |
| 90 | defer removeContainer() |
| 91 | |
| 92 | // Make sure to remove container immediately on ctrl+c |
| 93 | c := make(chan os.Signal, 1) |
| 94 | signal.Notify(c, os.Interrupt, syscall.SIGTERM) |
| 95 | caughtCtrlC := false |
| 96 | |
| 97 | routines.RunWithPanicHandler(func() { |
| 98 | <-c |
| 99 | caughtCtrlC = true |
| 100 | removeContainer() |
| 101 | exit.Error(ErrorDockerCtrlC()) |
| 102 | }, false) |
| 103 | |
| 104 | for _, copyPath := range copyToPaths { |
| 105 | err = docker.CopyToContainer(containerInfo.ID, copyPath.input, copyPath.containerPath) |
| 106 | if err != nil { |
| 107 | return "", nil, err |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | err = dockerClient.ContainerStart(context.Background(), containerInfo.ID, dockertypes.ContainerStartOptions{}) |
| 112 | if err != nil { |
no test coverage detected