Skip to content

Commit

Permalink
Merge branch 'master' of github.com:DDS-Derek/runlike into DDS-Derek-…
Browse files Browse the repository at this point in the history
…master
  • Loading branch information
lavie committed Sep 10, 2024
2 parents 2296186 + 59c43e4 commit d24075a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
17 changes: 15 additions & 2 deletions runlike/inspector.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,19 @@ def parse_ports(self):
if self.options[-1] == self.options[-2] : self.options.pop()


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 @@ -241,9 +254,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
9 changes: 6 additions & 3 deletions test_runlike.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,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')

def test_tty(self):
self.expect_substr('-t \\')
Expand All @@ -84,7 +84,8 @@ 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.expect_substr('--restart=no \\', 4)

def test_hostname(self):
self.expect_substr('--hostname=Essos \\')
Expand All @@ -95,6 +96,8 @@ def test_hostname_not_present(self):
def test_network_mode(self):
self.dont_expect_substr('--network=host', 1)
self.dont_expect_substr('--network=runlike_fixture_bridge', 1)
# When no network mode is set, bridge is used by default
self.expect_substr('--network=bridge', 1)
self.expect_substr('--network=host', 2)
self.expect_substr('--network=runlike_fixture_bridge', 3)

Expand Down

0 comments on commit d24075a

Please sign in to comment.