diff --git a/Atomic/install.py b/Atomic/install.py index d898929..e1831fb 100644 --- a/Atomic/install.py +++ b/Atomic/install.py @@ -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")) diff --git a/Atomic/syscontainers.py b/Atomic/syscontainers.py index 9278eef..bd7b2ee 100644 --- a/Atomic/syscontainers.py +++ b/Atomic/syscontainers.py @@ -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: diff --git a/Atomic/util.py b/Atomic/util.py index e1e5950..b75327a 100644 --- a/Atomic/util.py +++ b/Atomic/util.py @@ -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