Merge branch '17465-pysdk-storage-classes-support'
[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         "golang.org/x/net/context"
10 )
11
12 type bindmount struct {
13         HostPath string
14         ReadOnly bool
15 }
16
17 type containerSpec struct {
18         Image         string
19         VCPUs         int
20         RAM           int64
21         WorkingDir    string
22         Env           map[string]string
23         BindMounts    map[string]bindmount
24         Command       []string
25         EnableNetwork bool
26         NetworkMode   string // docker network mode, normally "default"
27         CgroupParent  string
28         Stdin         io.ReadCloser
29         Stdout        io.WriteCloser
30         Stderr        io.WriteCloser
31 }
32
33 // containerExecutor is an interface to a container runtime
34 // (docker/singularity).
35 type containerExecutor interface {
36         // ImageLoaded determines whether the given image is already
37         // available to use without calling ImageLoad.
38         ImageLoaded(imageID string) bool
39
40         // ImageLoad loads the image from the given tarball such that
41         // it can be used to create/start a container.
42         LoadImage(filename string) error
43
44         // Wait for the container process to finish, and return its
45         // exit code. If applicable, also remove the stopped container
46         // before returning.
47         Wait(context.Context) (int, error)
48
49         // Create a container, but don't start it yet.
50         Create(containerSpec) error
51
52         // Start the container
53         Start() error
54
55         // CID the container will belong to
56         CgroupID() string
57
58         // Stop the container immediately
59         Stop() error
60
61         // Release resources (temp dirs, stopped containers)
62         Close()
63 }