Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: directory mounting supports bind and volume modes #115

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions runlike/inspector.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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")
Expand Down
12 changes: 8 additions & 4 deletions test_runlike.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(':/random_volume:rw')
DDSDerek marked this conversation as resolved.
Show resolved Hide resolved

def test_tty(self):
self.expect_substr('-t \\')
Expand All @@ -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)
DDSDerek marked this conversation as resolved.
Show resolved Hide resolved
self.expect_substr('--restart=no \\', 4)

def test_hostname(self):
self.expect_substr('--hostname=Essos \\')
Expand All @@ -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)
DDSDerek marked this conversation as resolved.
Show resolved Hide resolved
self.expect_substr('--network=bridge', 1)
self.expect_substr('--network=host', 2)
self.expect_substr('--network=runlike_fixture_bridge', 3)

Expand Down
Loading