From c98f0869b346ae38eef2e6e3f678023b2f372b2c Mon Sep 17 00:00:00 2001 From: DDSRem <73049927+DDSRem@users.noreply.github.com> Date: Tue, 9 Jul 2024 10:36:35 +0800 Subject: [PATCH 1/6] feat: directory mounting supports bind and volume modes --- runlike/inspector.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/runlike/inspector.py b/runlike/inspector.py index 80af8c4..8f0c703 100644 --- a/runlike/inspector.py +++ b/runlike/inspector.py @@ -117,6 +117,19 @@ def parse_ports(self): self.options.append(f"{option_part}{hostname_part}{host_port_part}{container_port}{protocol_part}") + def parse_volumes(self): + mounts = self.get_container_fact("Mounts") + for mount in mounts: + if mount["Type"] == "volume": + volume_format = f'{mount["Name"]}:{mount["Destination"]}' + else: + volume_format = f'{mount["Source"]}:{mount["Destination"]}' + if mount.get("RW"): + volume_format += ':rw' + else: + volume_format += ':ro' + self.options.append(f"--volume {volume_format}") + def parse_links(self): links = self.get_container_fact("HostConfig.Links") link_options = set() @@ -233,9 +246,9 @@ def format_cli(self): self.parse_pid() self.parse_cpuset() + self.parse_volumes() + self.multi_option("Config.Env", "env") - self.multi_option("HostConfig.Binds", "volume") - self.multi_option("Config.Volumes", "volume") self.multi_option("HostConfig.VolumesFrom", "volumes-from") self.multi_option("HostConfig.CapAdd", "cap-add") self.multi_option("HostConfig.CapDrop", "cap-drop") From 1e54ce30ba09f8aafca63e11c25f48161794b2e5 Mon Sep 17 00:00:00 2001 From: DDSRem <73049927+DDSRem@users.noreply.github.com> Date: Tue, 9 Jul 2024 14:52:28 +0800 Subject: [PATCH 2/6] fix: try to solve CI error --- test_runlike.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test_runlike.py b/test_runlike.py index 87fe371..9f68842 100644 --- a/test_runlike.py +++ b/test_runlike.py @@ -60,10 +60,10 @@ def test_udp_with_host_port_and_ip(self): def test_host_volumes(self): cur_dir = os.path.dirname(os.path.realpath(__file__)) - self.expect_substr("--volume=%s:/workdir" % pipes.quote(cur_dir)) + self.expect_substr("--volume %s:/workdir:rw" % pipes.quote(cur_dir)) def test_no_host_volume(self): - self.expect_substr('--volume=/random_volume') + self.expect_substr('--volume=/random_volume:rw') def test_tty(self): self.expect_substr('-t \\') From f6a62a3e5bbc3484d249223cb13ab3f2ae6b99da Mon Sep 17 00:00:00 2001 From: DDSRem <73049927+DDSRem@users.noreply.github.com> Date: Tue, 9 Jul 2024 14:58:59 +0800 Subject: [PATCH 3/6] fix: try to solve ci error --- test_runlike.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test_runlike.py b/test_runlike.py index 9f68842..34ff507 100644 --- a/test_runlike.py +++ b/test_runlike.py @@ -63,7 +63,7 @@ def test_host_volumes(self): self.expect_substr("--volume %s:/workdir:rw" % pipes.quote(cur_dir)) def test_no_host_volume(self): - self.expect_substr('--volume=/random_volume:rw') + self.expect_substr(':/random_volume:rw') def test_tty(self): self.expect_substr('-t \\') From 7177cbef9779e1e70af20d3ec163b60d6fbbf4ae Mon Sep 17 00:00:00 2001 From: DDSRem <73049927+DDSRem@users.noreply.github.com> Date: Tue, 9 Jul 2024 15:14:18 +0800 Subject: [PATCH 4/6] fix: test error --- test_runlike.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/test_runlike.py b/test_runlike.py index 34ff507..29d2a46 100644 --- a/test_runlike.py +++ b/test_runlike.py @@ -82,7 +82,9 @@ def test_restart_with_max(self): self.expect_substr('--restart=on-failure:3 \\', 3) def test_restart_not_present(self): - self.dont_expect_substr('--restart', 4) + # If the restart policy is not set, the default value is no. + # self.dont_expect_substr('--restart', 4) + self.expect_substr('--restart=no \\') def test_hostname(self): self.expect_substr('--hostname=Essos \\') @@ -91,7 +93,9 @@ def test_hostname_not_present(self): self.dont_expect_substr('--hostname \\', 2) def test_network_mode(self): - self.dont_expect_substr('--network', 1) + # When no network mode is set, bridge is used by default + # self.dont_expect_substr('--network', 1) + self.expect_substr('--network=bridge', 1) self.expect_substr('--network=host', 2) self.expect_substr('--network=runlike_fixture_bridge', 3) From 0e38e372c13f6f7e004c38436f71d285378a6e35 Mon Sep 17 00:00:00 2001 From: DDSRem <73049927+DDSRem@users.noreply.github.com> Date: Tue, 9 Jul 2024 15:21:13 +0800 Subject: [PATCH 5/6] fix: restart no test failed --- test_runlike.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test_runlike.py b/test_runlike.py index 29d2a46..a4e45f8 100644 --- a/test_runlike.py +++ b/test_runlike.py @@ -84,7 +84,7 @@ def test_restart_with_max(self): def test_restart_not_present(self): # If the restart policy is not set, the default value is no. # self.dont_expect_substr('--restart', 4) - self.expect_substr('--restart=no \\') + self.expect_substr('--restart=no \\', 4) def test_hostname(self): self.expect_substr('--hostname=Essos \\') From 59c43e41f51dd9d9d5728e1fd42f02a2e01f483d Mon Sep 17 00:00:00 2001 From: DDSRem <73049927+DDSRem@users.noreply.github.com> Date: Tue, 9 Jul 2024 16:08:57 +0800 Subject: [PATCH 6/6] fix --- test_runlike.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/test_runlike.py b/test_runlike.py index a4e45f8..8358b80 100644 --- a/test_runlike.py +++ b/test_runlike.py @@ -83,7 +83,6 @@ def test_restart_with_max(self): def test_restart_not_present(self): # If the restart policy is not set, the default value is no. - # self.dont_expect_substr('--restart', 4) self.expect_substr('--restart=no \\', 4) def test_hostname(self): @@ -94,7 +93,6 @@ def test_hostname_not_present(self): def test_network_mode(self): # When no network mode is set, bridge is used by default - # self.dont_expect_substr('--network', 1) self.expect_substr('--network=bridge', 1) self.expect_substr('--network=host', 2) self.expect_substr('--network=runlike_fixture_bridge', 3)