Ejemplo n.º 1
0
    def run(self):
        """
        run the plugin
        """
        if not is_flatpak_build(self.workflow):
            self.log.info('not flatpak build, skipping plugin')
            return

        flatpak_yaml = self.workflow.source.config.flatpak
        if flatpak_yaml is None:
            return
        labels = flatpak_yaml.get('labels')
        if not labels:
            return

        labels_str = " ".join(
            label_to_string(k, v) for k, v in sorted(labels.items()))
        label_line = f"\nLABEL {labels_str}\n"

        def add_labels_to_df(build_dir: BuildDir) -> None:
            dockerfile = build_dir.dockerfile
            # put labels at the end of dockerfile (since they change metadata and do not interact
            # with FS, this should cause no harm)
            dockerfile.lines = dockerfile.lines + [label_line]

        self.workflow.build_dir.for_each_platform(add_labels_to_df)
Ejemplo n.º 2
0
    def run(self):
        """
        run the plugin
        """
        if not is_flatpak_build(self.workflow):
            self.log.info('not flatpak build, skipping plugin')
            return

        flatpak_yaml = self.workflow.source.config.flatpak
        if flatpak_yaml is None:
            return
        labels = flatpak_yaml.get('labels')
        if not labels:
            return

        dockerfile = df_parser(self.workflow.builder.df_path, workflow=self.workflow)
        lines = dockerfile.lines

        # Sort to get repeatable results with Python2
        formatted_labels = []
        for k in sorted(labels):
            formatted_labels.append(label_to_string(k, labels[k]))

        # put labels at the end of dockerfile (since they change metadata and do not interact
        # with FS, this should cause no harm)
        lines.append('\nLABEL ' + " ".join(formatted_labels) + '\n')
        dockerfile.lines = lines
Ejemplo n.º 3
0
    def run(self):
        """
        run the plugin
        """
        dockerfile = df_parser(self.workflow.builder.df_path,
                               workflow=self.workflow)

        lines = dockerfile.lines

        if (self.workflow.builder.dockerfile_images.custom_base_image
                or self.workflow.builder.dockerfile_images.base_from_scratch):
            base_image_labels = {}
        else:
            try:
                config = self.workflow.builder.base_image_inspect[
                    INSPECT_CONFIG]
            except KeyError as exc:
                message = "base image was not inspected"
                self.log.error(message)
                raise RuntimeError(message) from exc
            else:
                base_image_labels = config["Labels"] or {}

        self.generate_auto_labels(base_image_labels.copy(),
                                  dockerfile.labels.copy(), self.labels.copy())
        # changing dockerfile.labels writes out modified Dockerfile - err on
        # the safe side and make a copy
        self.add_aliases(base_image_labels.copy(), dockerfile.labels.copy(),
                         self.labels.copy())
        if self.info_url_format:
            self.add_info_url(base_image_labels.copy(),
                              dockerfile.labels.copy(), self.labels.copy())

        labels = []
        for key, value in self.labels.items():

            if key not in dockerfile.labels or dockerfile.labels[key] != value:

                if key in self.dont_overwrite_if_in_dockerfile and key in dockerfile.labels:
                    self.log.info(
                        "denying overwrite of label %r, using from Dockerfile",
                        key)

                elif (key in base_image_labels and key in self.dont_overwrite
                      and key not in dockerfile.labels):
                    self.log.info(
                        "denying overwrite of label %r, using from baseimage",
                        key)

                else:
                    label = label_to_string(key, value)
                    self.log.info("setting label %r", label)
                    labels.append(label)

        content = ""
        if labels:
            content = 'LABEL ' + " ".join(labels)
            # put labels at the end of dockerfile (since they change metadata and do not interact
            # with FS, this should cause no harm)
            lines.append('\n' + content + '\n')
            dockerfile.lines = lines

        self.add_release_env_var(dockerfile)

        return content
Ejemplo n.º 4
0
    def add_labels_to_df(self, build_dir: BuildDir) -> None:
        """Add labels to a platform-specific Dockerfile."""
        base_image_labels: Dict[str, str]

        base_image_inspect = self.workflow.imageutil.base_image_inspect(
            build_dir.platform)
        dockerfile = build_dir.dockerfile_with_parent_env(base_image_inspect)

        df_images = self.workflow.data.dockerfile_images
        if df_images.custom_base_image or df_images.base_from_scratch:
            base_image_labels = {}
        else:
            try:
                config = base_image_inspect[INSPECT_CONFIG]
            except KeyError as exc:
                message = "base image was not inspected"
                self.log.error(message)
                raise RuntimeError(message) from exc
            else:
                base_image_labels = config["Labels"] or {}

        add_labels = self.labels.copy()

        generated_labels = self.generate_auto_labels(build_dir.platform)
        add_labels.update(generated_labels)

        # changing dockerfile.labels writes out modified Dockerfile - err on
        # the safe side and make a copy
        alias_labels = self.add_aliases(base_image_labels.copy(),
                                        dockerfile.labels.copy(),
                                        add_labels.copy())
        add_labels.update(alias_labels)

        if self.info_url_format:
            info_url = self.get_info_url(base_image_labels.copy(),
                                         dockerfile.labels.copy(),
                                         add_labels.copy())
            add_labels["url"] = info_url

        labels = []
        for key, value in add_labels.items():

            if key not in dockerfile.labels or dockerfile.labels[key] != value:

                if key in self.dont_overwrite_if_in_dockerfile and key in dockerfile.labels:
                    self.log.info(
                        "denying overwrite of label %r, using from Dockerfile",
                        key)

                elif (key in base_image_labels and key in self.dont_overwrite
                      and key not in dockerfile.labels):
                    self.log.info(
                        "denying overwrite of label %r, using from baseimage",
                        key)

                else:
                    label = label_to_string(key, value)
                    self.log.info("setting label %r", label)
                    labels.append(label)

        if labels:
            label_line = f"LABEL {' '.join(labels)}\n"
            # put labels at the end of dockerfile (since they change metadata and do not interact
            # with FS, this should cause no harm)
            dockerfile.lines = dockerfile.lines + ["\n", label_line]

        self.add_release_env_var(dockerfile)