mirror of
https://github.com/projectatomic/atomic.git
synced 2026-02-05 18:45:01 +01:00
syscontainers: allow --system without runc installed
Also change --user to work without bwrap-oci being installed Closes: https://github.com/projectatomic/atomic/issues/866 Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com> Closes: #868 Approved by: rhatdan
This commit is contained in:
committed by
Atomic Bot
parent
92bec330c2
commit
e14343b1fa
@@ -56,27 +56,22 @@ def cli(subparser):
|
||||
help=_("preview the command that %s would execute") % sys.argv[0])
|
||||
installp.add_argument("image", help=_("container image"))
|
||||
if OSTREE_PRESENT:
|
||||
bwrap_oci_available = util.bwrap_oci_available()
|
||||
runc_available = util.runc_available()
|
||||
if bwrap_oci_available or runc_available:
|
||||
system_xor_user = installp.add_mutually_exclusive_group()
|
||||
if bwrap_oci_available:
|
||||
system_xor_user.add_argument("--user", dest="user", action="store_true", default=False,
|
||||
help=_("Flag to specify if user is non-root privileged."))
|
||||
if runc_available:
|
||||
system_xor_user.add_argument("--system", dest="system",
|
||||
action='store_true', default=False,
|
||||
help=_('install a system container'))
|
||||
system_xor_user = installp.add_mutually_exclusive_group()
|
||||
system_xor_user.add_argument("--user", dest="user", action="store_true", default=False,
|
||||
help=_("install the image as an user image."))
|
||||
system_xor_user.add_argument("--system", dest="system",
|
||||
action='store_true', default=False,
|
||||
help=_('install a system container'))
|
||||
installp.add_argument("--rootfs", dest="remote",
|
||||
help=_("choose an existing exploded container/image to use "
|
||||
"its rootfs as a remote, read-only rootfs for the "
|
||||
"container to be installed"))
|
||||
installp.add_argument("--set", dest="setvalues",
|
||||
action='append',
|
||||
help=_("Specify a variable in the VARIABLE=VALUE "
|
||||
help=_("specify a variable in the VARIABLE=VALUE "
|
||||
"form for a system container"))
|
||||
installp.add_argument("args", nargs=argparse.REMAINDER,
|
||||
help=_("Additional arguments appended to the image "
|
||||
help=_("additional arguments appended to the image "
|
||||
"install method"))
|
||||
|
||||
|
||||
|
||||
@@ -184,12 +184,6 @@ class SystemContainers(object):
|
||||
if self.args.system and self.user:
|
||||
raise ValueError("Only root can use --system")
|
||||
|
||||
if not self.user:
|
||||
try:
|
||||
util.check_call([util.RUNC_PATH, "--version"], stdout=DEVNULL)
|
||||
except util.FileNotFound:
|
||||
raise ValueError("Cannot install the container: runc is needed to run system containers")
|
||||
|
||||
image = self._pull_image_to_ostree(repo, image, False)
|
||||
|
||||
if self.get_checkout(name):
|
||||
@@ -210,6 +204,9 @@ class SystemContainers(object):
|
||||
configuration = json.loads(conf.read())
|
||||
except ValueError:
|
||||
raise ValueError("Invalid json in configuration file: {}.".format(conf_path))
|
||||
# empty file, nothing to do here
|
||||
if len(configuration) == 0:
|
||||
return []
|
||||
if not 'root' in configuration or \
|
||||
not 'readonly' in configuration['root'] or \
|
||||
not configuration['root']['readonly']:
|
||||
@@ -230,9 +227,17 @@ class SystemContainers(object):
|
||||
return missing_source_paths
|
||||
|
||||
def _generate_default_oci_configuration(self, destination):
|
||||
conf_path = os.path.join(destination, "config.json")
|
||||
|
||||
# If runc is not installed we are not able to generate the default configuration,
|
||||
# write an empty JSON file
|
||||
if not util.runc_available():
|
||||
with open(conf_path, 'w') as conf:
|
||||
conf.write('{}')
|
||||
return
|
||||
|
||||
args = [util.RUNC_PATH, 'spec']
|
||||
util.subp(args, cwd=destination)
|
||||
conf_path = os.path.join(destination, "config.json")
|
||||
with open(conf_path, 'r') as conf:
|
||||
configuration = json.loads(conf.read())
|
||||
configuration['root']['readonly'] = True
|
||||
@@ -246,7 +251,10 @@ class SystemContainers(object):
|
||||
if self.user:
|
||||
return ["%s '%s'" % (util.BWRAP_OCI_PATH, name), ""]
|
||||
|
||||
version = str(util.check_output([util.RUNC_PATH, "--version"], stderr=DEVNULL))
|
||||
try:
|
||||
version = str(util.check_output([util.RUNC_PATH, "--version"], stderr=DEVNULL))
|
||||
except util.FileNotFound:
|
||||
version = ""
|
||||
if "version 0" in version:
|
||||
runc_commands = ["start", "kill"]
|
||||
else:
|
||||
|
||||
@@ -40,9 +40,6 @@ def gomtree_available():
|
||||
def runc_available():
|
||||
return os.path.exists(RUNC_PATH)
|
||||
|
||||
def bwrap_oci_available():
|
||||
return os.path.exists(BWRAP_OCI_PATH)
|
||||
|
||||
def check_if_python2():
|
||||
if int(sys.version_info[0]) < 3:
|
||||
_input = raw_input # pylint: disable=undefined-variable,raw_input-builtin
|
||||
|
||||
Reference in New Issue
Block a user