17813: Upload .sif file to cache project & read it from keep
[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         // ImageLoaded determines whether the given image is already
38         // available to use without calling ImageLoad.
39         ImageLoaded(imageID string) bool
40
41         // ImageLoad loads the image from the given tarball such that
42         // it can be used to create/start a container.
43         LoadImage(filename string) error
44
45         // Wait for the container process to finish, and return its
46         // exit code. If applicable, also remove the stopped container
47         // before returning.
48         Wait(context.Context) (int, error)
49
50         // Create a container, but don't start it yet.
51         Create(containerSpec) error
52
53         // Start the container
54         Start() error
55
56         // CID the container will belong to
57         CgroupID() string
58
59         // Stop the container immediately
60         Stop() error
61
62         // Release resources (temp dirs, stopped containers)
63         Close()
64
65         // Give the executor access to arvados client & container info
66         SetArvadoClient(containerClient *arvados.Client, keepClient IKeepClient, container arvados.Container, keepMount string)
67 }