mirror of
https://github.com/containers/podman-compose.git
synced 2024-12-12 09:41:16 +01:00
Merge pull request #1082 from flixman/main
Provide support for conditional dependencies
This commit is contained in:
commit
d9fc8e91f2
1
newsfragments/conditional-dependencies.feature
Normal file
1
newsfragments/conditional-dependencies.feature
Normal file
@ -0,0 +1 @@
|
||||
Added support for honoring the condition in the depends_on section of the service, if stated.
|
File diff suppressed because it is too large
Load Diff
22
tests/integration/deps/docker-compose-conditional-fails.yaml
Normal file
22
tests/integration/deps/docker-compose-conditional-fails.yaml
Normal file
@ -0,0 +1,22 @@
|
||||
version: "3.7"
|
||||
services:
|
||||
web:
|
||||
image: nopush/podman-compose-test
|
||||
command: ["dumb-init", "/bin/busybox", "httpd", "-f", "-h", "/etc/", "-p", "8000"]
|
||||
tmpfs:
|
||||
- /run
|
||||
- /tmp
|
||||
healthcheck:
|
||||
test: ["CMD", "/bin/false"]
|
||||
interval: 10s # Time between health checks
|
||||
timeout: 1s # Time to wait for a response
|
||||
retries: 1 # Number of consecutive failures before marking as unhealthy
|
||||
sleep:
|
||||
image: nopush/podman-compose-test
|
||||
command: ["dumb-init", "/bin/busybox", "sh", "-c", "sleep 3600"]
|
||||
depends_on:
|
||||
web:
|
||||
condition: service_healthy
|
||||
tmpfs:
|
||||
- /run
|
||||
- /tmp
|
@ -0,0 +1,22 @@
|
||||
version: "3.7"
|
||||
services:
|
||||
web:
|
||||
image: nopush/podman-compose-test
|
||||
command: ["dumb-init", "/bin/busybox", "httpd", "-f", "-h", "/etc/", "-p", "8000"]
|
||||
tmpfs:
|
||||
- /run
|
||||
- /tmp
|
||||
healthcheck:
|
||||
test: ["CMD", "wget", "-qO-", "http://localhost:8000/hosts"]
|
||||
interval: 30s # Time between health checks
|
||||
timeout: 5s # Time to wait for a response
|
||||
retries: 3 # Number of consecutive failures before marking as unhealthy
|
||||
sleep:
|
||||
image: nopush/podman-compose-test
|
||||
command: ["dumb-init", "/bin/busybox", "sh", "-c", "sleep 3600"]
|
||||
depends_on:
|
||||
web:
|
||||
condition: service_healthy
|
||||
tmpfs:
|
||||
- /run
|
||||
- /tmp
|
@ -7,11 +7,11 @@ from tests.integration.test_podman_compose import test_path
|
||||
from tests.integration.test_utils import RunSubprocessMixin
|
||||
|
||||
|
||||
def compose_yaml_path():
|
||||
return os.path.join(os.path.join(test_path(), "deps"), "docker-compose.yaml")
|
||||
def compose_yaml_path(suffix=""):
|
||||
return os.path.join(os.path.join(test_path(), "deps"), f"docker-compose{suffix}.yaml")
|
||||
|
||||
|
||||
class TestComposeDeps(unittest.TestCase, RunSubprocessMixin):
|
||||
class TestComposeBaseDeps(unittest.TestCase, RunSubprocessMixin):
|
||||
def test_deps(self):
|
||||
try:
|
||||
output, error = self.run_subprocess_assert_returncode([
|
||||
@ -34,3 +34,48 @@ class TestComposeDeps(unittest.TestCase, RunSubprocessMixin):
|
||||
compose_yaml_path(),
|
||||
"down",
|
||||
])
|
||||
|
||||
|
||||
class TestComposeConditionalDeps(unittest.TestCase, RunSubprocessMixin):
|
||||
def test_deps_succeeds(self):
|
||||
suffix = "-conditional-succeeds"
|
||||
try:
|
||||
output, error = self.run_subprocess_assert_returncode([
|
||||
podman_compose_path(),
|
||||
"-f",
|
||||
compose_yaml_path(suffix),
|
||||
"run",
|
||||
"--rm",
|
||||
"sleep",
|
||||
"/bin/sh",
|
||||
"-c",
|
||||
"wget -O - http://web:8000/hosts",
|
||||
])
|
||||
self.assertIn(b"HTTP request sent, awaiting response... 200 OK", output)
|
||||
self.assertIn(b"deps_web_1", output)
|
||||
finally:
|
||||
self.run_subprocess_assert_returncode([
|
||||
podman_compose_path(),
|
||||
"-f",
|
||||
compose_yaml_path(suffix),
|
||||
"down",
|
||||
])
|
||||
|
||||
def test_deps_fails(self):
|
||||
suffix = "-conditional-fails"
|
||||
try:
|
||||
output, error = self.run_subprocess_assert_returncode([
|
||||
podman_compose_path(),
|
||||
"-f",
|
||||
compose_yaml_path(suffix),
|
||||
"ps",
|
||||
])
|
||||
self.assertNotIn(b"HTTP request sent, awaiting response... 200 OK", output)
|
||||
self.assertNotIn(b"deps_web_1", output)
|
||||
finally:
|
||||
self.run_subprocess_assert_returncode([
|
||||
podman_compose_path(),
|
||||
"-f",
|
||||
compose_yaml_path(suffix),
|
||||
"down",
|
||||
])
|
||||
|
Loading…
Reference in New Issue
Block a user