17813: Refactor singularity image loading / caching / conversion
[arvados.git] / lib / crunchrun / executor.go
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4 package crunchrun
5
6 import (
7         "io"
8
9         "git.arvados.org/arvados.git/sdk/go/arvados"
10         "golang.org/x/net/context"
11 )
12
13 type bindmount struct {
14         HostPath string
15         ReadOnly bool
16 }
17
18 type containerSpec struct {
19         Image         string
20         VCPUs         int
21         RAM           int64
22         WorkingDir    string
23         Env           map[string]string
24         BindMounts    map[string]bindmount
25         Command       []string
26         EnableNetwork bool
27         NetworkMode   string // docker network mode, normally "default"
28         CgroupParent  string
29         Stdin         io.Reader
30         Stdout        io.Writer
31         Stderr        io.Writer
32 }
33
34 // containerExecutor is an interface to a container runtime
35 // (docker/singularity).
36 type containerExecutor interface {
37         // ImageLoad loads the image from the given tarball such that
38         // it can be used to create/start a container.
39         LoadImage(imageID string, container arvados.Container, keepMount string,
40                 containerClient *arvados.Client, keepClient IKeepClient) error
41
42         // Wait for the container process to finish, and return its
43         // exit code. If applicable, also remove the stopped container
44         // before returning.
45         Wait(context.Context) (int, error)
46
47         // Create a container, but don't start it yet.
48         Create(containerSpec) error
49
50         // Start the container
51         Start() error
52
53         // CID the container will belong to
54         CgroupID() string
55
56         // Stop the container immediately
57         Stop() error
58
59         // Release resources (temp dirs, stopped containers)
60         Close()
61 }