Added --force-rm to compose build.

It's a flag passed to docker build that removes the intermediate
containers left behind on fail builds.

Signed-off-by: Adrian Budau <budau.adi@gmail.com>
This commit is contained in:
Adrian Budau 2015-10-27 02:00:51 -07:00 committed by Daniel Nephin
commit 4c2eb17ccd
10 changed files with 48 additions and 5 deletions

View file

@ -9,6 +9,7 @@ from operator import attrgetter
from .. import mock
from compose.cli.command import get_project
from compose.cli.docker_client import docker_client
from compose.container import Container
from tests.integration.testcases import DockerClientTestCase
@ -145,6 +146,33 @@ class CLITestCase(DockerClientTestCase):
assert BUILD_CACHE_TEXT not in result.stdout
assert BUILD_PULL_TEXT in result.stdout
def test_build_failed(self):
self.base_dir = 'tests/fixtures/simple-failing-dockerfile'
self.dispatch(['build', 'simple'], returncode=1)
labels = ["com.docker.compose.test_failing_image=true"]
containers = [
Container.from_ps(self.project.client, c)
for c in self.project.client.containers(
all=True,
filters={"label": labels})
]
assert len(containers) == 1
def test_build_failed_forcerm(self):
self.base_dir = 'tests/fixtures/simple-failing-dockerfile'
self.dispatch(['build', '--force-rm', 'simple'], returncode=1)
labels = ["com.docker.compose.test_failing_image=true"]
containers = [
Container.from_ps(self.project.client, c)
for c in self.project.client.containers(
all=True,
filters={"label": labels})
]
assert not containers
def test_up_detached(self):
self.dispatch(['up', '-d'])
service = self.project.get_service('simple')

View file

@ -0,0 +1,7 @@
FROM busybox:latest
LABEL com.docker.compose.test_image=true
LABEL com.docker.compose.test_failing_image=true
# With the following label the container wil be cleaned up automatically
# Must be kept in sync with LABEL_PROJECT from compose/const.py
LABEL com.docker.compose.project=composetest
RUN exit 1

View file

@ -0,0 +1,2 @@
simple:
build: .

View file

@ -356,6 +356,7 @@ class ServiceTest(unittest.TestCase):
stream=True,
path='.',
pull=False,
forcerm=False,
nocache=False,
rm=True,
)