Skip to content

Commit

Permalink
Add network->enable feature to compose file (#47)
Browse files Browse the repository at this point in the history
* Add network->enable feature to compose file
Signed-off-by: Paulo Almeida <paulo.almeidarodenas@niwa.co.nz>
  • Loading branch information
PauloMigAlmeida committed Oct 1, 2021
1 parent 443d64b commit 4c691eb
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ and **Merged pull requests**. Critical items to know are:
The versions coincide with releases on pypi.

## [0.0.x](https://github.com/singularityhub/singularity-compose/tree/master) (0.0.x)
- add network->enable option on composer file (0.1.11)
- add network->allocate_ip option on composer file (0.1.10)
- version 2.0 of the spec with added fakeroot network, start, exec, and run options (0.1.0)
- stop option added (equivalent functionality to down)
Expand Down
23 changes: 22 additions & 1 deletion docs/spec/spec-2.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ as a network (start) option (you might still be able to use it as a build option

## Network Group

### Allocate IP Address

By default `singularity-compose` will allocate an IP address for every instance in
the listed yaml file. Binding an IP address to a process requires `sudo` so in certain
scenarios in which access to a privileged user isn't an option, you might want to tell
Expand All @@ -107,7 +109,7 @@ The example below will run a container that exposes the port `5432` to the host.
```yaml
instance1:
...
network:
network:
allocate_ip: true | false
ports:
- 5432:5432
Expand All @@ -129,6 +131,25 @@ To allow fakeroot to bind ports without sudo you need to execute this:
echo "allow net networks = bridge, fakeroot" >> /etc/singularity/singularity.conf
```

### Enable/Disable Network

By default `singularity-compose` will always append `--net` to command to be executed in which it
will prompt for either having `--network=none` or `--fakeroot` added.

Depending on your environment's configuration and isolation requirements you may want to be able
to instruct `singularity-compose` not to append `--net` or any network-related params to the command
sent to singularity CLI.

The example below will disable the network features:

```yaml
instance1:
...
network:
enable: true | false
```


## Start Group

Startscript options generally include those for networking, and any other flags
Expand Down
11 changes: 6 additions & 5 deletions scompose/project/instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,9 @@ def set_network(self, params):
"""set network from the recipe to be used"""
self.network = params.get("network", {})

# if not specified, set the default value for allocate_ip property
if "allocate_ip" not in self.network:
self.network["allocate_ip"] = True
# if not specified, set the default value for the property
for key in ["enable", "allocate_ip"]:
self.network[key] = self.network.get(key, True)

def set_ports(self, params):
"""set ports from the recipe to be used"""
Expand Down Expand Up @@ -541,8 +541,9 @@ def create(self, ip_address=None, sudo=False, writable_tmpfs=False):
# Volumes
options += self._get_bind_commands()

# Ports
options += self._get_network_commands(ip_address)
# Network configuration + Ports
if self.network["enable"]:
options += self._get_network_commands(ip_address)

# Hostname
options += ["--hostname", self.name]
Expand Down
2 changes: 1 addition & 1 deletion scompose/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"""

__version__ = "0.1.10"
__version__ = "0.1.11"
AUTHOR = "Vanessa Sochat"
AUTHOR_EMAIL = "vsoch@users.noreply.github.com"
NAME = "singularity-compose"
Expand Down

0 comments on commit 4c691eb

Please sign in to comment.