Skip to content

Commit

Permalink
Merge pull request #43 from /issues/36-arbitrary-docker-args
Browse files Browse the repository at this point in the history
Allow arbitrary args to be passed to docker
  • Loading branch information
JonathonReinhart committed Feb 4, 2016
2 parents 4542d30 + c890a2d commit fc681f0
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]
### Added
- Add `-d` to pass arbitrary arguments to `docker run`


## [1.5.0] - 2016-02-01
### Added
- Add `-r` option to run container as root
Expand All @@ -19,6 +24,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
- Better handle empty `.scuba.yml` and other YAML-related errors
- Fix numerous bugs when running under Python 3


## [1.4.0] - 2016-01-08
### Added
- Added `--verbose` and `--dry-run` options
Expand Down
10 changes: 9 additions & 1 deletion scuba/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import sys
import subprocess
import shlex
import itertools
import argparse
from tempfile import NamedTemporaryFile
import atexit
Expand Down Expand Up @@ -121,13 +122,20 @@ def get_native_opts(scuba_args):

def parse_scuba_args(argv):
ap = argparse.ArgumentParser(description='Simple Container-Utilizing Build Apparatus')
ap.add_argument('-d', '--docker-arg', dest='docker_args', action='append',
type=lambda x: shlex.split(x), default=[],
help="Pass additional arguments to 'docker run'")
ap.add_argument('-n', '--dry-run', action='store_true')
ap.add_argument('-r', '--root', action='store_true')
ap.add_argument('-v', '--version', action='version', version='scuba ' + __version__)
ap.add_argument('-V', '--verbose', action='store_true')
ap.add_argument('command', nargs=argparse.REMAINDER)

args = ap.parse_args(argv)

# Flatten docker arguments into single list
args.docker_args = list(itertools.chain.from_iterable(args.docker_args))

global g_verbose
g_verbose = args.verbose

Expand Down Expand Up @@ -203,7 +211,7 @@ def main(argv=None):

# ...and set the working dir relative to it
'-w', os.path.join(SCUBA_ROOT, top_rel),
] + docker_opts
] + docker_opts + scuba_args.docker_args

# allocate TTY if scuba's output is going to a terminal
if sys.stdout.isatty():
Expand Down
24 changes: 23 additions & 1 deletion tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import logging
import os
import sys
from tempfile import mkdtemp, TemporaryFile
from tempfile import mkdtemp, TemporaryFile, NamedTemporaryFile
from shutil import rmtree

import scuba.__main__ as main
Expand Down Expand Up @@ -260,3 +260,25 @@ def test_user_root(self):
assert_equal(username, 'root')
assert_equal(gid, 0)
assert_equal(groupname, 'root')


def test_arbitrary_docker_args(self):
'''Verify -d successfully passes arbitrary docker arguments'''

with open('.scuba.yml', 'w') as f:
f.write('image: {0}\n'.format(DOCKER_IMAGE))

data = 'Lorem ipsum dolor sit amet'
data_path = '/lorem/ipsum'

with NamedTemporaryFile(mode='wt') as tempf:
tempf.write(data)
tempf.flush()

args = [
'-d=-v {0}:{1}:ro,z'.format(tempf.name, data_path),
'cat', data_path,
]
out, _ = self.run_scuba(args)

assert_str_equalish(out, data)

0 comments on commit fc681f0

Please sign in to comment.