This repository was archived by the owner on Jan 27, 2023. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathrun.py
More file actions
260 lines (250 loc) · 11 KB
/
Copy pathrun.py
File metadata and controls
260 lines (250 loc) · 11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
# Copyright 2018 Spotify AB
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import argparse
import sys
from ..docker_interface import build_docker_run_command
from .. import util
from .base import Plugin, ExecutePlugin
class RunPlugin(ExecutePlugin):
"""
Run a command inside a docker container.
"""
COMMANDS = ['run']
ORDER = 1000
build_command = staticmethod(build_docker_run_command)
class RunConfigurationPlugin(Plugin):
"""
Configure how to run a command inside a docker container.
"""
COMMANDS = ['run']
ORDER = 950
SCHEMA = {
"properties": {
"run": {
"properties": {
"image": {
"type": "string",
"description": "Image to derive the container from.",
"default": "#{/build/tag}"
},
"env": {
"type": "object",
"description": "Set environment variables (use `null` to forward environment variables).",
"additionalProperties": {
"type": [
"string",
"null"
]
}
},
"env-file": {
"type": "array",
"description": "Read in a file of environment variables.",
"items": {
"type": "string"
}
},
"mount": {
"type": "array",
"description": "Attach a filesystem mount to the container.",
"items": {
"type": "object",
"properties": {
"type": {
"type": "string",
"enum": [
"bind",
"tmpfs",
"volume"
]
},
"source": {
"type": "string",
"description": "Volume name or path on the host."
},
"destination": {
"type": "string",
"description": "Absolute mount path in the container."
},
"readonly": {
"type": "boolean",
"description": "Whether to mount the volume read-only."
}
},
"required": [
"type",
"destination"
],
"additionalProperties": False
}
},
"publish": {
"type": "array",
"description": "Publish a container's port(s), or range(s) of ports, to the host.",
"items": {
"type": "object",
"properties": {
"ip": {
"type": "string",
"description": ""
},
"host": {
"anyOf": [
{
"type": "number"
},
{
"type": "string",
"pattern": "\\d+-\\d+"
}
],
"description": "Port (e.g. `8000`) or range of ports (e.g. `8000-8100`) on the host."
},
"container": {
"anyOf": [
{
"type": "number"
},
{
"type": "string",
"pattern": "\\d+-\\d+"
}
],
"description": "Port (e.g. `8000`) or range of ports (e.g. `8000-8100`) on the container."
}
},
"required": [
"container"
],
"additionalProperties": False
}
},
"runtime": {
"type": "string",
"description": "Runtime to use for this container."
},
"tmpfs": {
"type": "array",
"description": "Mount a tmpfs directory",
"items": {
"type": "object",
"properties": {
"destination": {
"type": "string",
"description": "Absolute mount path in the container."
},
"options": {
"type": "array",
"description": "Mount options for the temporary file system.",
"items": {
"type": "string"
}
},
"size": {
"type": "integer",
"description": "Size of the tmpfs mount in bytes."
},
"mode": {
"type": "integer",
"description": "File mode of the tmpfs in octal."
}
},
"required": [
"destination"
],
"additionalProperties": False
}
},
"cmd": {
"type": "array",
"description": "Command to execute inside the container.",
"items": {
"type": "string"
}
},
"tty": {
"type": "boolean",
"description": "Allocate a pseudo-TTY"
},
"cpu-shares": {
"type": "integer",
"description": "CPU shares (relative weight)",
"minimum": 0,
"maximum": 1024
},
"name": {
"type": "string",
"description": "Assign a name to the container"
},
"network": {
"type": "string",
"description": "Connect a container to a network (default \"default\")"
},
"label": {
"type": "array",
"description": "Set meta data on a container"
},
"rm": {
"type": "boolean",
"description": "Automatically remove the container when it exits",
"default": True
},
"privileged": {
"type": "boolean",
"description": "Give extended privileges to this container",
"default": False
},
"memory": {
"type": "string",
"description": "Memory limit"
},
"interactive": {
"type": "boolean",
"description": "Keep STDIN open even if not attached"
},
"entrypoint": {
"type": "string",
"description": "Overwrite the default ENTRYPOINT of the image"
},
"workdir": {
"type": "string",
"description": "Working directory inside the container"
},
"user": {
"type": "string",
"description": "Username or UID (format: <name|uid>[:<group|gid>])"
},
"group-add": {
"type": "array",
"description": "Additional groups to run as.",
"items": {
"type": "string"
}
},
"gpus": {
"type": "string",
"description": "GPU devices to add to the container (‘all’ to pass all GPUs)",
}
},
"additionalProperties": False
}
},
"additionalProperties": False
}
def add_arguments(self, parser):
super(RunConfigurationPlugin, self).add_arguments(parser)
self.add_argument(parser, '/run/cmd', name='cmd', nargs=argparse.REMAINDER, type=None)
def apply(self, configuration, schema, args):
super(RunConfigurationPlugin, self).apply(configuration, schema, args)
# Set some sensible defaults (could also be published as variables)
util.set_default(configuration, '/run/tty', sys.stdout.isatty())
util.set_default(configuration, '/run/interactive', sys.stdout.isatty())
return configuration