Merge pull request #1082 from flixman/main

Provide support for conditional dependencies
This commit is contained in:
Povilas Kanapickas 2024-12-02 22:18:53 +02:00 committed by GitHub
commit d9fc8e91f2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 394 additions and 184 deletions

View 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

View 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

View 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", "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

View File

@ -7,11 +7,11 @@ from tests.integration.test_podman_compose import test_path
from tests.integration.test_utils import RunSubprocessMixin from tests.integration.test_utils import RunSubprocessMixin
def compose_yaml_path(): def compose_yaml_path(suffix=""):
return os.path.join(os.path.join(test_path(), "deps"), "docker-compose.yaml") 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): def test_deps(self):
try: try:
output, error = self.run_subprocess_assert_returncode([ output, error = self.run_subprocess_assert_returncode([
@ -34,3 +34,48 @@ class TestComposeDeps(unittest.TestCase, RunSubprocessMixin):
compose_yaml_path(), compose_yaml_path(),
"down", "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",
])