WIP: rename Fig to Compose

Signed-off-by: Aanand Prasad <aanand.prasad@gmail.com>
This commit is contained in:
Aanand Prasad 2015-01-12 14:59:05 +00:00
parent 7be8b4c06d
commit 2af7693e64
54 changed files with 199 additions and 211 deletions

2
.gitignore vendored
View File

@ -5,4 +5,4 @@
/dist
/docs/_site
/venv
fig.spec
compose.spec

View File

@ -14,4 +14,4 @@ RUN python setup.py install
RUN chown -R user /code/
ENTRYPOINT ["/usr/local/bin/fig"]
ENTRYPOINT ["/usr/local/bin/compose"]

3
bin/compose Executable file
View File

@ -0,0 +1,3 @@
#!/usr/bin/env python
from compose.cli.main import main
main()

View File

@ -1,3 +0,0 @@
#!/usr/bin/env python
from fig.cli.main import main
main()

View File

@ -43,11 +43,15 @@ class Command(DocoptCommand):
def perform_command(self, options, handler, command_options):
if options['COMMAND'] == 'help':
# Skip looking up the figfile.
# Skip looking up the compose file.
handler(None, command_options)
return
explicit_config_path = options.get('--file') or os.environ.get('FIG_FILE')
if 'FIG_FILE' in os.environ:
log.warn('The FIG_FILE environment variable is deprecated.')
log.warn('Please use COMPOSE_FILE instead.')
explicit_config_path = options.get('--file') or os.environ.get('COMPOSE_FILE') or os.environ.get('FIG_FILE')
project = self.get_project(
self.get_config_path(explicit_config_path),
project_name=options.get('--project-name'),
@ -59,7 +63,7 @@ class Command(DocoptCommand):
client = docker_client()
if verbose:
version_info = six.iteritems(client.version())
log.info("Fig version %s", __version__)
log.info("Compose version %s", __version__)
log.info("Docker base_url: %s", client.base_url)
log.info("Docker version: %s",
", ".join("%s=%s" % item for item in version_info))
@ -72,7 +76,7 @@ class Command(DocoptCommand):
return yaml.safe_load(fh)
except IOError as e:
if e.errno == errno.ENOENT:
raise errors.FigFileNotFound(os.path.basename(e.filename))
raise errors.ComposeFileNotFound(os.path.basename(e.filename))
raise errors.UserError(six.text_type(e))
def get_project(self, config_path, project_name=None, verbose=False):
@ -88,7 +92,11 @@ class Command(DocoptCommand):
def normalize_name(name):
return re.sub(r'[^a-z0-9]', '', name.lower())
project_name = project_name or os.environ.get('FIG_PROJECT_NAME')
if 'FIG_PROJECT_NAME' in os.environ:
log.warn('The FIG_PROJECT_NAME environment variable is deprecated.')
log.warn('Please use COMPOSE_PROJECT_NAME instead.')
project_name = project_name or os.environ.get('COMPOSE_PROJECT_NAME') or os.environ.get('FIG_PROJECT_NAME')
if project_name is not None:
return normalize_name(project_name)
@ -102,13 +110,13 @@ class Command(DocoptCommand):
if file_path:
return os.path.join(self.base_dir, file_path)
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 "
if os.path.exists(os.path.join(self.base_dir, 'compose.yaml')):
log.warning("Fig just read the file 'compose.yaml' on startup, rather "
"than 'compose.yml'")
log.warning("Please be aware that .yml is the expected extension "
"in most cases, and using .yaml can cause compatibility "
"issues in future")
return os.path.join(self.base_dir, 'fig.yaml')
return os.path.join(self.base_dir, 'compose.yaml')
return os.path.join(self.base_dir, 'fig.yml')
return os.path.join(self.base_dir, 'compose.yml')

View File

@ -55,8 +55,8 @@ class ConnectionErrorGeneric(UserError):
""" % url)
class FigFileNotFound(UserError):
class ComposeFileNotFound(UserError):
def __init__(self, filename):
super(FigFileNotFound, self).__init__("""
super(ComposeFileNotFound, self).__init__("""
Can't find %s. Are you in the right directory?
""" % filename)

View File

@ -71,13 +71,13 @@ class TopLevelCommand(Command):
"""Fast, isolated development environments using Docker.
Usage:
fig [options] [COMMAND] [ARGS...]
fig -h|--help
compose [options] [COMMAND] [ARGS...]
compose -h|--help
Options:
--verbose Show more output
--version Print version and exit
-f, --file FILE Specify an alternate fig file (default: fig.yml)
-f, --file FILE Specify an alternate compose file (default: compose.yml)
-p, --project-name NAME Specify an alternate project name (default: directory name)
Commands:
@ -99,7 +99,7 @@ class TopLevelCommand(Command):
"""
def docopt_options(self):
options = super(TopLevelCommand, self).docopt_options()
options['version'] = "fig %s" % __version__
options['version'] = "compose %s" % __version__
return options
def build(self, project, options):
@ -107,8 +107,8 @@ class TopLevelCommand(Command):
Build or rebuild services.
Services are built once and then tagged as `project_service`,
e.g. `figtest_db`. If you change a service's `Dockerfile` or the
contents of its build directory, you can run `fig build` to rebuild it.
e.g. `composetest_db`. If you change a service's `Dockerfile` or the
contents of its build directory, you can run `compose build` to rebuild it.
Usage: build [options] [SERVICE...]
@ -261,11 +261,11 @@ class TopLevelCommand(Command):
For example:
$ fig run web python manage.py shell
$ compose run web python manage.py shell
By default, linked services will be started, unless they are already
running. If you do not want to start linked services, use
`fig run --no-deps SERVICE COMMAND [ARGS...]`.
`compose run --no-deps SERVICE COMMAND [ARGS...]`.
Usage: run [options] [-e KEY=VAL...] SERVICE [COMMAND] [ARGS...]
@ -280,7 +280,7 @@ class TopLevelCommand(Command):
--rm Remove container after run. Ignored in detached mode.
--service-ports Run command with the service's ports enabled and mapped
to the host.
-T Disable pseudo-tty allocation. By default `fig run`
-T Disable pseudo-tty allocation. By default `compose run`
allocates a TTY.
"""
service = project.get_service(options['SERVICE'])
@ -352,7 +352,7 @@ class TopLevelCommand(Command):
Numbers are specified in the form `service=num` as arguments.
For example:
$ fig scale web=2 worker=3
$ compose scale web=2 worker=3
Usage: scale [SERVICE=NUM...]
"""
@ -372,7 +372,7 @@ class TopLevelCommand(Command):
'Service "%s" cannot be scaled because it specifies a port '
'on the host. If multiple containers for this service were '
'created, the port would clash.\n\nRemove the ":" from the '
'port definition in fig.yml so Docker can choose a random '
'port definition in compose.yml so Docker can choose a random '
'port for each container.' % service_name)
def start(self, project, options):
@ -387,7 +387,7 @@ class TopLevelCommand(Command):
"""
Stop running containers without removing them.
They can be started again with `fig start`.
They can be started again with `compose start`.
Usage: stop [SERVICE...]
"""
@ -405,14 +405,14 @@ class TopLevelCommand(Command):
"""
Build, (re)create, start and attach to containers for a service.
By default, `fig up` will aggregate the output of each container, and
when it exits, all containers will be stopped. If you run `fig up -d`,
By default, `compose up` will aggregate the output of each container, and
when it exits, all containers will be stopped. If you run `compose up -d`,
it'll start the containers in the background and leave them running.
If there are existing containers for a service, `fig up` will stop
If there are existing containers for a service, `compose up` will stop
and recreate them (preserving mounted volumes with volumes-from),
so that changes in `fig.yml` are picked up. If you do not want existing
containers to be recreated, `fig up --no-recreate` will re-use existing
so that changes in `compose.yml` are picked up. If you do not want existing
containers to be recreated, `compose up --no-recreate` will re-use existing
containers.
Usage: up [options] [SERVICE...]

View File

@ -67,7 +67,7 @@ class Project(object):
dicts = []
for service_name, service in list(config.items()):
if not isinstance(service, dict):
raise ConfigurationError('Service "%s" doesn\'t have any configuration options. All top level keys in your fig.yml must map to a dictionary of configuration options.' % service_name)
raise ConfigurationError('Service "%s" doesn\'t have any configuration options. All top level keys in your compose.yml must map to a dictionary of configuration options.' % service_name)
service['name'] = service_name
dicts.append(service)
return cls.from_dicts(name, dicts, client)

View File

@ -127,7 +127,7 @@ class Service(object):
return project == self.project and name == self.name
def get_container(self, number=1):
"""Return a :class:`fig.container.Container` for this service. The
"""Return a :class:`compose.container.Container` for this service. The
container must be active, and match `number`.
"""
for container in self.client.containers():

