Exemplo n.º 1
0
def run_command(cmd_name,
                cmd_args,
                cmd_cwd=None,
                cmd_env=None,
                cmd_input=None,
                err_type=ftl_error.FTLErrors.INTERNAL):
    with Timing(cmd_name):
        logging.info("`%s` full cmd:\n%s" % (cmd_name, " ".join(cmd_args)))
        proc_pipe = None
        proc_pipe = subprocess.Popen(
            cmd_args,
            stdin=subprocess.PIPE,
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE,
            cwd=cmd_cwd,
            env=cmd_env,
        )
        stdout, stderr = proc_pipe.communicate(input=cmd_input)
        logging.info("`%s` stdout:\n%s" % (cmd_name, stdout))
        err_txt = ""
        if stderr:
            err_txt = "`%s` had error output:\n%s" % (cmd_name, stderr)
            logging.error(err_txt)
        if proc_pipe.returncode:
            ret_txt = "error: `%s` returned code: %d" % (cmd_name,
                                                         proc_pipe.returncode)
            logging.error(ret_txt)
            if err_type == ftl_error.FTLErrors.USER():
                raise ftl_error.UserError("%s\n%s" % (err_txt, ret_txt))
            elif err_type == ftl_error.FTLErrors.INTERNAL():
                raise ftl_error.InternalError("%s\n%s" % (err_txt, ret_txt))
            else:
                raise Exception("Unknown error type passed to run_command")
Exemplo n.º 2
0
    def _gen_npm_install_tar(self, app_dir):
        npm_install_cmd = ['npm', 'install', '--production']
        npm_output = ftl_util.run_command('npm_install',
                                          npm_install_cmd,
                                          cmd_cwd=app_dir,
                                          err_type=ftl_error.FTLErrors.USER())

        module_destination = os.path.join(self._destination_path,
                                          'node_modules')
        modules_dir = os.path.join(self._directory, "node_modules")
        if not os.path.isdir(modules_dir) or os.listdir(modules_dir) == []:
            if "Invalid name" in npm_output:
                raise ftl_error.UserError("%s\n%s" % (npm_output, "0"))

        return ftl_util.zip_dir_to_layer_sha(modules_dir, module_destination)
Exemplo n.º 3
0
def run_command(cmd_name,
                cmd_args,
                cmd_cwd=None,
                cmd_env=None,
                cmd_input=None,
                err_type=ftl_error.FTLErrors.INTERNAL()):
    with Timing(cmd_name):
        cmd = "%s %s" % (cmd_name, " ".join(cmd_args))
        logging.info(cmd)
        proc_pipe = None
        try:
            proc_pipe = subprocess.Popen(
                cmd_args,
                stdin=subprocess.PIPE,
                stdout=subprocess.PIPE,
                stderr=subprocess.PIPE,
                cwd=cmd_cwd,
                env=cmd_env,
            )
        except OSError as e:
            raise ftl_error.InternalError(
                "%s\nexited with error %s\n%s is likely not on the path" %
                (cmd, e, cmd_name))
        stdout, stderr = proc_pipe.communicate(input=cmd_input)
        logging.info("`%s` stdout:\n%s", cmd_name, stdout)
        err_txt = ""
        if stderr:
            err_txt = "`%s` had stderr output:\n%s" % (cmd_name, stderr)
            logging.info(err_txt)
        if proc_pipe.returncode:
            ret_txt = "error: `%s` returned code: %d" % (cmd_name,
                                                         proc_pipe.returncode)
            logging.error(ret_txt)
            if err_type == ftl_error.FTLErrors.USER():
                raise ftl_error.UserError("%s\n%s" % (err_txt, ret_txt))
            elif err_type == ftl_error.FTLErrors.INTERNAL():
                raise ftl_error.InternalError("%s\n%s" % (err_txt, ret_txt))
            else:
                raise Exception("Unknown error type passed to run_command")
        return "stdout: %s, stderr: %s" % (stdout, stderr)