mirror of https://github.com/docker/compose.git
Merge pull request #5788 from mnottale/dash-underscore-in-project-name
Allow dash and underscore in project name.
This commit is contained in:
commit
6c7c7902f1
|
@ -127,7 +127,7 @@ def get_project(project_dir, config_path=None, project_name=None, verbose=False,
|
|||
|
||||
def get_project_name(working_dir, project_name=None, environment=None):
|
||||
def normalize_name(name):
|
||||
return re.sub(r'[^a-z0-9]', '', name.lower())
|
||||
return re.sub(r'[^-_a-z0-9]', '', name.lower())
|
||||
|
||||
if not environment:
|
||||
environment = Environment.from_env_file(working_dir)
|
||||
|
|
|
@ -491,16 +491,16 @@ class CLITestCase(DockerClientTestCase):
|
|||
def test_ps(self):
|
||||
self.project.get_service('simple').create_container()
|
||||
result = self.dispatch(['ps'])
|
||||
assert 'simplecomposefile_simple_1' in result.stdout
|
||||
assert 'simple-composefile_simple_1' in result.stdout
|
||||
|
||||
def test_ps_default_composefile(self):
|
||||
self.base_dir = 'tests/fixtures/multiple-composefiles'
|
||||
self.dispatch(['up', '-d'])
|
||||
result = self.dispatch(['ps'])
|
||||
|
||||
assert 'multiplecomposefiles_simple_1' in result.stdout
|
||||
assert 'multiplecomposefiles_another_1' in result.stdout
|
||||
assert 'multiplecomposefiles_yetanother_1' not in result.stdout
|
||||
assert 'multiple-composefiles_simple_1' in result.stdout
|
||||
assert 'multiple-composefiles_another_1' in result.stdout
|
||||
assert 'multiple-composefiles_yetanother_1' not in result.stdout
|
||||
|
||||
def test_ps_alternate_composefile(self):
|
||||
config_path = os.path.abspath(
|
||||
|
@ -511,9 +511,9 @@ class CLITestCase(DockerClientTestCase):
|
|||
self.dispatch(['-f', 'compose2.yml', 'up', '-d'])
|
||||
result = self.dispatch(['-f', 'compose2.yml', 'ps'])
|
||||
|
||||
assert 'multiplecomposefiles_simple_1' not in result.stdout
|
||||
assert 'multiplecomposefiles_another_1' not in result.stdout
|
||||
assert 'multiplecomposefiles_yetanother_1' in result.stdout
|
||||
assert 'multiple-composefiles_simple_1' not in result.stdout
|
||||
assert 'multiple-composefiles_another_1' not in result.stdout
|
||||
assert 'multiple-composefiles_yetanother_1' in result.stdout
|
||||
|
||||
def test_ps_services_filter_option(self):
|
||||
self.base_dir = 'tests/fixtures/ps-services-filter'
|
||||
|
@ -900,18 +900,18 @@ class CLITestCase(DockerClientTestCase):
|
|||
assert len(self.project.containers(one_off=OneOffFilter.only, stopped=True)) == 2
|
||||
|
||||
result = self.dispatch(['down', '--rmi=local', '--volumes'])
|
||||
assert 'Stopping v2full_web_1' in result.stderr
|
||||
assert 'Stopping v2full_other_1' in result.stderr
|
||||
assert 'Stopping v2full_web_run_2' in result.stderr
|
||||
assert 'Removing v2full_web_1' in result.stderr
|
||||
assert 'Removing v2full_other_1' in result.stderr
|
||||
assert 'Removing v2full_web_run_1' in result.stderr
|
||||
assert 'Removing v2full_web_run_2' in result.stderr
|
||||
assert 'Removing volume v2full_data' in result.stderr
|
||||
assert 'Removing image v2full_web' in result.stderr
|
||||
assert 'Stopping v2-full_web_1' in result.stderr
|
||||
assert 'Stopping v2-full_other_1' in result.stderr
|
||||
assert 'Stopping v2-full_web_run_2' in result.stderr
|
||||
assert 'Removing v2-full_web_1' in result.stderr
|
||||
assert 'Removing v2-full_other_1' in result.stderr
|
||||
assert 'Removing v2-full_web_run_1' in result.stderr
|
||||
assert 'Removing v2-full_web_run_2' in result.stderr
|
||||
assert 'Removing volume v2-full_data' in result.stderr
|
||||
assert 'Removing image v2-full_web' in result.stderr
|
||||
assert 'Removing image busybox' not in result.stderr
|
||||
assert 'Removing network v2full_default' in result.stderr
|
||||
assert 'Removing network v2full_front' in result.stderr
|
||||
assert 'Removing network v2-full_default' in result.stderr
|
||||
assert 'Removing network v2-full_front' in result.stderr
|
||||
|
||||
def test_down_timeout(self):
|
||||
self.dispatch(['up', '-d'], None)
|
||||
|
@ -1998,39 +1998,39 @@ class CLITestCase(DockerClientTestCase):
|
|||
proc = start_process(self.base_dir, ['run', '-T', 'simple', 'top'])
|
||||
wait_on_condition(ContainerStateCondition(
|
||||
self.project.client,
|
||||
'simplecomposefile_simple_run_1',
|
||||
'simple-composefile_simple_run_1',
|
||||
'running'))
|
||||
|
||||
os.kill(proc.pid, signal.SIGINT)
|
||||
wait_on_condition(ContainerStateCondition(
|
||||
self.project.client,
|
||||
'simplecomposefile_simple_run_1',
|
||||
'simple-composefile_simple_run_1',
|
||||
'exited'))
|
||||
|
||||
def test_run_handles_sigterm(self):
|
||||
proc = start_process(self.base_dir, ['run', '-T', 'simple', 'top'])
|
||||
wait_on_condition(ContainerStateCondition(
|
||||
self.project.client,
|
||||
'simplecomposefile_simple_run_1',
|
||||
'simple-composefile_simple_run_1',
|
||||
'running'))
|
||||
|
||||
os.kill(proc.pid, signal.SIGTERM)
|
||||
wait_on_condition(ContainerStateCondition(
|
||||
self.project.client,
|
||||
'simplecomposefile_simple_run_1',
|
||||
'simple-composefile_simple_run_1',
|
||||
'exited'))
|
||||
|
||||
def test_run_handles_sighup(self):
|
||||
proc = start_process(self.base_dir, ['run', '-T', 'simple', 'top'])
|
||||
wait_on_condition(ContainerStateCondition(
|
||||
self.project.client,
|
||||
'simplecomposefile_simple_run_1',
|
||||
'simple-composefile_simple_run_1',
|
||||
'running'))
|
||||
|
||||
os.kill(proc.pid, signal.SIGHUP)
|
||||
wait_on_condition(ContainerStateCondition(
|
||||
self.project.client,
|
||||
'simplecomposefile_simple_run_1',
|
||||
'simple-composefile_simple_run_1',
|
||||
'exited'))
|
||||
|
||||
@mock.patch.dict(os.environ)
|
||||
|
@ -2232,7 +2232,7 @@ class CLITestCase(DockerClientTestCase):
|
|||
self.dispatch(['up', '-d', 'another'])
|
||||
wait_on_condition(ContainerStateCondition(
|
||||
self.project.client,
|
||||
'logscomposefile_another_1',
|
||||
'logs-composefile_another_1',
|
||||
'exited'))
|
||||
|
||||
self.dispatch(['kill', 'simple'])
|
||||
|
@ -2241,8 +2241,8 @@ class CLITestCase(DockerClientTestCase):
|
|||
|
||||
assert 'hello' in result.stdout
|
||||
assert 'test' in result.stdout
|
||||
assert 'logscomposefile_another_1 exited with code 0' in result.stdout
|
||||
assert 'logscomposefile_simple_1 exited with code 137' in result.stdout
|
||||
assert 'logs-composefile_another_1 exited with code 0' in result.stdout
|
||||
assert 'logs-composefile_simple_1 exited with code 137' in result.stdout
|
||||
|
||||
def test_logs_default(self):
|
||||
self.base_dir = 'tests/fixtures/logs-composefile'
|
||||
|
@ -2489,7 +2489,7 @@ class CLITestCase(DockerClientTestCase):
|
|||
|
||||
container, = self.project.containers()
|
||||
expected_template = ' container {} {}'
|
||||
expected_meta_info = ['image=busybox:latest', 'name=simplecomposefile_simple_1']
|
||||
expected_meta_info = ['image=busybox:latest', 'name=simple-composefile_simple_1']
|
||||
|
||||
assert expected_template.format('create', container.id) in lines[0]
|
||||
assert expected_template.format('start', container.id) in lines[1]
|
||||
|
@ -2609,13 +2609,13 @@ class CLITestCase(DockerClientTestCase):
|
|||
|
||||
result = wait_on_process(proc, returncode=1)
|
||||
|
||||
assert 'exitcodefrom_another_1 exited with code 1' in result.stdout
|
||||
assert 'exit-code-from_another_1 exited with code 1' in result.stdout
|
||||
|
||||
def test_images(self):
|
||||
self.project.get_service('simple').create_container()
|
||||
result = self.dispatch(['images'])
|
||||
assert 'busybox' in result.stdout
|
||||
assert 'simplecomposefile_simple_1' in result.stdout
|
||||
assert 'simple-composefile_simple_1' in result.stdout
|
||||
|
||||
def test_images_default_composefile(self):
|
||||
self.base_dir = 'tests/fixtures/multiple-composefiles'
|
||||
|
@ -2623,8 +2623,8 @@ class CLITestCase(DockerClientTestCase):
|
|||
result = self.dispatch(['images'])
|
||||
|
||||
assert 'busybox' in result.stdout
|
||||
assert 'multiplecomposefiles_another_1' in result.stdout
|
||||
assert 'multiplecomposefiles_simple_1' in result.stdout
|
||||
assert 'multiple-composefiles_another_1' in result.stdout
|
||||
assert 'multiple-composefiles_simple_1' in result.stdout
|
||||
|
||||
@mock.patch.dict(os.environ)
|
||||
def test_images_tagless_image(self):
|
||||
|
@ -2644,7 +2644,7 @@ class CLITestCase(DockerClientTestCase):
|
|||
self.project.get_service('foo').create_container()
|
||||
result = self.dispatch(['images'])
|
||||
assert '<none>' in result.stdout
|
||||
assert 'taglessimage_foo_1' in result.stdout
|
||||
assert 'tagless-image_foo_1' in result.stdout
|
||||
|
||||
def test_up_with_override_yaml(self):
|
||||
self.base_dir = 'tests/fixtures/override-yaml-files'
|
||||
|
|
|
@ -30,12 +30,12 @@ class CLITestCase(unittest.TestCase):
|
|||
test_dir = py._path.local.LocalPath('tests/fixtures/simple-composefile')
|
||||
with test_dir.as_cwd():
|
||||
project_name = get_project_name('.')
|
||||
assert 'simplecomposefile' == project_name
|
||||
assert 'simple-composefile' == project_name
|
||||
|
||||
def test_project_name_with_explicit_base_dir(self):
|
||||
base_dir = 'tests/fixtures/simple-composefile'
|
||||
project_name = get_project_name(base_dir)
|
||||
assert 'simplecomposefile' == project_name
|
||||
assert 'simple-composefile' == project_name
|
||||
|
||||
def test_project_name_with_explicit_uppercase_base_dir(self):
|
||||
base_dir = 'tests/fixtures/UpperCaseDir'
|
||||
|
@ -45,7 +45,7 @@ class CLITestCase(unittest.TestCase):
|
|||
def test_project_name_with_explicit_project_name(self):
|
||||
name = 'explicit-project-name'
|
||||
project_name = get_project_name(None, project_name=name)
|
||||
assert 'explicitprojectname' == project_name
|
||||
assert 'explicit-project-name' == project_name
|
||||
|
||||
@mock.patch.dict(os.environ)
|
||||
def test_project_name_from_environment_new_var(self):
|
||||
|
@ -59,7 +59,7 @@ class CLITestCase(unittest.TestCase):
|
|||
with mock.patch.dict(os.environ):
|
||||
os.environ['COMPOSE_PROJECT_NAME'] = ''
|
||||
project_name = get_project_name(base_dir)
|
||||
assert 'simplecomposefile' == project_name
|
||||
assert 'simple-composefile' == project_name
|
||||
|
||||
@mock.patch.dict(os.environ)
|
||||
def test_project_name_with_environment_file(self):
|
||||
|
@ -80,7 +80,7 @@ class CLITestCase(unittest.TestCase):
|
|||
def test_get_project(self):
|
||||
base_dir = 'tests/fixtures/longer-filename-composefile'
|
||||
project = get_project(base_dir)
|
||||
assert project.name == 'longerfilenamecomposefile'
|
||||
assert project.name == 'longer-filename-composefile'
|
||||
assert project.client
|
||||
assert project.services
|
||||
|
||||
|
|
Loading…
Reference in New Issue