Skip to content

Commit

Permalink
Dwr/arg support (#49)
Browse files Browse the repository at this point in the history
* add general arg support

* fixes #48 - Add build-args support

* Address issue caught in PR review
  • Loading branch information
rappdw authored and mikekwright committed May 31, 2019
1 parent 8887688 commit 1b252f1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
10 changes: 6 additions & 4 deletions scripts/build-image
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,21 @@ def build(image, image_name, image_tag, config, pull=False):

rc = 0
pull_base = ''
args = config.get(image, 'build_args') if config.has_option(image, 'build_args') else ''

if pull:
pull_base = '--pull'
if is_multistage(image):
# if this is a multistage build and it follows the conventions, tag the builder image
# otherwise, a prune will remove the layers used during the builder phase and subsequent
# builds will take longer than required
rc = image_operation(
'docker build {pull_base} --compress -t {image_name}-builder:{image_tag} -f docker/{image}/Dockerfile --target builder .'
.format(pull_base=pull_base, image_name=image_name, image=image, image_tag=image_tag))
'docker build {pull_base} --compress -t {image_name}-builder:{image_tag} -f docker/{image}/Dockerfile --target builder {args} .'
.format(pull_base=pull_base, image_name=image_name, image=image, image_tag=image_tag, args=args))
if not rc:
rc = image_operation(
'docker build {pull_base} --compress -t {image_name}:{image_tag} -f docker/{image}/Dockerfile .'
.format(pull_base=pull_base, image_name=image_name, image=image, image_tag=image_tag))
'docker build {pull_base} --compress -t {image_name}:{image_tag} -f docker/{image}/Dockerfile {args} .'
.format(pull_base=pull_base, image_name=image_name, image=image, image_tag=image_tag, args=args))

if rc != 0:
print('docker build failed: {rc}'.format(rc=rc))
Expand Down
13 changes: 5 additions & 8 deletions scripts/run-image
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ else:


_base_cmd = 'docker run {init} --name {name} {environment} {keep_container} {interactive} {gpu} {network} ' \
'{volumes} {ports} {image_name}:{image_tag} {cmd}'
'{volumes} {ports} {args} {image_name}:{image_tag} {cmd}'


def fetch_env_variables(config, image, args_env=None):
Expand Down Expand Up @@ -78,6 +78,7 @@ def run(mode, image_name, image_tag, **kwargs):
environment=kwargs['environment'],
network=kwargs['network'],
ports=kwargs['ports'],
args=kwargs['args'],
volumes=volumes,
gpu=kwargs['gpu'],
cmd=kwargs['cmd'],
Expand All @@ -104,13 +105,12 @@ if __name__ == '__main__':

parser = argparse.ArgumentParser()
parser.add_argument("image", choices=image_types, help="Docker image to run")
parser.add_argument("-a", "--args", help="general docker arguments", default='')
parser.add_argument("-k", "--keep", help="keep the image after execution", action='store_true')
parser.add_argument("-c", "--command", help="Command for image override")
parser.add_argument("-n", "--network", help="Network for image override", default='')
parser.add_argument("-g", "--use-gpu", dest='use_gpu', default=False, action='store_true',
help="Start the container with gpu support")
parser.add_argument("-p", "--pre", default=False, action='store_true',
help="use pre 1.25 API")
parser.add_argument("-e", "--env", action='append',
help="environment variables to pass to running container, e.g. foo=bar")
args = parser.parse_args()
Expand All @@ -119,10 +119,6 @@ if __name__ == '__main__':
gpu = '--runtime=nvidia -e NVIDIA_VISIBLE_DEVICES=all'
else:
gpu = ''
if args.pre:
init = ''
else:
init = '--init'

run_config = {
'environment': fetch_env_variables(config, args.image, args.env) + populate_aws_env_variables(),
Expand All @@ -133,7 +129,8 @@ if __name__ == '__main__':
'volumes': '',
'ports': '',
'cmd': args.command or '',
'init': init
'init': '--init',
'args': args.args
}

is_docked = bool(os.environ.get('DOCKER_IP'))
Expand Down

0 comments on commit 1b252f1

Please sign in to comment.