View File

@ -1,5 +1,5 @@
#!/bin/bash
set -ex
pushd docs
fig run --rm jekyll jekyll build
compose run --rm jekyll jekyll build
popd

View File

@ -2,7 +2,7 @@
set -ex
mkdir -p `pwd`/dist
chmod 777 `pwd`/dist
docker build -t fig .
docker run -u user -v `pwd`/dist:/code/dist --rm --entrypoint pyinstaller fig -F bin/fig
mv dist/fig dist/fig-Linux-x86_64
docker run -u user -v `pwd`/dist:/code/dist --rm --entrypoint dist/fig-Linux-x86_64 fig --version
docker build -t compose .
docker run -u user -v `pwd`/dist:/code/dist --rm --entrypoint pyinstaller compose -F bin/compose
mv dist/compose dist/compose-Linux-x86_64
docker run -u user -v `pwd`/dist:/code/dist --rm --entrypoint dist/compose-Linux-x86_64 compose --version

View File

@ -5,6 +5,6 @@ virtualenv venv
venv/bin/pip install -r requirements.txt
venv/bin/pip install -r requirements-dev.txt
venv/bin/pip install .
venv/bin/pyinstaller -F bin/fig
mv dist/fig dist/fig-Darwin-x86_64
dist/fig-Darwin-x86_64 --version
venv/bin/pyinstaller -F bin/compose
mv dist/compose dist/compose-Darwin-x86_64
dist/compose-Darwin-x86_64 --version

View File

@ -1,3 +1,3 @@
#!/bin/sh
find . -type f -name '*.pyc' -delete
rm -rf docs/_site build dist fig.egg-info
rm -rf docs/_site build dist compose.egg-info

