Skip to content

Commit b184871

Browse files
authored
Merge pull request #12 from singularityhub/fix/exec-non-sudo-network
Fix/exec non sudo network
2 parents a179232 + 37538ff commit b184871

File tree

5 files changed

+17
-6
lines changed

5 files changed

+17
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ and **Merged pull requests**. Critical items to know are:
1414
The versions coincide with releases on pypi.
1515

1616
## [0.0.x](https://github.com/singularityhub/singularity-compose/tree/master) (0.0.x)
17+
- when not using sudo, need to set --network=none, and catching exec error (0.0.12)
1718
- pyaml version should be for newer kind, and still check for attribute (0.0.11)
1819
- alpha release with simple (single container) working example (0.0.1)
1920
- dummy release (0.0.0)

scompose/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@
1616
along with this program. If not, see <https://www.gnu.org/licenses/>.
1717
1818
'''
19+
from .version import __version__

scompose/project/instance.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,11 @@ def _get_network_commands(self, ip_address=None):
154154
ensure they are bound correctly.
155155
'''
156156
ports = ['--net']
157+
158+
# If no sudo, isolates container network with a loopback interface.
159+
if not self.sudo:
160+
ports += ["--network", "none"]
161+
157162
for pair in self.ports:
158163
ports += ['--network-args', '"portmap=%s/tcp"' % pair]
159164

scompose/project/project.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import json
3131
import os
3232
import re
33+
import subprocess
3334
import sys
3435

3536

@@ -267,11 +268,14 @@ def execute(self, name, commands):
267268
if name in self.instances:
268269
instance = self.instances[name]
269270
if instance.exists():
270-
for line in self.client.execute(instance.instance.get_uri(),
271-
command=commands,
272-
stream=True,
273-
sudo=self.sudo):
274-
print(line, end='')
271+
try:
272+
for line in self.client.execute(instance.instance.get_uri(),
273+
command=commands,
274+
stream=True,
275+
sudo=self.sudo):
276+
print(line, end='')
277+
except subprocess.CalledProcessError:
278+
bot.exit('Command had non zero exit status.')
275279

276280
# Logs
277281

scompose/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
1818
'''
1919

20-
__version__ = "0.0.11"
20+
__version__ = "0.0.12"
2121
AUTHOR = 'Vanessa Sochat'
2222
AUTHOR_EMAIL = '[email protected]'
2323
NAME = 'singularity-compose'

0 commit comments

Comments
 (0)