Quellcode durchsuchen

Return ContainerExecCreateResponse from container exec start API endpoint, Fixes #11613

Signed-off-by: Antonio Murdaca <me@runcom.ninja>
Antonio Murdaca vor 10 Jahren
Ursprung
Commit
0c3d2f6f96
3 geänderte Dateien mit 28 neuen und 7 gelöschten Zeilen
  1. 6 3
      api/client/commands.go
  2. 13 4
      api/server/server.go
  3. 9 0
      api/types/types.go

+ 6 - 3
api/client/commands.go

@@ -2677,12 +2677,15 @@ func (cli *DockerCli) CmdExec(args ...string) error {
 		return err
 		return err
 	}
 	}
 
 
-	var execResult engine.Env
-	if err := execResult.Decode(stream); err != nil {
+	var response types.ContainerExecCreateResponse
+	if err := json.NewDecoder(stream).Decode(&response); err != nil {
 		return err
 		return err
 	}
 	}
+	for _, warning := range response.Warnings {
+		fmt.Fprintf(cli.err, "WARNING: %s\n", warning)
+	}
 
 
-	execID := execResult.Get("Id")
+	execID := response.ID
 
 
 	if execID == "" {
 	if execID == "" {
 		fmt.Fprintf(cli.out, "exec ID empty")
 		fmt.Fprintf(cli.out, "exec ID empty")

+ 13 - 4
api/server/server.go

@@ -1155,10 +1155,11 @@ func postContainerExecCreate(eng *engine.Engine, version version.Version, w http
 		return nil
 		return nil
 	}
 	}
 	var (
 	var (
-		out          engine.Env
 		name         = vars["name"]
 		name         = vars["name"]
 		job          = eng.Job("execCreate", name)
 		job          = eng.Job("execCreate", name)
 		stdoutBuffer = bytes.NewBuffer(nil)
 		stdoutBuffer = bytes.NewBuffer(nil)
+		outWarnings  []string
+		warnings     = bytes.NewBuffer(nil)
 	)
 	)
 
 
 	if err := job.DecodeEnv(r.Body); err != nil {
 	if err := job.DecodeEnv(r.Body); err != nil {
@@ -1166,15 +1167,23 @@ func postContainerExecCreate(eng *engine.Engine, version version.Version, w http
 	}
 	}
 
 
 	job.Stdout.Add(stdoutBuffer)
 	job.Stdout.Add(stdoutBuffer)
+	// Read warnings from stderr
+	job.Stderr.Add(warnings)
 	// Register an instance of Exec in container.
 	// Register an instance of Exec in container.
 	if err := job.Run(); err != nil {
 	if err := job.Run(); err != nil {
 		fmt.Fprintf(os.Stderr, "Error setting up exec command in container %s: %s\n", name, err)
 		fmt.Fprintf(os.Stderr, "Error setting up exec command in container %s: %s\n", name, err)
 		return err
 		return err
 	}
 	}
-	// Return the ID
-	out.Set("Id", engine.Tail(stdoutBuffer, 1))
+	// Parse warnings from stderr
+	scanner := bufio.NewScanner(warnings)
+	for scanner.Scan() {
+		outWarnings = append(outWarnings, scanner.Text())
+	}
 
 
-	return writeJSONEnv(w, http.StatusCreated, out)
+	return writeJSON(w, http.StatusCreated, &types.ContainerExecCreateResponse{
+		ID:       engine.Tail(stdoutBuffer, 1),
+		Warnings: outWarnings,
+	})
 }
 }
 
 
 // TODO(vishh): Refactor the code to avoid having to specify stream config as part of both create and start.
 // TODO(vishh): Refactor the code to avoid having to specify stream config as part of both create and start.

+ 9 - 0
api/types/types.go

@@ -9,3 +9,12 @@ type ContainerCreateResponse struct {
 	// Warnings are any warnings encountered during the creation of the container.
 	// Warnings are any warnings encountered during the creation of the container.
 	Warnings []string `json:"Warnings"`
 	Warnings []string `json:"Warnings"`
 }
 }
+
+// POST /containers/{name:.*}/exec
+type ContainerExecCreateResponse struct {
+	// ID is the exec ID.
+	ID string `json:"Id"`
+
+	// Warnings are any warnings encountered during the execution of the command.
+	Warnings []string `json:"Warnings"`
+}