dfbar 0.2.2__tar.gz → 0.3.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {dfbar-0.2.2/src/dfbar.egg-info → dfbar-0.3.0}/PKG-INFO +1 -1
- {dfbar-0.2.2 → dfbar-0.3.0}/src/dfbar/__init__.py +1 -0
- dfbar-0.3.0/src/dfbar/__main__.py +5 -0
- {dfbar-0.2.2 → dfbar-0.3.0}/src/dfbar/dfbar.py +37 -7
- {dfbar-0.2.2 → dfbar-0.3.0/src/dfbar.egg-info}/PKG-INFO +1 -1
- dfbar-0.2.2/src/dfbar/__main__.py +0 -11
- {dfbar-0.2.2 → dfbar-0.3.0}/LICENSE +0 -0
- {dfbar-0.2.2 → dfbar-0.3.0}/README.md +0 -0
- {dfbar-0.2.2 → dfbar-0.3.0}/pyproject.toml +0 -0
- {dfbar-0.2.2 → dfbar-0.3.0}/setup.cfg +0 -0
- {dfbar-0.2.2 → dfbar-0.3.0}/setup.py +0 -0
- {dfbar-0.2.2 → dfbar-0.3.0}/src/dfbar.egg-info/SOURCES.txt +0 -0
- {dfbar-0.2.2 → dfbar-0.3.0}/src/dfbar.egg-info/dependency_links.txt +0 -0
- {dfbar-0.2.2 → dfbar-0.3.0}/src/dfbar.egg-info/entry_points.txt +0 -0
- {dfbar-0.2.2 → dfbar-0.3.0}/src/dfbar.egg-info/top_level.txt +0 -0
|
@@ -23,7 +23,8 @@ class Logger:
|
|
|
23
23
|
print('WARNING: ' + message)
|
|
24
24
|
|
|
25
25
|
def process_docker_spec(spec, dockerfile=None, verbose=False,
|
|
26
|
-
run=True,
|
|
26
|
+
run=True, allow_shell=False, ignore_missing=False,
|
|
27
|
+
mode=None, custom_opts=[]):
|
|
27
28
|
logger = Logger(verbose)
|
|
28
29
|
|
|
29
30
|
# Make sure we have a valid spec
|
|
@@ -61,6 +62,7 @@ def process_docker_spec(spec, dockerfile=None, verbose=False,
|
|
|
61
62
|
build_opts = ""
|
|
62
63
|
run_opts = ""
|
|
63
64
|
image_opts = ""
|
|
65
|
+
shell = False
|
|
64
66
|
|
|
65
67
|
# Read the dockerfile for processing
|
|
66
68
|
lines = []
|
|
@@ -91,6 +93,14 @@ def process_docker_spec(spec, dockerfile=None, verbose=False,
|
|
|
91
93
|
image_opts = "%s %s" % (image_opts, match.groups()[0])
|
|
92
94
|
continue
|
|
93
95
|
|
|
96
|
+
match = re.search('^\s*#\s*USE_SHELL\s*(.*)', line)
|
|
97
|
+
if match is not None:
|
|
98
|
+
if not allow_shell:
|
|
99
|
+
raise Exception('Dockerfile requires shell parsing, but shell parsing not allowed')
|
|
100
|
+
|
|
101
|
+
shell = True
|
|
102
|
+
continue
|
|
103
|
+
|
|
94
104
|
if mode is not None and mode != '':
|
|
95
105
|
match = re.search('^\s*#\s*' + mode + '_BUILD_OPTS\s*(.*)', line)
|
|
96
106
|
if match is not None:
|
|
@@ -110,12 +120,14 @@ def process_docker_spec(spec, dockerfile=None, verbose=False,
|
|
|
110
120
|
logger.log_verbose('Build Options: %s' % build_opts)
|
|
111
121
|
logger.log_verbose('Run Options: %s' % run_opts)
|
|
112
122
|
logger.log_verbose('Image Options: %s' % image_opts)
|
|
123
|
+
logger.log_verbose('Custom Options: %s' % custom_opts)
|
|
113
124
|
|
|
114
125
|
# Configure environment variables for use by docker commands
|
|
115
126
|
os.environ['DFBAR_DOCKER_DIR'] = spec
|
|
116
127
|
os.environ['DFBAR_DOCKERFILE'] = dockerfile
|
|
117
128
|
os.environ['DFBAR_USER_ID'] = str(os.getuid())
|
|
118
129
|
os.environ['DFBAR_GROUP_ID'] = str(os.getgid())
|
|
130
|
+
os.environ['DFBAR_CWD'] = os.getcwd()
|
|
119
131
|
|
|
120
132
|
# Perform a build of the Dockerfile
|
|
121
133
|
build_cmd = ('docker build -f %s -q %s ' % (dockerfile, spec)) + build_opts
|
|
@@ -144,9 +156,12 @@ def process_docker_spec(spec, dockerfile=None, verbose=False,
|
|
|
144
156
|
run_cmd = 'docker run --rm %s -t %s %s %s ' % (interactive_arg, run_opts, docker_image, image_opts)
|
|
145
157
|
if shell:
|
|
146
158
|
call_args = run_cmd
|
|
159
|
+
for opt in custom_opts:
|
|
160
|
+
call_args = '%s "%s"' % (call_args, opt.replace('"', '\\"'))
|
|
147
161
|
else:
|
|
148
162
|
call_args = shlex.split(run_cmd)
|
|
149
163
|
call_args = [os.path.expandvars(x) for x in call_args]
|
|
164
|
+
call_args = call_args + custom_opts
|
|
150
165
|
|
|
151
166
|
logger.log_verbose('Run call args: %s' % call_args)
|
|
152
167
|
|
|
@@ -195,8 +210,8 @@ def main():
|
|
|
195
210
|
|
|
196
211
|
parser.add_argument('-s',
|
|
197
212
|
action='store_true',
|
|
198
|
-
dest='
|
|
199
|
-
help='
|
|
213
|
+
dest='allow_shell',
|
|
214
|
+
help='Allow use of the shell to execute the build, run and image options. This can be dangerous if the Dockerfile is from an untrusted source')
|
|
200
215
|
|
|
201
216
|
parser.add_argument('-m',
|
|
202
217
|
action='store',
|
|
@@ -208,6 +223,11 @@ def main():
|
|
|
208
223
|
action='store',
|
|
209
224
|
help='The Dockerfile directory, Dockerfile, base directory or image profile, depending on options. Default to determine Dockerfile directory or Dockerfile')
|
|
210
225
|
|
|
226
|
+
parser.add_argument('custom_opts',
|
|
227
|
+
action='store',
|
|
228
|
+
nargs=argparse.REMAINDER,
|
|
229
|
+
help='Custom options to supply to the image being run')
|
|
230
|
+
|
|
211
231
|
args = parser.parse_args()
|
|
212
232
|
logger = Logger(args.verbose)
|
|
213
233
|
|
|
@@ -216,8 +236,14 @@ def main():
|
|
|
216
236
|
dockerfile = args.dockerfile
|
|
217
237
|
verbose = args.verbose
|
|
218
238
|
run = args.run
|
|
219
|
-
|
|
239
|
+
allow_shell = args.allow_shell
|
|
220
240
|
mode = args.mode
|
|
241
|
+
custom_opts = args.custom_opts
|
|
242
|
+
|
|
243
|
+
# Allow use of the shell for parsing by environment variable
|
|
244
|
+
env_shell = os.environ.get('DFBAR_ALLOW_SHELL')
|
|
245
|
+
if env_shell is not None and env_shell.lower() in ['1', 'true']:
|
|
246
|
+
allow_shell = True
|
|
221
247
|
|
|
222
248
|
spec_list = []
|
|
223
249
|
|
|
@@ -259,12 +285,13 @@ def main():
|
|
|
259
285
|
try:
|
|
260
286
|
for spec in spec_list:
|
|
261
287
|
process_docker_spec(spec, dockerfile=dockerfile,
|
|
262
|
-
verbose=verbose, run=run,
|
|
263
|
-
ignore_missing=ignore_missing, mode=mode
|
|
288
|
+
verbose=verbose, run=run, allow_shell=allow_shell,
|
|
289
|
+
ignore_missing=ignore_missing, mode=mode,
|
|
290
|
+
custom_opts=custom_opts)
|
|
264
291
|
except Exception as e:
|
|
265
292
|
raise Exception('Processing failed with error: %s' % str(e))
|
|
266
293
|
|
|
267
|
-
|
|
294
|
+
def cli_entrypoint():
|
|
268
295
|
try:
|
|
269
296
|
main()
|
|
270
297
|
except Exception as e:
|
|
@@ -272,3 +299,6 @@ if __name__ == '__main__':
|
|
|
272
299
|
sys.exit(1)
|
|
273
300
|
|
|
274
301
|
sys.exit(0)
|
|
302
|
+
|
|
303
|
+
if __name__ == '__main__':
|
|
304
|
+
cli_entrypoint()
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|