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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: dfbar
3
- Version: 0.2.2
3
+ Version: 0.3.0
4
4
  Summary: Dockerfile Build and Run
5
5
  Home-page: https://github.com/archmachina/dfbar
6
6
  Download-URL: https://pypi.org/project/dfbar/
@@ -2,5 +2,6 @@ from .dfbar import *
2
2
 
3
3
  __all__ = [
4
4
  'main',
5
+ 'cli_entrypoint',
5
6
  'process_docker_spec'
6
7
  ]
@@ -0,0 +1,5 @@
1
+ from .dfbar import cli_entrypoint
2
+ import sys
3
+
4
+ if __name__ == '__main__':
5
+ cli_entrypoint()
@@ -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, shell=False, ignore_missing=False, mode=''):
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='shell',
199
- help='Use the shell to execute the build, run and image options. This can be dangerous if the Dockerfile is from an untrusted source')
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
- shell = args.shell
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, shell=shell,
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
- if __name__ == '__main__':
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()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: dfbar
3
- Version: 0.2.2
3
+ Version: 0.3.0
4
4
  Summary: Dockerfile Build and Run
5
5
  Home-page: https://github.com/archmachina/dfbar
6
6
  Download-URL: https://pypi.org/project/dfbar/
@@ -1,11 +0,0 @@
1
- from .dfbar import main
2
- import sys
3
-
4
- if __name__ == '__main__':
5
- try:
6
- main()
7
- except Exception as e:
8
- print(e)
9
- sys.exit(1)
10
-
11
- sys.exit(0)
File without changes
File without changes
File without changes
File without changes
File without changes