Skip to content

Commit 69adaa1

Browse files
committed
adding support for custom network args
Signed-off-by: vsoch <vsoch@users.noreply.github.com>
1 parent e301c95 commit 69adaa1

File tree

10 files changed

+68
-21
lines changed

10 files changed

+68
-21
lines changed

CHANGELOG.md

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

1616
## [0.1.x](https://github.com/singularityhub/singularity-compose/tree/master) (0.1.x)
17+
- support for network args (0.1.19)
18+
- allow for background run commands (run->background:true) 0.1.18
1719
- add support for instance replicas (0.1.17)
1820
- fix check command validation (0.1.16)
1921
- fix a bug triggered when using startoptions in conjunction with network=false (0.1.15)

docs/spec/spec-2.0.md

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ INFO: Cleaning up image...
127127

128128
To allow fakeroot to bind ports without sudo you need to execute this:
129129

130-
```
130+
```bash
131131
echo "allow net networks = bridge, fakeroot" >> /etc/singularity/singularity.conf
132132
```
133133

@@ -149,6 +149,41 @@ The example below will disable the network features:
149149
enable: true | false
150150
```
151151

152+
### Custom Network
153+
154+
As of version 0.1.19 we have support for custom network args, and a full example of using a custom network
155+
[here](https://github.com/singularityhub/singularity-compose-examples/tree/master/v2.0/custom-network).
156+
To summarize, let's say you start with this configuration at `/usr/local/etc/singularity/network/50_static-redis.conflist`:
157+
158+
```yaml
159+
version: "2.0"
160+
instances:
161+
cg-cache:
162+
name: redis
163+
run:
164+
background: true
165+
build:
166+
context: .
167+
recipe: redis.def
168+
start:
169+
background: true
170+
options:
171+
- "env-file=./env-file.sh"
172+
command: redis-server --bind 0.0.0.0 --requirepass ${REDIS_PASSWORD}
173+
volumes:
174+
- ./env-file.sh:/.singularity.d/env/env-file.sh
175+
network:
176+
enable: true
177+
allocate_ip: true
178+
179+
# If network args are provided, --network none is not used
180+
args:
181+
- '"portmap=6379:6379/tcp"'
182+
ports:
183+
- 6379:6379
184+
```
185+
186+
The addition is support for ``--network-args`` and the custom network (the portmap) that you've defined above.
152187

153188
## Start Group
154189

scompose/client/__init__.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def get_parser():
9191
)
9292

9393
# print version and exit
94-
version = subparsers.add_parser("version", help="show software version")
94+
subparsers.add_parser("version", help="show software version")
9595

9696
# Build
9797

@@ -112,8 +112,7 @@ def get_parser():
112112
)
113113

114114
# Config
115-
116-
config = subparsers.add_parser("config", help="Validate and view the compose file")
115+
subparsers.add_parser("config", help="Validate and view the compose file")
117116

118117
# Create (assumes built already), Up (will also build, if able)
119118

@@ -189,7 +188,7 @@ def get_parser():
189188
action="store_true",
190189
)
191190

192-
ps = subparsers.add_parser("ps", help="list instances")
191+
subparsers.add_parser("ps", help="list instances")
193192

194193
# Add list of names
195194
for sub in [build, create, down, logs, up, restart, stop]:

scompose/config/schema.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
99
"""
1010

11-
import os
1211
import sys
1312

1413
from jsonschema.exceptions import ValidationError
@@ -57,6 +56,8 @@ def validate_config(filepath):
5756
"properties": {
5857
"allocate_ip": {"type": "boolean"},
5958
"enable": {"type": "boolean"},
59+
# --network-args
60+
"args": string_list,
6061
},
6162
}
6263

scompose/project/instance.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import os
1717
import platform
1818
import re
19-
import time
2019

2120

2221
class Instance:
@@ -174,13 +173,17 @@ def set_network(self, params):
174173
self.network[key] = self.network.get(key, True)
175174

176175
def set_ports(self, params):
177-
"""set ports from the recipe to be used"""
176+
"""
177+
Set ports from the recipe to be used
178+
"""
178179
self.ports = params.get("ports", [])
179180

180181
# Commands
181182

182183
def set_start(self, params):
183-
"""set arguments to the startscript"""
184+
"""
185+
Set arguments to the startscript
186+
"""
184187
start = params.get("start", {})
185188
self.args = start.get("args", "")
186189
self.start_opts = [
@@ -211,6 +214,13 @@ def _get_command_opts(self, group):
211214
"""
212215
return ["--%s" % opt if len(opt) > 1 else "-%s" % opt for opt in group]
213216

