Prevent attempts to create image names starting with - or _

Signed-off-by: Joffrey F <joffrey@docker.com>
This commit is contained in:
Joffrey F 2018-06-22 15:56:53 -07:00
parent 6e30c130d5
commit b00db08aa9
2 changed files with 18 additions and 1 deletions

View File

@ -363,7 +363,9 @@ class Service(object):
@property
def image_name(self):
return self.options.get('image', '{s.project}_{s.name}'.format(s=self))
return self.options.get('image', '{project}_{s.name}'.format(
s=self, project=self.project.lstrip('_-')
))
@property
def platform(self):

View File

@ -1137,6 +1137,21 @@ class ServiceTest(DockerClientTestCase):
service.build()
assert service.image()
def test_build_with_illegal_leading_chars(self):
base_dir = tempfile.mkdtemp()
self.addCleanup(shutil.rmtree, base_dir)
with open(os.path.join(base_dir, 'Dockerfile'), 'w') as f:
f.write('FROM busybox\nRUN echo "Embodiment of Scarlet Devil"\n')
service = Service(
'build_leading_slug', client=self.client,
project='___-composetest', build={
'context': text_type(base_dir)
}
)
assert service.image_name == 'composetest_build_leading_slug'
service.build()
assert service.image()
def test_start_container_stays_unprivileged(self):
service = self.create_service('web')
container = create_and_start_container(service).inspect()