View File

@ -1,29 +0,0 @@
#!/bin/bash
set -ex
script/build-docs
pushd docs/_site
export GIT_DIR=.git-gh-pages
export GIT_WORK_TREE=.
if [ ! -d "$GIT_DIR" ]; then
git init
fi
if !(git remote | grep origin); then
git remote add origin git@github.com:docker/fig.git
fi
git fetch origin
git reset --soft origin/gh-pages
echo ".git-gh-pages" > .gitignore
git add -A .
git commit -m "update" || echo "didn't commit"
git push origin master:gh-pages
popd

View File

@ -1,5 +1,5 @@
#!/bin/sh
set -ex
docker build -t fig .
docker run -v /var/run/docker.sock:/var/run/docker.sock --rm --entrypoint flake8 fig fig
docker run -v /var/run/docker.sock:/var/run/docker.sock --rm --entrypoint nosetests fig $@
docker build -t compose .
docker run -v /var/run/docker.sock:/var/run/docker.sock --rm --entrypoint flake8 compose compose
docker run -v /var/run/docker.sock:/var/run/docker.sock --rm --entrypoint nosetests compose $@

View File

@ -48,10 +48,10 @@ if sys.version_info < (2, 7):
setup(
name='fig',
version=find_version("fig", "__init__.py"),
description='Fast, isolated development environments using Docker',
url='http://www.fig.sh/',
name='compose',
version=find_version("compose", "__init__.py"),
description='Multi-container orchestration for Docker',
url='https://www.docker.com/',
author='Docker, Inc.',
license='Apache License 2.0',
packages=find_packages(exclude=[ 'tests.*', 'tests' ]),
@ -61,6 +61,6 @@ setup(
tests_require=tests_require,
entry_points="""
[console_scripts]
fig=fig.cli.main:main
compose=compose.cli.main:main
""",
)

View File

@ -0,0 +1,5 @@
implicit:
image: composetest_test
explicit:
image: composetest_test
command: [ "/bin/true" ]

View File

@ -1,5 +0,0 @@
implicit:
image: figtest_test
explicit:
image: figtest_test
command: [ "/bin/true" ]

View File

@ -5,7 +5,7 @@ from six import StringIO
from mock import patch
from .testcases import DockerClientTestCase
from fig.cli.main import TopLevelCommand
from compose.cli.main import TopLevelCommand
class CLITestCase(DockerClientTestCase):
@ -14,7 +14,7 @@ class CLITestCase(DockerClientTestCase):
self.old_sys_exit = sys.exit
sys.exit = lambda code=0: None
self.command = TopLevelCommand()
self.command.base_dir = 'tests/fixtures/simple-figfile'
self.command.base_dir = 'tests/fixtures/simple-composefile'
def tearDown(self):
sys.exit = self.old_sys_exit
@ -27,43 +27,44 @@ class CLITestCase(DockerClientTestCase):
def test_help(self):
old_base_dir = self.command.base_dir
self.command.base_dir = 'tests/fixtures/no-figfile'
self.command.base_dir = 'tests/fixtures/no-composefile'
with self.assertRaises(SystemExit) as exc_context:
self.command.dispatch(['help', 'up'], None)
self.assertIn('Usage: up [options] [SERVICE...]', str(exc_context.exception))
# self.project.kill() fails during teardown
# unless there is a figfile.
# unless there is a composefile.
self.command.base_dir = old_base_dir
# TODO: address the "Inappropriate ioctl for device" warnings in test output
@patch('sys.stdout', new_callable=StringIO)
def test_ps(self, mock_stdout):
self.project.get_service('simple').create_container()
self.command.dispatch(['ps'], None)
self.assertIn('simplefigfile_simple_1', mock_stdout.getvalue())
self.assertIn('simplecomposefile_simple_1', mock_stdout.getvalue())
@patch('sys.stdout', new_callable=StringIO)
def test_ps_default_figfile(self, mock_stdout):
self.command.base_dir = 'tests/fixtures/multiple-figfiles'
def test_ps_default_composefile(self, mock_stdout):
self.command.base_dir = 'tests/fixtures/multiple-composefiles'
self.command.dispatch(['up', '-d'], None)
self.command.dispatch(['ps'], None)
output = mock_stdout.getvalue()
self.assertIn('multiplefigfiles_simple_1', output)
self.assertIn('multiplefigfiles_another_1', output)
self.assertNotIn('multiplefigfiles_yetanother_1', output)
self.assertIn('multiplecomposefiles_simple_1', output)
self.assertIn('multiplecomposefiles_another_1', output)
self.assertNotIn('multiplecomposefiles_yetanother_1', output)
@patch('sys.stdout', new_callable=StringIO)
def test_ps_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)
def test_ps_alternate_composefile(self, mock_stdout):
self.command.base_dir = 'tests/fixtures/multiple-composefiles'
self.command.dispatch(['-f', 'compose2.yml', 'up', '-d'], None)
self.command.dispatch(['-f', 'compose2.yml', 'ps'], None)
output = mock_stdout.getvalue()
self.assertNotIn('multiplefigfiles_simple_1', output)
self.assertNotIn('multiplefigfiles_another_1', output)
self.assertIn('multiplefigfiles_yetanother_1', output)
self.assertNotIn('multiplecomposefiles_simple_1', output)
self.assertNotIn('multiplecomposefiles_another_1', output)
self.assertIn('multiplecomposefiles_yetanother_1', output)
@patch('fig.service.log')
@patch('compose.service.log')
def test_pull(self, mock_logging):
self.command.dispatch(['pull'], None)
mock_logging.info.assert_any_call('Pulling simple (busybox:latest)...')
@ -99,7 +100,7 @@ class CLITestCase(DockerClientTestCase):
self.assertFalse(config['AttachStdin'])
def test_up_with_links(self):
self.command.base_dir = 'tests/fixtures/links-figfile'
self.command.base_dir = 'tests/fixtures/links-composefile'
self.command.dispatch(['up', '-d', 'web'], None)
web = self.project.get_service('web')
db = self.project.get_service('db')
@ -109,7 +110,7 @@ class CLITestCase(DockerClientTestCase):
self.assertEqual(len(console.containers()), 0)
def test_up_with_no_deps(self):
self.command.base_dir = 'tests/fixtures/links-figfile'
self.command.base_dir = 'tests/fixtures/links-composefile'
self.command.dispatch(['up', '-d', '--no-deps', 'web'], None)
web = self.project.get_service('web')
db = self.project.get_service('db')
@ -148,7 +149,7 @@ class CLITestCase(DockerClientTestCase):
@patch('dockerpty.start')
def test_run_service_without_links(self, mock_stdout):
self.command.base_dir = 'tests/fixtures/links-figfile'
self.command.base_dir = 'tests/fixtures/links-composefile'
self.command.dispatch(['run', 'console', '/bin/true'], None)
self.assertEqual(len(self.project.containers()), 0)
@ -161,7 +162,7 @@ class CLITestCase(DockerClientTestCase):
@patch('dockerpty.start')
def test_run_service_with_links(self, __):
self.command.base_dir = 'tests/fixtures/links-figfile'
self.command.base_dir = 'tests/fixtures/links-composefile'
self.command.dispatch(['run', 'web', '/bin/true'], None)
db = self.project.get_service('db')
console = self.project.get_service('console')
@ -170,14 +171,14 @@ class CLITestCase(DockerClientTestCase):
@patch('dockerpty.start')
def test_run_with_no_deps(self, __):
self.command.base_dir = 'tests/fixtures/links-figfile'
self.command.base_dir = 'tests/fixtures/links-composefile'
self.command.dispatch(['run', '--no-deps', 'web', '/bin/true'], None)
db = self.project.get_service('db')
self.assertEqual(len(db.containers()), 0)
@patch('dockerpty.start')
def test_run_does_not_recreate_linked_containers(self, __):
self.command.base_dir = 'tests/fixtures/links-figfile'
self.command.base_dir = 'tests/fixtures/links-composefile'
self.command.dispatch(['up', '-d', 'db'], None)
db = self.project.get_service('db')
self.assertEqual(len(db.containers()), 1)
@ -193,8 +194,8 @@ class CLITestCase(DockerClientTestCase):
@patch('dockerpty.start')
def test_run_without_command(self, __):
self.command.base_dir = 'tests/fixtures/commands-figfile'
self.check_build('tests/fixtures/simple-dockerfile', tag='figtest_test')
self.command.base_dir = 'tests/fixtures/commands-composefile'
self.check_build('tests/fixtures/simple-dockerfile', tag='composetest_test')
for c in self.project.containers(stopped=True, one_off=True):
c.remove()
@ -233,7 +234,7 @@ class CLITestCase(DockerClientTestCase):
@patch('dockerpty.start')
def test_run_service_with_environement_overridden(self, _):
name = 'service'
self.command.base_dir = 'tests/fixtures/environment-figfile'
self.command.base_dir = 'tests/fixtures/environment-composefile'
self.command.dispatch(
['run', '-e', 'foo=notbar', '-e', 'allo=moto=bobo',
'-e', 'alpha=beta', name],
@ -253,7 +254,7 @@ class CLITestCase(DockerClientTestCase):
@patch('dockerpty.start')
def test_run_service_without_map_ports(self, __):
# create one off container
self.command.base_dir = 'tests/fixtures/ports-figfile'
self.command.base_dir = 'tests/fixtures/ports-composefile'
self.command.dispatch(['run', '-d', 'simple'], None)
container = self.project.get_service('simple').containers(one_off=True)[0]
@ -271,7 +272,7 @@ class CLITestCase(DockerClientTestCase):
@patch('dockerpty.start')
def test_run_service_with_map_ports(self, __):
# create one off container
self.command.base_dir = 'tests/fixtures/ports-figfile'
self.command.base_dir = 'tests/fixtures/ports-composefile'
self.command.dispatch(['run', '-d', '--service-ports', 'simple'], None)
container = self.project.get_service('simple').containers(one_off=True)[0]
@ -368,7 +369,7 @@ class CLITestCase(DockerClientTestCase):
self.assertEqual(len(project.get_service('another').containers()), 0)
def test_port(self):
self.command.base_dir = 'tests/fixtures/ports-figfile'
self.command.base_dir = 'tests/fixtures/ports-composefile'
self.command.dispatch(['up', '-d'], None)
container = self.project.get_service('simple').get_container()

View File

@ -1,13 +1,13 @@
from __future__ import unicode_literals
from fig.project import Project, ConfigurationError
from fig.container import Container
from compose.project import Project, ConfigurationError
from compose.container import Container
from .testcases import DockerClientTestCase
class ProjectTest(DockerClientTestCase):
def test_volumes_from_service(self):
project = Project.from_config(
name='figtest',
name='composetest',
config={
'data': {
'image': 'busybox:latest',
@ -29,14 +29,14 @@ class ProjectTest(DockerClientTestCase):
self.client,
image='busybox:latest',
volumes=['/var/data'],
name='figtest_data_container',
name='composetest_data_container',
)
project = Project.from_config(
name='figtest',
name='composetest',
config={
'db': {
'image': 'busybox:latest',
'volumes_from': ['figtest_data_container'],
'volumes_from': ['composetest_data_container'],
},
},
client=self.client,
@ -47,7 +47,7 @@ class ProjectTest(DockerClientTestCase):
def test_start_stop_kill_remove(self):
web = self.create_service('web')
db = self.create_service('db')
project = Project('figtest', [web, db], self.client)
project = Project('composetest', [web, db], self.client)
project.start()
@ -80,7 +80,7 @@ class ProjectTest(DockerClientTestCase):
def test_project_up(self):
web = self.create_service('web')
db = self.create_service('db', volumes=['/var/db'])
project = Project('figtest', [web, db], self.client)
project = Project('composetest', [web, db], self.client)
project.start()
self.assertEqual(len(project.containers()), 0)
@ -95,7 +95,7 @@ class ProjectTest(DockerClientTestCase):
def test_project_up_recreates_containers(self):
web = self.create_service('web')
db = self.create_service('db', volumes=['/etc'])
project = Project('figtest', [web, db], self.client)
project = Project('composetest', [web, db], self.client)
project.start()
self.assertEqual(len(project.containers()), 0)
@ -117,7 +117,7 @@ class ProjectTest(DockerClientTestCase):
def test_project_up_with_no_recreate_running(self):
web = self.create_service('web')
db = self.create_service('db', volumes=['/var/db'])
project = Project('figtest', [web, db], self.client)
project = Project('composetest', [web, db], self.client)
project.start()
self.assertEqual(len(project.containers()), 0)
@ -140,7 +140,7 @@ class ProjectTest(DockerClientTestCase):
def test_project_up_with_no_recreate_stopped(self):
web = self.create_service('web')
db = self.create_service('db', volumes=['/var/db'])
project = Project('figtest', [web, db], self.client)
project = Project('composetest', [web, db], self.client)
project.start()
self.assertEqual(len(project.containers()), 0)
@ -169,7 +169,7 @@ class ProjectTest(DockerClientTestCase):
def test_project_up_without_all_services(self):
console = self.create_service('console')
db = self.create_service('db')
project = Project('figtest', [console, db], self.client)
project = Project('composetest', [console, db], self.client)
project.start()
self.assertEqual(len(project.containers()), 0)
@ -186,7 +186,7 @@ class ProjectTest(DockerClientTestCase):
db = self.create_service('db', volumes=['/var/db'])
web = self.create_service('web', links=[(db, 'db')])
project = Project('figtest', [web, db, console], self.client)
project = Project('composetest', [web, db, console], self.client)
project.start()
self.assertEqual(len(project.containers()), 0)
@ -204,7 +204,7 @@ class ProjectTest(DockerClientTestCase):
db = self.create_service('db', volumes=['/var/db'])
web = self.create_service('web', links=[(db, 'db')])
project = Project('figtest', [web, db, console], self.client)
project = Project('composetest', [web, db, console], self.client)
project.start()
self.assertEqual(len(project.containers()), 0)
@ -219,7 +219,7 @@ class ProjectTest(DockerClientTestCase):
def test_unscale_after_restart(self):
web = self.create_service('web')
project = Project('figtest', [web], self.client)
project = Project('composetest', [web], self.client)
project.start()

View File

@ -3,9 +3,9 @@ from __future__ import absolute_import
import os
from os import path
from fig import Service
from fig.service import CannotBeScaledError
from fig.container import Container
from compose import Service
from compose.service import CannotBeScaledError
from compose.container import Container
from docker.errors import APIError
from .testcases import DockerClientTestCase
@ -23,7 +23,7 @@ class ServiceTest(DockerClientTestCase):
create_and_start_container(foo)
self.assertEqual(len(foo.containers()), 1)
self.assertEqual(foo.containers()[0].name, 'figtest_foo_1')
self.assertEqual(foo.containers()[0].name, 'composetest_foo_1')
self.assertEqual(len(bar.containers()), 0)
create_and_start_container(bar)
@ -33,8 +33,8 @@ class ServiceTest(DockerClientTestCase):
self.assertEqual(len(bar.containers()), 2)
names = [c.name for c in bar.containers()]
self.assertIn('figtest_bar_1', names)
self.assertIn('figtest_bar_2', names)
self.assertIn('composetest_bar_1', names)
self.assertIn('composetest_bar_2', names)
def test_containers_one_off(self):
db = self.create_service('db')
@ -45,7 +45,7 @@ class ServiceTest(DockerClientTestCase):
def test_project_is_added_to_container_name(self):
service = self.create_service('web')
create_and_start_container(service)
self.assertEqual(service.containers()[0].name, 'figtest_web_1')
self.assertEqual(service.containers()[0].name, 'composetest_web_1')
def test_start_stop(self):
service = self.create_service('scalingtest')
@ -86,13 +86,13 @@ class ServiceTest(DockerClientTestCase):
def test_create_container_with_one_off(self):
db = self.create_service('db')
container = db.create_container(one_off=True)
self.assertEqual(container.name, 'figtest_db_run_1')
self.assertEqual(container.name, 'composetest_db_run_1')
def test_create_container_with_one_off_when_existing_container_is_running(self):
db = self.create_service('db')
db.start()
container = db.create_container(one_off=True)
self.assertEqual(container.name, 'figtest_db_run_1')
self.assertEqual(container.name, 'composetest_db_run_1')
def test_create_container_with_unspecified_volume(self):
service = self.create_service('db', volumes=['/var/db'])
@ -146,7 +146,7 @@ class ServiceTest(DockerClientTestCase):
self.assertEqual(old_container.dictionary['Config']['Entrypoint'], ['sleep'])
self.assertEqual(old_container.dictionary['Config']['Cmd'], ['300'])
self.assertIn('FOO=1', old_container.dictionary['Config']['Env'])
self.assertEqual(old_container.name, 'figtest_db_1')
self.assertEqual(old_container.name, 'composetest_db_1')
service.start_container(old_container)
volume_path = old_container.inspect()['Volumes']['/etc']
@ -163,7 +163,7 @@ class ServiceTest(DockerClientTestCase):
self.assertEqual(new_container.dictionary['Config']['Entrypoint'], ['sleep'])
self.assertEqual(new_container.dictionary['Config']['Cmd'], ['300'])
self.assertIn('FOO=2', new_container.dictionary['Config']['Env'])
self.assertEqual(new_container.name, 'figtest_db_1')
self.assertEqual(new_container.name, 'composetest_db_1')
self.assertEqual(new_container.inspect()['Volumes']['/etc'], volume_path)
self.assertIn(intermediate_container.id, new_container.dictionary['HostConfig']['VolumesFrom'])
@ -226,8 +226,8 @@ class ServiceTest(DockerClientTestCase):
self.assertEqual(
set(web.containers()[0].links()),
set([
'figtest_db_1', 'db_1',
'figtest_db_2', 'db_2',
'composetest_db_1', 'db_1',
'composetest_db_2', 'db_2',
'db',
]),
)
@ -243,17 +243,17 @@ class ServiceTest(DockerClientTestCase):
self.assertEqual(
set(web.containers()[0].links()),
set([
'figtest_db_1', 'db_1',
'figtest_db_2', 'db_2',
'composetest_db_1', 'db_1',
'composetest_db_2', 'db_2',
'custom_link_name',
]),
)
def test_start_container_with_external_links(self):
db = self.create_service('db')
web = self.create_service('web', external_links=['figtest_db_1',
'figtest_db_2',
'figtest_db_3:db_3'])
web = self.create_service('web', external_links=['composetest_db_1',
'composetest_db_2',
'composetest_db_3:db_3'])
for _ in range(3):
create_and_start_container(db)
@ -262,8 +262,8 @@ class ServiceTest(DockerClientTestCase):
self.assertEqual(
set(web.containers()[0].links()),
set([
'figtest_db_1',
'figtest_db_2',
'composetest_db_1',
'composetest_db_2',
'db_3',
]),
)
@ -288,8 +288,8 @@ class ServiceTest(DockerClientTestCase):
self.assertEqual(
set(c.links()),
set([
'figtest_db_1', 'db_1',
'figtest_db_2', 'db_2',
'composetest_db_1', 'db_1',
'composetest_db_2', 'db_2',
'db',
]),
)
@ -299,20 +299,20 @@ class ServiceTest(DockerClientTestCase):
name='test',
client=self.client,
build='tests/fixtures/simple-dockerfile',
project='figtest',
project='composetest',
)
container = create_and_start_container(service)
container.wait()
self.assertIn('success', container.logs())
self.assertEqual(len(self.client.images(name='figtest_test')), 1)
self.assertEqual(len(self.client.images(name='composetest_test')), 1)
def test_start_container_uses_tagged_image_if_it_exists(self):
self.client.build('tests/fixtures/simple-dockerfile', tag='figtest_test')
self.client.build('tests/fixtures/simple-dockerfile', tag='composetest_test')
service = Service(
name='test',
client=self.client,
build='this/does/not/exist/and/will/throw/error',
project='figtest',
project='composetest',
)
container = create_and_start_container(service)
container.wait()

View File

@ -1,8 +1,8 @@
from __future__ import unicode_literals
from __future__ import absolute_import
from fig.service import Service
from fig.cli.docker_client import docker_client
from fig.progress_stream import stream_output
from compose.service import Service
from compose.cli.docker_client import docker_client
from compose.progress_stream import stream_output
from .. import unittest
@ -13,18 +13,18 @@ class DockerClientTestCase(unittest.TestCase):
def setUp(self):
for c in self.client.containers(all=True):
if c['Names'] and 'figtest' in c['Names'][0]:
if c['Names'] and 'composetest' in c['Names'][0]:
self.client.kill(c['Id'])
self.client.remove_container(c['Id'])
for i in self.client.images():
if isinstance(i.get('Tag'), basestring) and 'figtest' in i['Tag']:
if isinstance(i.get('Tag'), basestring) and 'composetest' in i['Tag']:
self.client.remove_image(i)
def create_service(self, name, **kwargs):
if 'command' not in kwargs:
kwargs['command'] = ["/bin/sleep", "300"]
return Service(
project='figtest',
project='composetest',
name=name,
client=self.client,
image="busybox:latest",

View File

@ -5,7 +5,7 @@ import os
import mock
from tests import unittest
from fig.cli import docker_client
from compose.cli import docker_client
class DockerClientTestCase(unittest.TestCase):

View File

@ -2,7 +2,7 @@ from __future__ import unicode_literals
from __future__ import absolute_import
from tests import unittest
from fig.cli import verbose_proxy
from compose.cli import verbose_proxy
class VerboseProxyTestCase(unittest.TestCase):

View File

@ -6,8 +6,8 @@ from .. import unittest
import mock
from fig.cli import main
from fig.cli.main import TopLevelCommand
from compose.cli import main
from compose.cli.main import TopLevelCommand
from six import StringIO
@ -16,18 +16,18 @@ class CLITestCase(unittest.TestCase):
cwd = os.getcwd()
try:
os.chdir('tests/fixtures/simple-figfile')
os.chdir('tests/fixtures/simple-composefile')
command = TopLevelCommand()
project_name = command.get_project_name(command.get_config_path())
self.assertEquals('simplefigfile', project_name)
self.assertEquals('simplecomposefile', project_name)
finally:
os.chdir(cwd)
def test_project_name_with_explicit_base_dir(self):
command = TopLevelCommand()
command.base_dir = 'tests/fixtures/simple-figfile'
command.base_dir = 'tests/fixtures/simple-composefile'
project_name = command.get_project_name(command.get_config_path())
self.assertEquals('simplefigfile', project_name)
self.assertEquals('simplecomposefile', project_name)
def test_project_name_with_explicit_uppercase_base_dir(self):
command = TopLevelCommand()
@ -41,7 +41,7 @@ class CLITestCase(unittest.TestCase):
project_name = command.get_project_name(None, project_name=name)
self.assertEquals('explicitprojectname', project_name)
def test_project_name_from_environment(self):
def test_project_name_from_environment_old_var(self):
command = TopLevelCommand()
name = 'namefromenv'
with mock.patch.dict(os.environ):
@ -49,18 +49,26 @@ class CLITestCase(unittest.TestCase):
project_name = command.get_project_name(None)
self.assertEquals(project_name, name)
def test_project_name_from_environment_new_var(self):
command = TopLevelCommand()
name = 'namefromenv'
with mock.patch.dict(os.environ):
os.environ['COMPOSE_PROJECT_NAME'] = name
project_name = command.get_project_name(None)
self.assertEquals(project_name, name)
def test_yaml_filename_check(self):
command = TopLevelCommand()
command.base_dir = 'tests/fixtures/longer-filename-figfile'
with mock.patch('fig.cli.command.log', autospec=True) as mock_log:
command.base_dir = 'tests/fixtures/longer-filename-composefile'
with mock.patch('compose.cli.command.log', autospec=True) as mock_log:
self.assertTrue(command.get_config_path())
self.assertEqual(mock_log.warning.call_count, 2)
def test_get_project(self):
command = TopLevelCommand()
command.base_dir = 'tests/fixtures/longer-filename-figfile'
command.base_dir = 'tests/fixtures/longer-filename-composefile'
project = command.get_project(command.get_config_path())
self.assertEqual(project.name, 'longerfilenamefigfile')
self.assertEqual(project.name, 'longerfilenamecomposefile')
self.assertTrue(project.client)
self.assertTrue(project.services)

View File

@ -4,7 +4,7 @@ from .. import unittest
import mock
import docker
from fig.container import Container
from compose.container import Container
class ContainerTest(unittest.TestCase):
@ -20,7 +20,7 @@ class ContainerTest(unittest.TestCase):
"Ports": None,
"SizeRw": 0,
"SizeRootFs": 0,
"Names": ["/figtest_db_1", "/figtest_web_1/db"],
"Names": ["/composetest_db_1", "/composetest_web_1/db"],
"NetworkSettings": {
"Ports": {},
},
@ -33,7 +33,7 @@ class ContainerTest(unittest.TestCase):
self.assertEqual(container.dictionary, {
"Id": "abc",
"Image":"busybox:latest",
"Name": "/figtest_db_1",
"Name": "/composetest_db_1",
})
def test_from_ps_prefixed(self):
@ -45,7 +45,7 @@ class ContainerTest(unittest.TestCase):
self.assertEqual(container.dictionary, {
"Id": "abc",
"Image":"busybox:latest",
"Name": "/figtest_db_1",
"Name": "/composetest_db_1",
})
def test_environment(self):
@ -73,7 +73,7 @@ class ContainerTest(unittest.TestCase):
container = Container.from_ps(None,
self.container_dict,
has_been_inspected=True)
self.assertEqual(container.name, "figtest_db_1")
self.assertEqual(container.name, "composetest_db_1")
def test_name_without_project(self):
container = Container.from_ps(None,

View File

@ -2,7 +2,7 @@ from __future__ import unicode_literals
from __future__ import absolute_import
import os
from fig.cli.log_printer import LogPrinter
from compose.cli.log_printer import LogPrinter
from .. import unittest

View File

@ -5,7 +5,7 @@ from tests import unittest
import mock
from six import StringIO
from fig import progress_stream
from compose import progress_stream
class ProgressStreamTestCase(unittest.TestCase):

View File

@ -1,11 +1,11 @@
from __future__ import unicode_literals
from .. import unittest
from fig.service import Service
from fig.project import Project, ConfigurationError
from compose.service import Service
from compose.project import Project, ConfigurationError
class ProjectTest(unittest.TestCase):
def test_from_dict(self):
project = Project.from_dicts('figtest', [
project = Project.from_dicts('composetest', [
{
'name': 'web',
'image': 'busybox:latest'
@ -22,7 +22,7 @@ class ProjectTest(unittest.TestCase):
self.assertEqual(project.get_service('db').options['image'], 'busybox:latest')
def test_from_dict_sorts_in_dependency_order(self):
project = Project.from_dicts('figtest', [
project = Project.from_dicts('composetest', [
{
'name': 'web',
'image': 'busybox:latest',
@ -45,7 +45,7 @@ class ProjectTest(unittest.TestCase):
self.assertEqual(project.services[2].name, 'web')
def test_from_config(self):
project = Project.from_config('figtest', {
project = Project.from_config('composetest', {
'web': {
'image': 'busybox:latest',
},
@ -61,13 +61,13 @@ class ProjectTest(unittest.TestCase):
def test_from_config_throws_error_when_not_dict(self):
with self.assertRaises(ConfigurationError):
project = Project.from_config('figtest', {
project = Project.from_config('composetest', {
'web': 'busybox:latest',
}, None)
def test_get_service(self):
web = Service(
project='figtest',
project='composetest',
name='web',
client=None,
image="busybox:latest",
@ -77,11 +77,11 @@ class ProjectTest(unittest.TestCase):
def test_get_services_returns_all_services_without_args(self):
web = Service(
project='figtest',
project='composetest',
name='web',
)
console = Service(
project='figtest',
project='composetest',
name='console',
)
project = Project('test', [web, console], None)
@ -89,11 +89,11 @@ class ProjectTest(unittest.TestCase):
def test_get_services_returns_listed_services_with_args(self):
web = Service(
project='figtest',
project='composetest',
name='web',
)
console = Service(
project='figtest',
project='composetest',
name='console',
)
project = Project('test', [web, console], None)
@ -101,20 +101,20 @@ class ProjectTest(unittest.TestCase):
def test_get_services_with_include_links(self):
db = Service(
project='figtest',
project='composetest',
name='db',
)
web = Service(
project='figtest',
project='composetest',
name='web',
links=[(db, 'database')]
)
cache = Service(
project='figtest',
project='composetest',
name='cache'
)
console = Service(
project='figtest',
project='composetest',
name='console',
links=[(web, 'web')]
)
@ -126,11 +126,11 @@ class ProjectTest(unittest.TestCase):
def test_get_services_removes_duplicates_following_links(self):
db = Service(
project='figtest',
project='composetest',
name='db',
)
web = Service(
project='figtest',
project='composetest',
name='web',
links=[(db, 'database')]
)

View File

@ -8,9 +8,9 @@ import mock
import docker
from requests import Response
from fig import Service
from fig.container import Container
from fig.service import (
from compose import Service
from compose.container import Container
from compose.service import (
ConfigError,
split_port,
build_port_bindings,
@ -203,7 +203,7 @@ class ServiceTest(unittest.TestCase):
self.assertRaises(ValueError, service.get_container)
@mock.patch('fig.service.Container', autospec=True)
@mock.patch('compose.service.Container', autospec=True)
def test_get_container(self, mock_container_class):
container_dict = dict(Name='default_foo_2')
self.mock_client.containers.return_value = [container_dict]
@ -214,15 +214,15 @@ class ServiceTest(unittest.TestCase):
mock_container_class.from_ps.assert_called_once_with(
self.mock_client, container_dict)
@mock.patch('fig.service.log', autospec=True)
@mock.patch('compose.service.log', autospec=True)
def test_pull_image(self, mock_log):
service = Service('foo', client=self.mock_client, image='someimage:sometag')
service.pull(insecure_registry=True)
self.mock_client.pull.assert_called_once_with('someimage:sometag', insecure_registry=True)
mock_log.info.assert_called_once_with('Pulling foo (someimage:sometag)...')
@mock.patch('fig.service.Container', autospec=True)
@mock.patch('fig.service.log', autospec=True)
@mock.patch('compose.service.Container', autospec=True)
@mock.patch('compose.service.log', autospec=True)
def test_create_container_from_insecure_registry(
self,
mock_log,

View File

@ -1,4 +1,4 @@
from fig.project import sort_service_dicts, DependencyError
from compose.project import sort_service_dicts, DependencyError
from .. import unittest

View File

@ -1,6 +1,6 @@
from __future__ import unicode_literals
from __future__ import absolute_import
from fig.cli.utils import split_buffer
from compose.cli.utils import split_buffer
from .. import unittest
class SplitBufferTest(unittest.TestCase):