summaryrefslogtreecommitdiff
path: root/compose/service.py
diff options
context:
space:
mode:
authorSlava Kardakov <ojab@ojab.ru>2021-02-16 16:09:02 +0000
committerSlava Kardakov <ojab@ojab.ru>2021-02-18 17:47:59 +0000
commit4daad056c4d54ea5d4e84f097f9b825067fa016d (patch)
tree17f06411f6b3163d1f4c247f6e722e0d059099a7 /compose/service.py
parent74c09cac664f5c9e22dfed2f6bea66e9936670b3 (diff)
Add init container support
Fixes #6855 See https://github.com/compose-spec/compose-spec/pull/134 Signed-off-by: Slava Kardakov <ojab@ojab.ru>
Diffstat (limited to 'compose/service.py')
-rw-r--r--compose/service.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/compose/service.py b/compose/service.py
index df0d76fb..b5ac907a 100644
--- a/compose/service.py
+++ b/compose/service.py
@@ -45,6 +45,7 @@ from .const import LABEL_VERSION
from .const import NANOCPUS_SCALE
from .const import WINDOWS_LONGPATH_PREFIX
from .container import Container
+from .errors import CompletedUnsuccessfully
from .errors import HealthCheckFailed
from .errors import NoHealthCheckConfigured
from .errors import OperationFailedError
@@ -112,6 +113,7 @@ HOST_CONFIG_KEYS = [
CONDITION_STARTED = 'service_started'
CONDITION_HEALTHY = 'service_healthy'
+CONDITION_COMPLETED_SUCCESSFULLY = 'service_completed_successfully'
class BuildError(Exception):
@@ -753,6 +755,8 @@ class Service:
configs[svc] = lambda s: True
elif config['condition'] == CONDITION_HEALTHY:
configs[svc] = lambda s: s.is_healthy()
+ elif config['condition'] == CONDITION_COMPLETED_SUCCESSFULLY:
+ configs[svc] = lambda s: s.is_completed_successfully()
else:
# The config schema already prevents this, but it might be
# bypassed if Compose is called programmatically.
@@ -1304,6 +1308,21 @@ class Service:
raise HealthCheckFailed(ctnr.short_id)
return result
+ def is_completed_successfully(self):
+ """ Check that all containers for this service has completed successfully
+ Returns false if at least one container does not exited and
+ raises CompletedUnsuccessfully exception if at least one container
+ exited with non-zero exit code.
+ """
+ result = True
+ for ctnr in self.containers(stopped=True):
+ ctnr.inspect()
+ if ctnr.get('State.Status') != 'exited':
+ result = False
+ elif ctnr.exit_code != 0:
+ raise CompletedUnsuccessfully(ctnr.short_id, ctnr.exit_code)
+ return result
+
def _parse_proxy_config(self):
client = self.client
if 'proxies' not in client._general_configs: