Support loading in Figfiles with .yaml extension

Add basic boilerplate text - feel free to change
This commit is contained in:
Chris Adams 2014-01-28 00:43:23 +00:00
parent 7c9c55785d
commit 1d18d747a5
3 changed files with 21 additions and 1 deletions

View File

@ -36,8 +36,9 @@ 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 = os.path.join(self.base_dir, 'fig.yml') 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))
@ -60,3 +61,12 @@ If it's at a non-standard location, specify the URL with the DOCKER_HOST environ
def formatter(self): def formatter(self):
return Formatter() return Formatter()
def check_yaml_filename(self):
if os.path.exists(os.path.join(self.base_dir, 'fig.yaml')):
log.warning("Fig just read the file 'fig.yaml' on startup, rather than 'fig.yml'")
log.warning("Please be aware that fig.yml the expected extension in most cases, and using .yaml can cause compatibility issues in future")
return os.path.join(self.base_dir, 'fig.yaml')
else:
os.path.join(self.base_dir, 'fig.yml')

View File

@ -15,6 +15,13 @@ class CLITestCase(DockerClientTestCase):
self.command.project.kill() self.command.project.kill()
self.command.project.remove_stopped() self.command.project.remove_stopped()
def test_yaml_filename_check(self):
self.command.base_dir = 'tests/fixtures/longer-filename-figfile'
project = self.command.project
self.assertTrue( project.get_service('definedinyamlnotyml'), "Service: definedinyamlnotyml should have been loaded from .yaml file" )
def test_help(self): def test_help(self):
self.assertRaises(SystemExit, lambda: self.command.dispatch(['-h'], None)) self.assertRaises(SystemExit, lambda: self.command.dispatch(['-h'], None))

View File

@ -0,0 +1,3 @@
definedinyamlnotyml:
image: ubuntu
command: /bin/sleep 300