217+
@property
218+
def network_args(self):
219+
"""
220+
Return a list of network args.
221+
"""
222+
return self.params.get("network", {}).get("args", [])
223+
214224
def _get_network_commands(self, ip_address=None):
215225
"""
216226
Take a list of ports, return the list of --network-args to
@@ -221,8 +231,12 @@ def _get_network_commands(self, ip_address=None):
221231
# Fakeroot means not needing sudo
222232
fakeroot = "--fakeroot" in self.start_opts or "-f" in self.start_opts
223233

224-
# If not sudo or fakeroot, we need --network none
225-
if not self.sudo and not fakeroot:
234+
# Add all network args
235+
network_args = self.network_args
236+
for arg in network_args:
237+
ports += ["--network-args", arg]
238+
239+
if not network_args and (not self.sudo and not fakeroot):
226240
ports += ["--network", "none"]
227241

228242
for pair in self.ports:

scompose/project/project.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ def get_instance_names(self):
6161
return names
6262

6363
def set_filename(self, filename):
64-
"""Set the filename to read the recipe from.
64+
"""
65+
Set the filename to read the recipe from.
6566
6667
If not provided, defaults to singularity-compose.yml. The working directory
6768
is set to be the directory name of the configuration file.
@@ -297,7 +298,8 @@ def get_bridge_address(self, name="sbr0"):
297298
return bridge_address
298299

299300
def create_hosts(self, lookup):
300-
"""create a hosts file to bind to all containers, where we define the
301+
"""
302+
Create a hosts file to bind to all containers, where we define the
301303
correct hostnames to correspond with the ip addresses created.
302304
Note: This function is terrible. Singularity should easily expose
303305
these addresses. See issue here:
@@ -503,8 +505,7 @@ def _create(
503505
bridge: the bridge ip address to use for networking, and generating
504506
addresses for the individual containers.
505507
see /usr/local/etc/singularity/network/00_bridge.conflist
506-
no_resolv: if True, don't create and bind a resolv.conf with Google
507-
nameservers.
508+
no_resolv: if True, don't create and bind a resolv.conf.
508509
"""
509510
# If no names provided, we create all
510511
names = names or self.get_instance_names()

scompose/tests/test_client.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
from scompose.utils import run_command
1111
from time import sleep
1212
import requests
13-
import pytest
1413
import os
1514

1615

scompose/tests/test_command_args.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,8 @@
88

99
from scompose.logger import bot
1010
from scompose.project import Project
11-
from scompose.utils import run_command
1211
from time import sleep
1312
import shutil
14-
import pytest
1513
import os
1614

1715
here = os.path.dirname(os.path.abspath(__file__))

scompose/tests/test_depends_on.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,8 @@
88

99
from scompose.logger import bot
1010
from scompose.project import Project
11-
from scompose.utils import run_command
1211
from time import sleep
1312
import shutil
14-
import pytest
1513
import os
1614

1715
here = os.path.dirname(os.path.abspath(__file__))

scompose/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
99
"""
1010

11-
__version__ = "0.1.17"
11+
__version__ = "0.1.19"
1212
AUTHOR = "Vanessa Sochat"
1313
AUTHOR_EMAIL = "vsoch@users.noreply.github.com"
1414
NAME = "singularity-compose"

0 commit comments

Comments
 (0)