Skip to content

Commit

Permalink
Adding --name option to make, run and shell commands
Browse files Browse the repository at this point in the history
  • Loading branch information
tsorya committed Jun 26, 2017
1 parent 2a19bb4 commit d814282
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
12 changes: 9 additions & 3 deletions skipper/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,11 @@ def rmi(ctx, remote, image, tag):

@cli.command(context_settings=dict(ignore_unknown_options=True))
@click.option('-i', '--interactive', help='Interactive mode', is_flag=True, default=False, envvar='SKIPPER_INTERACTIVE')
@click.option('-n', '--name', help='Container name', default=None)
@click.option('-e', '--env', multiple=True, help='Environment variables to pass the container')
@click.argument('command', nargs=-1, type=click.UNPROCESSED, required=True)
@click.pass_context
def run(ctx, interactive, env, command):
def run(ctx, interactive, name, env, command):
'''
Run arbitrary commands
'''
Expand All @@ -177,18 +178,20 @@ def run(ctx, interactive, env, command):
fqdn_image=build_container,
environment=_expend_env(ctx, env),
interactive=interactive,
name=name,
net=ctx.obj['build_container_net'],
volumes=ctx.obj.get('volumes'),
workdir=ctx.obj.get('workdir'))


@cli.command(context_settings=dict(ignore_unknown_options=True))
@click.option('-i', '--interactive', help='Interactive mode', is_flag=True, default=False, envvar='SKIPPER_INTERACTIVE')
@click.option('-n', '--name', help='Container name', default=None)
@click.option('-e', '--env', multiple=True, help='Environment variables to pass the container')
@click.option('-f', 'makefile', help='Makefile to use', default='Makefile')
@click.argument('make_params', nargs=-1, type=click.UNPROCESSED, required=False)
@click.pass_context
def make(ctx, interactive, env, makefile, make_params):
def make(ctx, interactive, name, env, makefile, make_params):
'''
Execute makefile target(s)
'''
Expand All @@ -203,15 +206,17 @@ def make(ctx, interactive, env, makefile, make_params):
fqdn_image=build_container,
environment=_expend_env(ctx, env),
interactive=interactive,
name=name,
net=ctx.obj['build_container_net'],
volumes=ctx.obj.get('volumes'),
workdir=ctx.obj.get('workdir'))


@cli.command()
@click.option('-e', '--env', multiple=True, help='Environment variables to pass the container')
@click.option('-n', '--name', help='Container name', default=None)
@click.pass_context
def shell(ctx, env):
def shell(ctx, env, name):
'''
Start a shell
'''
Expand All @@ -225,6 +230,7 @@ def shell(ctx, env):
fqdn_image=build_container,
environment=_expend_env(ctx, env),
interactive=True,
name=name,
net=ctx.obj['build_container_net'],
volumes=ctx.obj.get('volumes'),
workdir=ctx.obj.get('workdir'))
Expand Down
8 changes: 5 additions & 3 deletions skipper/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
from contextlib import contextmanager


def run(command, fqdn_image=None, environment=None, interactive=False, net='host', volumes=None, workdir=None):
def run(command, fqdn_image=None, environment=None, interactive=False, name=None, net='host', volumes=None, workdir=None):
if fqdn_image is not None:
return _run_nested(fqdn_image, environment, command, interactive, net, volumes, workdir)
return _run_nested(fqdn_image, environment, command, interactive, name, net, volumes, workdir)

return _run(command)

Expand All @@ -22,14 +22,16 @@ def _run(cmd):


# pylint: disable=too-many-locals
def _run_nested(fqdn_image, environment, command, interactive, net='host', volumes=None, workdir=None):
def _run_nested(fqdn_image, environment, command, interactive, name, net='host', volumes=None, workdir=None):
cwd = os.getcwd()
workspace = os.path.dirname(cwd)
project = os.path.basename(cwd)

docker_cmd = ['docker', 'run']
if interactive:
docker_cmd += ['-i']
if name:
docker_cmd += ['--name', name]

docker_cmd += ['-t']
docker_cmd += ['--rm']
Expand Down

0 comments on commit d814282

Please sign in to comment.