From 6af7a2d691648781252b6c7d7b1471fd052b7496 Mon Sep 17 00:00:00 2001 From: Povilas Kanapickas Date: Fri, 8 Mar 2024 14:45:22 +0200 Subject: [PATCH] tests: Optimize speed by using dumb-init to handle SIGTERM signal Signed-off-by: Povilas Kanapickas --- tests/__init__.py | 12 ++++++++++++ tests/base_image/Dockerfile | 6 ++++++ tests/deps/docker-compose.yaml | 12 ++++++------ tests/exit-from/docker-compose.yaml | 12 ++++++------ .../extends_w_empty_service/common-services.yml | 2 +- tests/extends_w_empty_service/docker-compose.yml | 2 +- .../sub/docker/example/Dockerfile | 2 +- tests/include/docker-compose.base.yaml | 4 ++-- tests/ports/docker-compose.yml | 8 ++++---- tests/profile/docker-compose.yml | 14 +++++++------- tests/test_podman_compose_include.py | 2 +- tests/test_podman_compose_tests.py | 3 ++- tests/vol/docker-compose.yaml | 16 ++++++++-------- 13 files changed, 57 insertions(+), 38 deletions(-) create mode 100644 tests/base_image/Dockerfile diff --git a/tests/__init__.py b/tests/__init__.py index e69de29b..dbd5d2fc 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -0,0 +1,12 @@ +import os +import subprocess + + +def create_base_test_image(): + subprocess.check_call( + ['podman', 'build', '-t', 'nopush/podman-compose-test', '.'], + cwd=os.path.join(os.path.dirname(__file__), "base_image"), + ) + + +create_base_test_image() diff --git a/tests/base_image/Dockerfile b/tests/base_image/Dockerfile new file mode 100644 index 00000000..5fd76c33 --- /dev/null +++ b/tests/base_image/Dockerfile @@ -0,0 +1,6 @@ +FROM docker.io/library/debian:bookworm-slim +RUN apt-get update \ + && apt-get install -y \ + dumb-init \ + busybox \ + wget diff --git a/tests/deps/docker-compose.yaml b/tests/deps/docker-compose.yaml index 77993235..cb0a9ee3 100644 --- a/tests/deps/docker-compose.yaml +++ b/tests/deps/docker-compose.yaml @@ -1,22 +1,22 @@ version: "3.7" services: web: - image: busybox - command: ["/bin/busybox", "httpd", "-f", "-h", "/etc/", "-p", "8000"] + image: nopush/podman-compose-test + command: ["dumb-init", "/bin/busybox", "httpd", "-f", "-h", "/etc/", "-p", "8000"] tmpfs: - /run - /tmp sleep: - image: busybox - command: ["/bin/busybox", "sh", "-c", "sleep 3600"] + image: nopush/podman-compose-test + command: ["dumb-init", "/bin/busybox", "sh", "-c", "sleep 3600"] depends_on: - "web" tmpfs: - /run - /tmp sleep2: - image: busybox - command: ["/bin/busybox", "sh", "-c", "sleep 3600"] + image: nopush/podman-compose-test + command: ["dumb-init", "/bin/busybox", "sh", "-c", "sleep 3600"] depends_on: - sleep tmpfs: diff --git a/tests/exit-from/docker-compose.yaml b/tests/exit-from/docker-compose.yaml index cfc38972..a286b2a0 100644 --- a/tests/exit-from/docker-compose.yaml +++ b/tests/exit-from/docker-compose.yaml @@ -1,20 +1,20 @@ version: "3" services: too_long: - image: busybox - command: ["/bin/busybox", "sh", "-c", "sleep 3600; exit 0"] + image: nopush/podman-compose-test + command: ["dumb-init", "/bin/busybox", "sh", "-c", "sleep 3600; exit 0"] tmpfs: - /run - /tmp sh1: - image: busybox - command: ["/bin/busybox", "sh", "-c", "sleep 5; exit 1"] + image: nopush/podman-compose-test + command: ["dumb-init", "/bin/busybox", "sh", "-c", "sleep 1; exit 1"] tmpfs: - /run - /tmp sh2: - image: busybox - command: ["/bin/busybox", "sh", "-c", "sleep 5; exit 2"] + image: nopush/podman-compose-test + command: ["dumb-init", "/bin/busybox", "sh", "-c", "sleep 1; exit 2"] tmpfs: - /run - /tmp diff --git a/tests/extends_w_empty_service/common-services.yml b/tests/extends_w_empty_service/common-services.yml index b7deb2c8..b1138a50 100644 --- a/tests/extends_w_empty_service/common-services.yml +++ b/tests/extends_w_empty_service/common-services.yml @@ -2,6 +2,6 @@ services: webapp_default: webapp_special: - image: busybox + image: nopush/podman-compose-test volumes: - "/data" diff --git a/tests/extends_w_empty_service/docker-compose.yml b/tests/extends_w_empty_service/docker-compose.yml index d5414e30..72e2dc7c 100644 --- a/tests/extends_w_empty_service/docker-compose.yml +++ b/tests/extends_w_empty_service/docker-compose.yml @@ -1,7 +1,7 @@ version: "3" services: web: - image: busybox + image: nopush/podman-compose-test extends: file: common-services.yml service: webapp_default diff --git a/tests/extends_w_file_subdir/sub/docker/example/Dockerfile b/tests/extends_w_file_subdir/sub/docker/example/Dockerfile index 14b3ba54..b6882dab 100644 --- a/tests/extends_w_file_subdir/sub/docker/example/Dockerfile +++ b/tests/extends_w_file_subdir/sub/docker/example/Dockerfile @@ -1 +1 @@ -FROM busybox as base +FROM nopush/podman-compose-test as base diff --git a/tests/include/docker-compose.base.yaml b/tests/include/docker-compose.base.yaml index e356a149..fe80e088 100644 --- a/tests/include/docker-compose.base.yaml +++ b/tests/include/docker-compose.base.yaml @@ -2,6 +2,6 @@ version: '3.6' services: web: - image: busybox - command: ["/bin/busybox", "httpd", "-f", "-h", ".", "-p", "8003"] + image: nopush/podman-compose-test + command: ["dumb-init", "/bin/busybox", "httpd", "-f", "-h", ".", "-p", "8003"] diff --git a/tests/ports/docker-compose.yml b/tests/ports/docker-compose.yml index 68b2e4d4..e89bd051 100644 --- a/tests/ports/docker-compose.yml +++ b/tests/ports/docker-compose.yml @@ -1,18 +1,18 @@ version: "3" services: web1: - image: busybox + image: nopush/podman-compose-test hostname: web1 - command: ["/bin/busybox", "httpd", "-f", "-h", "/var/www/html", "-p", "8001"] + command: ["dumb-init", "/bin/busybox", "httpd", "-f", "-h", "/var/www/html", "-p", "8001"] working_dir: /var/www/html ports: - 8001:8001 volumes: - ./test1.txt:/var/www/html/index.txt:ro,z web2: - image: busybox + image: nopush/podman-compose-test hostname: web2 - command: ["/bin/busybox", "httpd", "-f", "-h", "/var/www/html", "-p", "8002"] + command: ["dumb-init", "/bin/busybox", "httpd", "-f", "-h", "/var/www/html", "-p", "8002"] working_dir: /var/www/html ports: - 8002:8002 diff --git a/tests/profile/docker-compose.yml b/tests/profile/docker-compose.yml index 0a2a7cd6..fe84fce6 100644 --- a/tests/profile/docker-compose.yml +++ b/tests/profile/docker-compose.yml @@ -1,24 +1,24 @@ version: "3" services: default-service: - image: busybox - command: ["/bin/busybox", "httpd", "-f", "-h", "/etc/", "-p", "8000"] + image: nopush/podman-compose-test + command: ["dumb-init", "/bin/busybox", "httpd", "-f", "-h", "/etc/", "-p", "8000"] tmpfs: - /run - /tmp service-1: - image: busybox - command: ["/bin/busybox", "httpd", "-f", "-h", "/etc/", "-p", "8000"] + image: nopush/podman-compose-test + command: ["dumb-init", "/bin/busybox", "httpd", "-f", "-h", "/etc/", "-p", "8000"] tmpfs: - /run - /tmp profiles: - profile-1 service-2: - image: busybox - command: ["/bin/busybox", "httpd", "-f", "-h", "/etc/", "-p", "8000"] + image: nopush/podman-compose-test + command: ["dumb-init", "/bin/busybox", "httpd", "-f", "-h", "/etc/", "-p", "8000"] tmpfs: - /run - /tmp profiles: - - profile-2 \ No newline at end of file + - profile-2 diff --git a/tests/test_podman_compose_include.py b/tests/test_podman_compose_include.py index 7aae8ae7..5ca3964b 100644 --- a/tests/test_podman_compose_include.py +++ b/tests/test_podman_compose_include.py @@ -49,7 +49,7 @@ def test_podman_compose_include(self): self.run_subprocess_assert_returncode(command_up) out, _ = self.run_subprocess_assert_returncode(command_check_container) - self.assertEqual(out, b'"docker.io/library/busybox:latest"\n') + self.assertEqual(out, b'"localhost/nopush/podman-compose-test:latest"\n') # Get container ID to remove it out, _ = self.run_subprocess_assert_returncode(command_container_id) self.assertNotEqual(out, b"") diff --git a/tests/test_podman_compose_tests.py b/tests/test_podman_compose_tests.py index de1f019c..2f4b4d98 100644 --- a/tests/test_podman_compose_tests.py +++ b/tests/test_podman_compose_tests.py @@ -155,7 +155,8 @@ def test_down_with_orphans(self): "run", "--rm", "-d", - "busybox", + "nopush/podman-compose-test", + "dumb-init", "/bin/busybox", "httpd", "-f", diff --git a/tests/vol/docker-compose.yaml b/tests/vol/docker-compose.yaml index 5dc8d250..85a60d61 100644 --- a/tests/vol/docker-compose.yaml +++ b/tests/vol/docker-compose.yaml @@ -1,8 +1,8 @@ version: "3" services: web: - image: busybox - command: ["/bin/busybox", "httpd", "-f", "-h", "/var/www/html", "-p", "8000"] + image: nopush/podman-compose-test + command: ["dumb-init", "/bin/busybox", "httpd", "-f", "-h", "/var/www/html", "-p", "8000"] working_dir: /var/www/html restart: always volumes: @@ -11,21 +11,21 @@ services: - /run - /tmp web1: - image: busybox - command: ["/bin/busybox", "httpd", "-f", "-h", "/var/www/html", "-p", "8001"] + image: nopush/podman-compose-test + command: ["dumb-init", "/bin/busybox", "httpd", "-f", "-h", "/var/www/html", "-p", "8001"] restart: unless-stopped working_dir: /var/www/html volumes: - myvol1:/var/www/html:ro,z web2: - image: busybox - command: ["/bin/busybox", "httpd", "-f", "-h", "/var/www/html", "-p", "8002"] + image: nopush/podman-compose-test + command: ["dumb-init", "/bin/busybox", "httpd", "-f", "-h", "/var/www/html", "-p", "8002"] working_dir: /var/www/html volumes: - myvol2:/var/www/html:ro web3: - image: busybox - command: ["/bin/busybox", "httpd", "-f", "-h", "/var/www/html", "-p", "8003"] + image: nopush/podman-compose-test + command: ["dumb-init", "/bin/busybox", "httpd", "-f", "-h", "/var/www/html", "-p", "8003"] working_dir: /var/www/html volumes: - myvol2:/var/www/html