1
1
#! /usr/bin/env python
2
-
2
+ import datetime
3
3
import sys , argparse , pyaml , docker
4
4
from collections import OrderedDict
5
5
@@ -26,7 +26,21 @@ def render(struct, args, networks):
26
26
pyaml .p (OrderedDict (struct ))
27
27
else :
28
28
pyaml .p (OrderedDict ({'version' : '"3"' , 'services' : struct , 'networks' : networks }))
29
-
29
+
30
+
31
+ def is_date_or_time (s : str ):
32
+ for parse_func in [datetime .date .fromisoformat , datetime .datetime .fromisoformat ]:
33
+ try :
34
+ parse_func (s .rstrip ('Z' ))
35
+ return True
36
+ except ValueError :
37
+ pass
38
+ return False
39
+
40
+
41
+ def fix_label (label : str ):
42
+ return f"'{ label } '" if is_date_or_time (label ) else label
43
+
30
44
31
45
def generate (cname ):
32
46
c = docker .from_env ()
@@ -57,7 +71,7 @@ def generate(cname):
57
71
'environment' : cattrs ['Config' ]['Env' ],
58
72
'extra_hosts' : cattrs ['HostConfig' ]['ExtraHosts' ],
59
73
'image' : cattrs ['Config' ]['Image' ],
60
- 'labels' : cattrs ['Config' ]['Labels' ],
74
+ 'labels' : { label : fix_label ( value ) for label , value in cattrs ['Config' ]['Labels' ]. items ()} ,
61
75
'links' : cattrs ['HostConfig' ]['Links' ],
62
76
#'log_driver': cattrs['HostConfig']['LogConfig']['Type'],
63
77
#'log_opt': cattrs['HostConfig']['LogConfig']['Config'],
0 commit comments