X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/64c516079154f73da3f2a33a957fa8ae8eb23749..5ef89a24d5fa8bc6926a433e22360a09fdb3154d:/lib/crunchrun/docker.go diff --git a/lib/crunchrun/docker.go b/lib/crunchrun/docker.go index a39b754b3d..10a2dd38e8 100644 --- a/lib/crunchrun/docker.go +++ b/lib/crunchrun/docker.go @@ -11,6 +11,7 @@ import ( "strings" "time" + "git.arvados.org/arvados.git/sdk/go/arvados" dockertypes "github.com/docker/docker/api/types" dockercontainer "github.com/docker/docker/api/types/container" dockerclient "github.com/docker/docker/client" @@ -45,12 +46,16 @@ func newDockerExecutor(containerUUID string, logf func(string, ...interface{}), }, err } -func (e *dockerExecutor) ImageLoaded(imageID string) bool { +func (e *dockerExecutor) LoadImage(imageID string, container arvados.Container, arvMountPoint string, + containerClient *arvados.Client, keepClient IKeepClient) error { _, _, err := e.dockerclient.ImageInspectWithRaw(context.TODO(), imageID) - return err == nil -} + if err == nil { + // already loaded + return nil + } + + filename := arvMountPoint + "/by_id/" + container.ContainerImage + "/" + imageID + ".tar" -func (e *dockerExecutor) LoadImage(filename string) error { f, err := os.Open(filename) if err != nil { return err @@ -186,7 +191,7 @@ func (e *dockerExecutor) Wait(ctx context.Context) (int, error) { } } -func (e *dockerExecutor) startIO(stdin io.ReadCloser, stdout, stderr io.WriteCloser) error { +func (e *dockerExecutor) startIO(stdin io.Reader, stdout, stderr io.Writer) error { resp, err := e.dockerclient.ContainerAttach(context.TODO(), e.containerID, dockertypes.ContainerAttachOptions{ Stream: true, Stdin: stdin != nil, @@ -213,8 +218,7 @@ func (e *dockerExecutor) startIO(stdin io.ReadCloser, stdout, stderr io.WriteClo return nil } -func (e *dockerExecutor) handleStdin(stdin io.ReadCloser, conn io.Writer, closeConn func() error) error { - defer stdin.Close() +func (e *dockerExecutor) handleStdin(stdin io.Reader, conn io.Writer, closeConn func() error) error { defer closeConn() _, err := io.Copy(conn, stdin) if err != nil { @@ -225,7 +229,7 @@ func (e *dockerExecutor) handleStdin(stdin io.ReadCloser, conn io.Writer, closeC // Handle docker log protocol; see // https://docs.docker.com/engine/reference/api/docker_remote_api_v1.15/#attach-to-a-container -func (e *dockerExecutor) handleStdoutStderr(stdout, stderr io.WriteCloser, reader io.Reader) error { +func (e *dockerExecutor) handleStdoutStderr(stdout, stderr io.Writer, reader io.Reader) error { header := make([]byte, 8) var err error for err == nil { @@ -247,14 +251,6 @@ func (e *dockerExecutor) handleStdoutStderr(stdout, stderr io.WriteCloser, reade if err != nil { return fmt.Errorf("error copying stdout/stderr from docker: %v", err) } - err = stdout.Close() - if err != nil { - return fmt.Errorf("error writing stdout: close: %v", err) - } - err = stderr.Close() - if err != nil { - return fmt.Errorf("error writing stderr: close: %v", err) - } return nil }