Skip to content

Commit

Permalink
Add an option to setup mountpoints when fetching a plugin
Browse files Browse the repository at this point in the history
Add the option --mountpoints/-M to the fetch subcommand. It gives the
possibility to setup one or many mountpoints at the jail creation of
a plugin, before the initial start. It mimicks the format of the Docker
--volume option: source:destination[:options]

Example:
  iocage fetch -P ./plugin.json -M /mnt/tank/plugin-data:/data:ro
  • Loading branch information
Romain LE DISEZ committed Dec 30, 2021
1 parent ea74589 commit e572531
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
6 changes: 6 additions & 0 deletions iocage_cli/fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,12 @@ def validate_count(ctx, param, value):
'--proxy', '-S', default=None,
help='Provide proxy to use for creating jail'
)
@click.option(
"--mountpoints", "-M", multiple=True,
help="Specify a mountpoint to setup in the jail. Format is "
"source:destination[:options].\n(only applicable if "
"fetching a plugin)"
)
def cli(**kwargs):
"""CLI command that calls fetch_release()"""
release = kwargs.get("release", None)
Expand Down
49 changes: 49 additions & 0 deletions iocage_lib/ioc_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import iocage_lib.ioc_create
import iocage_lib.ioc_destroy
import iocage_lib.ioc_exec
import iocage_lib.ioc_fstab
import iocage_lib.ioc_list
import iocage_lib.ioc_json
import iocage_lib.ioc_start
Expand Down Expand Up @@ -94,6 +95,7 @@ def __init__(
self.plugin_json_path = None
self.plugin = plugin
self.jail = jail
self.mountpoints = kwargs.pop("mountpoints", [])
self.http = kwargs.pop("http", True)
self.hardened = kwargs.pop("hardened", False)
self.date = datetime.datetime.utcnow().strftime("%F")
Expand Down Expand Up @@ -321,6 +323,7 @@ def fetch_plugin(self, props, num, accept_license):

try:
jaildir, _conf, repo_dir = self.__fetch_plugin_create__(props)
self.__fetch_plugin_add_mountpoints__(jaildir)
# As soon as we create the jail, we should write the plugin manifest to jail directory
# This is done to ensure that subsequent starts of the jail make use of the plugin
# manifest as required
Expand Down Expand Up @@ -607,6 +610,52 @@ def __fetch_plugin_create__(self, create_props):

return jaildir, _conf, repo_dir

def __fetch_plugin_add_mountpoints__(self, jaildir):
for mountpoint in self.mountpoints:
fstype = "nullfs"
options = "rw"
dump = "0"
_pass = "0"

parts = mountpoint.split(":")
if len(parts) < 2 or len(parts) > 3:
raise RuntimeError(
f"Ignoring invalid mountpoint `{mountpoint}`, expecting "
"`source:destination[:options]`."
)
else:
source = parts[0].strip()
destination = parts[1].strip()
if len(parts) == 3:
options = parts[2]

if (not source or source[0] != "/"
or not destination or destination[0] != "/"
or not options):
raise RuntimeError(
f"Ignoring invalid mountpoint `{mountpoint}`, source and "
"destination must be absolute path, options cannot be "
"empty."
)

destination = f"{jaildir}/root{destination}"
if destination and len(destination) > 88:
iocage_lib.ioc_common.logit(
{
"level":
"WARNING",
"message":
"The destination's mountpoint exceeds 88 "
"characters, this may cause failure!"
},
silent=self.silent)

os.makedirs(destination, exist_ok=True)
iocage_lib.ioc_fstab.IOCFstab(
self.jail, "add", source, destination,
fstype, options, dump, _pass
)

def __fetch_plugin_install_packages__(self, jaildir, conf, pkg_repos,
create_props, repo_dir):
"""Attempts to start the jail and install the packages"""
Expand Down

0 comments on commit e572531

Please sign in to comment.