예제 #1
0
 def _print_table_of_contents(build_summary):
     for i, build in enumerate(build_summary):
         index = str(i + 1)
         build_name = build["name"].strip()
         anchor = build_name.strip().lower().replace(" ", "-")
         display.info("%s. [%s](#%s)" % (index, build_name, anchor))
     display.info("")
예제 #2
0
    def run_command(cmd,
                    shell=False,
                    dry_run=False,
                    cwd=None,
                    fail_on_bad_return_code=True,
                    with_continuous_output=False,
                    omit_printing_output=False,
                    stdin_feed=None):

        cmd_for_printing = System._get_cmd_for_printing(
            cmd, omit_printing_output)

        if dry_run:
            display.info("[DRY] Would execute command: %s" % cmd_for_printing)
            return "", "", 0

        logging.debug("Executing command: %s", cmd_for_printing)
        out, err, return_code = System._run_command(cmd, shell, cwd,
                                                    with_continuous_output,
                                                    stdin_feed)

        if fail_on_bad_return_code and return_code != 0:
            if err:
                raise Exception(
                    "Command returned with exit code %s: %s, stderr: %s" %
                    (return_code, cmd_for_printing, err))
            raise Exception("Command returned with exit code %s: %s" %
                            (return_code, cmd_for_printing))

        return out, err, return_code
예제 #3
0
    def lint(self):
        display.info("Step 0 : Linting \"%s\"" % str(self.dockerfile))

        self.validate_syntax()
        self.validate_rules()

        for error in self.errors:
            display.error("---> %s" % error)

        with_warnings = ""
        if self.warnings:
            for warning in self.warnings:
                display.warn("---> [WARNING] %s" % warning)
            if not self.errors:
                with_warnings = " with warning(s)"

        result = "---> %s%s" % ("FAILED" if self.errors else "OK",
                                with_warnings)
        if self.errors:
            display.error(result)
        else:
            display.info(result, color="green")

        if self.exit_on_errors and self.errors:
            raise LintingException("Linting failed")
예제 #4
0
 def _print_build_labels(build_labels):
     display.info("### Build Labels")
     display.info("")
     if build_labels:
         for build_label in build_labels:
             display.info("- " + build_label)
     else:
         display.info("None")
     display.info("")
예제 #5
0
 def _print_build_args(build_args):
     display.info("### Build Arguments")
     display.info("")
     if build_args:
         table = [build_arg.split("=") for build_arg in build_args]
         display.info(tabulate.tabulate(table, ["Key", "Value"], tablefmt="github"))
     else:
         display.info("None")
     display.info("")
예제 #6
0
 def _print_build_digests(digest):
     display.info("### Repository Digests")
     display.info("")
     # digest: "sha256:d85914d547a6c92faa39ce7058bd7529baacab7e0cd4255442b04577c4d1f424"
     if digest is None:
         display.info("None")
     else:
         display.info('digest: "' + digest + '"')
     display.info("")
예제 #7
0
 def _print_build_tags(build_tags):
     display.info("### Build Tags")
     display.info("")
     if build_tags:
         for build_tag in build_tags:
             display.info("- " + build_tag)
     else:
         display.info("None")
     display.info("")
예제 #8
0
 def print_full_build_summary(cls, build_summary):
     display.info("")
     display.info("Markdown Summary (Gitlab compatible):")
     display.info("")
     display.info("# Build Summary")
     display.info("")
     cls._print_table_of_contents(build_summary)
     for build in build_summary:
         cls._print_build_name(build.get("name"))
         cls._print_build_args(build.get("build-args"))
         cls._print_build_labels(build.get("build-labels"))
         cls._print_build_tags(build.get("build-tags"))
         cls._print_build_image_properties(build.get("image-properties"))
         cls._print_build_digests(build.get("digest"))
예제 #9
0
 def _with_continuous_output(cmd, shell, cwd):
     process = subprocess.Popen(cmd,
                                stdout=subprocess.PIPE,
                                shell=shell,
                                cwd=cwd,
                                env=System._get_exec_env())
     err = None
     out = ""
     for line in io.TextIOWrapper(process.stdout, encoding="utf-8"):
         out += line
         try:
             display.info(line.rstrip())
         except UnicodeEncodeError as exception:
             logging.error("error displaying parts of the output: %s",
                           exception)
     return_code = process.wait()
     out, err = System._clean_outputs(out, err)
     return out, err, return_code
예제 #10
0
 def _print_build_name(build_name):
     display.info("## " + build_name)
     display.info("")
예제 #11
0
 def _print_builder_stages_rules(cls):
     display.info("# Builder Stages Rules")
     cls._print_rules(BuilderStagesRules(None))
예제 #12
0
 def _print_last_stage_rules(cls):
     display.info("# Last Stage Rules")
     cls._print_rules(LastStageRules(None))
예제 #13
0
 def _print_every_stage_rules(cls):
     display.info("# Every Stage Rules")
     cls._print_rules(EveryStageRules(None))
예제 #14
0
 def _print_general_rules(cls):
     display.info("# General Rules")
     cls._print_rules(GeneralRules(None))
예제 #15
0
 def _print_rules(rule_class):
     display.info("")
     for i, rule in enumerate(DockerfileLint.gather_rules(rule_class)):
         display.info(str(i + 1) + ". " + getattr(rule_class, rule).__doc__ + " (" + rule + ")")
     display.info("")
예제 #16
0
 def _print_build_image_properties(image_properties):
     display.info("### Image Properties")
     display.info("")
     display.info("```")
     display.info(json.dumps(image_properties, indent=4, sort_keys=True))
     display.info("```")
     display.info("")
예제 #17
0
 def print_tag_list(build_summary):
     display.info("")
     for build in build_summary:
         display.info(build["name"].strip() + ":")
         for tag in build["build-tags"]:
             display.info(tag)
예제 #18
0
 def print_builds(self):
     display.info("Available builds:")
     if "builds" in self.config:
         for build in self.config["builds"]:
             ConfigBase._pprint_complex_data(build)
예제 #19
0
 def _pprint_complex_data(data):
     display.info(json.dumps(data, indent=4, sort_keys=True))