Skip to content

Commit

Permalink
Add add-host support.
Browse files Browse the repository at this point in the history
  • Loading branch information
anryko authored and lavie committed Oct 18, 2018
1 parent 95df1e9 commit 4b4ea54
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 1 deletion.
2 changes: 2 additions & 0 deletions fixtures.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ docker run -d --name runlike_fixture1 \
--device=/dev/null:/dev/null:r \
--label com.example.group="one" \
--label com.example.environment="test" \
--add-host hostname2:127.0.0.2 \
--add-host hostname3:127.0.0.3 \
--log-driver=fluentd \
--log-opt fluentd-async-connect=true \
--log-opt tag=docker.runlike \
Expand Down
2 changes: 1 addition & 1 deletion runlike/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.5.0"
__version__ = "0.5.1"
5 changes: 5 additions & 0 deletions runlike/inspector.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,10 @@ def parse_log(self):
log_options.add('--log-opt %s=%s' % (key, value))
self.options += list(log_options)

def parse_extra_hosts(self):
hosts = self.get_fact("HostConfig.ExtraHosts") or []
self.options += ['--add-host %s' % host for host in hosts]

def format_cli(self):
self.output = "docker run "

Expand Down Expand Up @@ -181,6 +185,7 @@ def format_cli(self):
self.parse_devices()
self.parse_labels()
self.parse_log()
self.parse_extra_hosts()

stdout_attached = self.get_fact("Config.AttachStdout")
if not stdout_attached:
Expand Down
7 changes: 7 additions & 0 deletions test_runlike.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,13 @@ def test_one_label(self):
def test_labels_not_present(self):
self.dont_expect_substr('--label', 3)

def test_extra_hosts(self):
self.expect_substr('--add-host hostname2:127.0.0.2 \\', 1)
self.expect_substr('--add-host hostname3:127.0.0.3 \\', 1)

def test_extra_hosts_not_present(self):
self.dont_expect_substr('--add-host', 2)

def test_log_driver_default_no_opts(self):
self.dont_expect_substr('--log-driver', 2)
self.dont_expect_substr('--log-opt', 2)
Expand Down

0 comments on commit 4b4ea54

Please sign in to comment.