Skip to content

Commit

Permalink
process optional use_host_network flag
Browse files Browse the repository at this point in the history
  • Loading branch information
hktudock committed Jul 27, 2022
1 parent 38b83ae commit 94e3299
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 8 deletions.
1 change: 1 addition & 0 deletions riptide_engine_docker/cmd_detached.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def cmd_detached(client: DockerClient, project: 'Project', command: 'Command', r
)

builder.set_name(get_container_name(project["name"]))
# network_mode host not supported atm
builder.set_network(get_network_name(project["name"]))

builder.set_env(EENV_NO_STDOUT_REDIRECT, "yes")
Expand Down
31 changes: 23 additions & 8 deletions riptide_engine_docker/container_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ def __init__(self, image: str, command: Union[List, str, None]) -> None:
self.hostname = None
self.allow_full_memlock = False
self.cap_sys_admin = False
self.use_host_network = False

self.on_linux = platform.system().lower().startswith('linux')
self.set_env(EENV_ON_LINUX, "1" if self.on_linux else "0")
Expand Down Expand Up @@ -114,6 +115,10 @@ def set_network(self, network: str):
self.network = network
return self

def set_use_host_network(self, flag: bool):
self.use_host_network = flag
return self

def set_name(self, name: str):
self.name = name
return self
Expand Down Expand Up @@ -282,8 +287,14 @@ def build_docker_api(self) -> dict:

if self.name:
args['name'] = self.name
if self.network:
args['network'] = self.network

if self.use_host_network:
args['network_mode'] = 'host'
else:
if self.network:
args['network'] = self.network
args['ports'] = self.ports

if self.entrypoint:
args['entrypoint'] = [self.entrypoint]
if self.work_dir:
Expand All @@ -307,7 +318,7 @@ def build_docker_api(self) -> dict:
args['environment'][EENV_NAMED_VOLUMES] = ':'.join(self.named_volumes_in_cnt)

args['labels'] = self.labels
args['ports'] = self.ports

args['mounts'] = list(self.mounts.values())

return args
Expand All @@ -321,8 +332,15 @@ def build_docker_cli(self) -> List[str]:
]
if self.name:
shell += ["--name", self.name]
if self.network:
shell += ["--network", self.network]

if self.use_host_network:
shell += ["--network", 'host']
else:
if self.network:
shell += ["--network", self.network]
for container, host in self.ports.items():
shell += ['-p', str(host) + ':' + str(container)]

if self.entrypoint:
shell += ["--entrypoint", self.entrypoint]
if self.work_dir:
Expand All @@ -342,9 +360,6 @@ def build_docker_cli(self) -> List[str]:
for key, value in self.labels.items():
shell += ['--label', key + '=' + value]

for container, host in self.ports.items():
shell += ['-p', str(host) + ':' + str(container)]

# Mac: Add delegated
mac_add = ',consistency=delegated' if platform.system().lower().startswith('mac') else ''
for mount in self.mounts.values():
Expand Down
3 changes: 3 additions & 0 deletions riptide_engine_docker/fg.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ def fg(client, project: Project, container_name: str, exec_object: Union[Command
builder.set_name(container_name)
builder.set_network(get_network_name(project["name"]))

if "use_host_network" in exec_object and exec_object["use_host_network"]:
builder.set_use_host_network(True)

builder.set_env(EENV_NO_STDOUT_REDIRECT, "yes")
builder.set_args(arguments)

Expand Down

0 comments on commit 94e3299

Please sign in to comment.