mirror of
https://github.com/docker/compose.git
synced 2025-07-23 21:54:40 +02:00
Alternate fig file can be specified with -f
This commit is contained in:
parent
05e15e27ef
commit
9d1383ba26
@ -22,6 +22,9 @@ log = logging.getLogger(__name__)
|
|||||||
class Command(DocoptCommand):
|
class Command(DocoptCommand):
|
||||||
base_dir = '.'
|
base_dir = '.'
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
self.yaml_path = os.environ.get('FIG_FILE', None)
|
||||||
|
|
||||||
def dispatch(self, *args, **kwargs):
|
def dispatch(self, *args, **kwargs):
|
||||||
try:
|
try:
|
||||||
super(Command, self).dispatch(*args, **kwargs)
|
super(Command, self).dispatch(*args, **kwargs)
|
||||||
@ -54,6 +57,11 @@ Couldn't connect to Docker daemon at %s - is it running?
|
|||||||
If it's at a non-standard location, specify the URL with the DOCKER_HOST environment variable.
|
If it's at a non-standard location, specify the URL with the DOCKER_HOST environment variable.
|
||||||
""" % self.client.base_url)
|
""" % self.client.base_url)
|
||||||
|
|
||||||
|
def perform_command(self, options, *args, **kwargs):
|
||||||
|
if options['--file'] is not None:
|
||||||
|
self.yaml_path = os.path.join(self.base_dir, options['--file'])
|
||||||
|
return super(Command, self).perform_command(options, *args, **kwargs)
|
||||||
|
|
||||||
@cached_property
|
@cached_property
|
||||||
def client(self):
|
def client(self):
|
||||||
return Client(docker_url())
|
return Client(docker_url())
|
||||||
@ -61,9 +69,10 @@ If it's at a non-standard location, specify the URL with the DOCKER_HOST environ
|
|||||||
@cached_property
|
@cached_property
|
||||||
def project(self):
|
def project(self):
|
||||||
try:
|
try:
|
||||||
yaml_path = self.check_yaml_filename()
|
yaml_path = self.yaml_path
|
||||||
|
if yaml_path is None:
|
||||||
|
yaml_path = self.check_yaml_filename()
|
||||||
config = yaml.load(open(yaml_path))
|
config = yaml.load(open(yaml_path))
|
||||||
|
|
||||||
except IOError as e:
|
except IOError as e:
|
||||||
if e.errno == errno.ENOENT:
|
if e.errno == errno.ENOENT:
|
||||||
log.error("Can't find %s. Are you in the right directory?", os.path.basename(e.filename))
|
log.error("Can't find %s. Are you in the right directory?", os.path.basename(e.filename))
|
||||||
|
@ -70,6 +70,7 @@ class TopLevelCommand(Command):
|
|||||||
Options:
|
Options:
|
||||||
--verbose Show more output
|
--verbose Show more output
|
||||||
--version Print version and exit
|
--version Print version and exit
|
||||||
|
-f, --file FILE Specify an alternate fig file (default: fig.yml)
|
||||||
|
|
||||||
Commands:
|
Commands:
|
||||||
build Build or rebuild services
|
build Build or rebuild services
|
||||||
|
@ -31,6 +31,28 @@ class CLITestCase(DockerClientTestCase):
|
|||||||
self.command.dispatch(['ps'], None)
|
self.command.dispatch(['ps'], None)
|
||||||
self.assertIn('fig_simple_1', mock_stdout.getvalue())
|
self.assertIn('fig_simple_1', mock_stdout.getvalue())
|
||||||
|
|
||||||
|
@patch('sys.stdout', new_callable=StringIO)
|
||||||
|
def test_default_figfile(self, mock_stdout):
|
||||||
|
self.command.base_dir = 'tests/fixtures/multiple-figfiles'
|
||||||
|
self.command.dispatch(['up', '-d'], None)
|
||||||
|
self.command.dispatch(['ps'], None)
|
||||||
|
|
||||||
|
output = mock_stdout.getvalue()
|
||||||
|
self.assertIn('fig_simple_1', output)
|
||||||
|
self.assertIn('fig_another_1', output)
|
||||||
|
self.assertNotIn('fig_yetanother_1', output)
|
||||||
|
|
||||||
|
@patch('sys.stdout', new_callable=StringIO)
|
||||||
|
def test_alternate_figfile(self, mock_stdout):
|
||||||
|
self.command.base_dir = 'tests/fixtures/multiple-figfiles'
|
||||||
|
self.command.dispatch(['-f', 'fig2.yml', 'up', '-d'], None)
|
||||||
|
self.command.dispatch(['-f', 'fig2.yml', 'ps'], None)
|
||||||
|
|
||||||
|
output = mock_stdout.getvalue()
|
||||||
|
self.assertNotIn('fig_simple_1', output)
|
||||||
|
self.assertNotIn('fig_another_1', output)
|
||||||
|
self.assertIn('fig_yetanother_1', output)
|
||||||
|
|
||||||
def test_scale(self):
|
def test_scale(self):
|
||||||
project = self.command.project
|
project = self.command.project
|
||||||
|
|
||||||
|
6
tests/fixtures/multiple-figfiles/fig.yml
vendored
Normal file
6
tests/fixtures/multiple-figfiles/fig.yml
vendored
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
simple:
|
||||||
|
image: ubuntu
|
||||||
|
command: /bin/sleep 300
|
||||||
|
another:
|
||||||
|
image: ubuntu
|
||||||
|
command: /bin/sleep 300
|
3
tests/fixtures/multiple-figfiles/fig2.yml
vendored
Normal file
3
tests/fixtures/multiple-figfiles/fig2.yml
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
yetanother:
|
||||||
|
image: ubuntu
|
||||||
|
command: /bin/sleep 300
|
Loading…
x
Reference in New Issue
Block a user