|
@@ -7,6 +7,11 @@ and reconstructed by looking at the `docker inspect` output.
|
7
|
7
|
Each function named `handle_*` handles one configuration option,
|
8
|
8
|
reading the relevant information from the inspect output and adding
|
9
|
9
|
the relevant command line flags to the config.
|
|
10
|
+
|
|
11
|
+Each function named `modify_*` allows the user to modify the
|
|
12
|
+configuration in some manner. Modify functions are called twice:
|
|
13
|
+once with an ArgumentParser, and subsequently with the parsed
|
|
14
|
+arguments and the container object.
|
10
|
15
|
"""
|
11
|
16
|
|
12
|
17
|
import argparse
|
|
@@ -205,6 +210,15 @@ def handle_volumes_from(container):
|
205
|
210
|
lambda c: c['HostConfig']['VolumesFrom'])
|
206
|
211
|
|
207
|
212
|
|
|
213
|
+def modify_image(parser=None, args=None, container=None):
|
|
214
|
+ """Allows the image (name, version, etc) to be modified in one go."""
|
|
215
|
+ if parser:
|
|
216
|
+ parser.add_argument('--image',
|
|
217
|
+ help='Image to use in place of the original')
|
|
218
|
+ elif args.image:
|
|
219
|
+ container.image = args.image
|
|
220
|
+
|
|
221
|
+
|
208
|
222
|
def functions():
|
209
|
223
|
"""Lists all functions defined in this module.
|
210
|
224
|
|
|
@@ -226,6 +240,15 @@ def handlers():
|
226
|
240
|
return [func for (name, func) in functions() if name.startswith('handle_')]
|
227
|
241
|
|
228
|
242
|
|
|
243
|
+def modifiers():
|
|
244
|
+ """Lists all modifiers defined in this module.
|
|
245
|
+
|
|
246
|
+ Returns:
|
|
247
|
+ list of function: All modifiers (modify_* funcs) in this module.
|
|
248
|
+ """
|
|
249
|
+ return [func for (name, func) in functions() if name.startswith('modify_')]
|
|
250
|
+
|
|
251
|
+
|
229
|
252
|
def main():
|
230
|
253
|
"""Script entry point."""
|
231
|
254
|
parser = argparse.ArgumentParser(description='Reruns docker containers ' \
|
|
@@ -234,6 +257,11 @@ def main():
|
234
|
257
|
parser.add_argument('-d', '--dry-run', action='store_true',
|
235
|
258
|
help='Don\'t actually re-run the container, just ' \
|
236
|
259
|
'print what would happen.')
|
|
260
|
+
|
|
261
|
+ mods = modifiers()
|
|
262
|
+ for mod in mods:
|
|
263
|
+ mod(parser=parser)
|
|
264
|
+
|
237
|
265
|
args = parser.parse_args()
|
238
|
266
|
container_info = docker_inspect(args.container, 'container')
|
239
|
267
|
image_info = docker_inspect(container_info['Config']['Image'], 'image')
|
|
@@ -242,6 +270,9 @@ def main():
|
242
|
270
|
for handler in handlers():
|
243
|
271
|
handler(container)
|
244
|
272
|
|
|
273
|
+ for mod in mods:
|
|
274
|
+ mod(args=args, container=container)
|
|
275
|
+
|
245
|
276
|
commands = [
|
246
|
277
|
['docker', 'stop', args.container],
|
247
|
278
|
['docker', 'rm', args.container],
|