def run(self):
        """
        run the plugin
        """

        parser = df_parser(self.workflow.builder.df_path, workflow=self.workflow)
        release_labels = get_all_label_keys('release')
        dockerfile_labels = parser.labels
        if any(release_label in dockerfile_labels
               for release_label in release_labels):
            self.log.debug("release set explicitly so not incrementing")
            return

        component_label = get_preferred_label_key(dockerfile_labels,
                                                  'com.redhat.component')
        try:
            component = dockerfile_labels[component_label]
        except KeyError:
            raise RuntimeError("missing label: {}".format(component_label))

        version_label = get_preferred_label_key(dockerfile_labels, 'version')
        try:
            version = dockerfile_labels[version_label]
        except KeyError:
            raise RuntimeError('missing label: {}'.format(version_label))

        build_info = {'name': component, 'version': version}
        self.log.debug('getting next release from build info: %s', build_info)
        next_release = self.xmlrpc.getNextRelease(build_info)

        # getNextRelease will return the release of the last successful build
        # but next_release might be a failed build. Koji's CGImport doesn't
        # allow reuploading builds, so instead we should increment next_release
        # and make sure the build doesn't exist
        while True:
            build_info = {'name': component, 'version': version, 'release': next_release}
            self.log.debug('checking that the build does not exist: %s', build_info)
            build = self.xmlrpc.getBuild(build_info)
            if not build:
                break

            next_release = str(int(next_release) + 1)

        # Always set preferred release label - other will be set if old-style
        # label is present
        preferred_release_label = get_preferred_label_key(dockerfile_labels,
                                                         'release')
        old_style_label = get_all_label_keys('com.redhat.component')[1]
        release_labels_to_be_set = [preferred_release_label]
        if old_style_label in dockerfile_labels.keys():
            release_labels_to_be_set = release_labels

        # No release labels are set so set them
        for release_label in release_labels_to_be_set:
            self.log.info("setting %s=%s", release_label, next_release)

            # Write the label back to the file (this is a property setter)
            dockerfile_labels[release_label] = next_release
    def run(self):
        """
        run the plugin
        """

        parser = df_parser(self.workflow.builder.df_path,
                           workflow=self.workflow)
        dockerfile_labels = parser.labels

        release = get_preferred_label(dockerfile_labels, 'release')
        if release is not None and not self.append:
            self.log.debug("release set explicitly so not incrementing")
            return

        component_label = get_preferred_label_key(dockerfile_labels,
                                                  'com.redhat.component')
        try:
            component = dockerfile_labels[component_label]
        except KeyError:
            raise RuntimeError("missing label: {}".format(component_label))

        version_label = get_preferred_label_key(dockerfile_labels, 'version')
        try:
            version = dockerfile_labels[version_label]
        except KeyError:
            raise RuntimeError('missing label: {}'.format(version_label))

        if self.append:
            next_release = self.get_next_release_append(
                component, version, release)
        else:
            next_release = self.get_next_release_standard(component, version)

        # Always set preferred release label - other will be set if old-style
        # label is present
        release_labels = get_all_label_keys('release')
        preferred_release_label = get_preferred_label_key(
            dockerfile_labels, 'release')
        old_style_label = get_all_label_keys('com.redhat.component')[1]
        release_labels_to_be_set = [preferred_release_label]
        if old_style_label in dockerfile_labels.keys():
            release_labels_to_be_set = release_labels

        # No release labels are set so set them
        for release_label in release_labels_to_be_set:
            self.log.info("setting %s=%s", release_label, next_release)

            # Write the label back to the file (this is a property setter)
            dockerfile_labels[release_label] = next_release
    def run(self):
        """
        run the plugin
        """

        parser = df_parser(self.workflow.builder.df_path, workflow=self.workflow)
        dockerfile_labels = parser.labels

        release = get_preferred_label(dockerfile_labels, 'release')
        if release is not None and not self.append:
            self.log.debug("release set explicitly so not incrementing")
            return

        component_label = get_preferred_label_key(dockerfile_labels,
                                                  'com.redhat.component')
        try:
            component = dockerfile_labels[component_label]
        except KeyError:
            raise RuntimeError("missing label: {}".format(component_label))

        version_label = get_preferred_label_key(dockerfile_labels, 'version')
        try:
            version = dockerfile_labels[version_label]
        except KeyError:
            raise RuntimeError('missing label: {}'.format(version_label))

        if self.append:
            next_release = self.get_next_release_append(component, version, release)
        else:
            next_release = self.get_next_release_standard(component, version)

        # Always set preferred release label - other will be set if old-style
        # label is present
        release_labels = get_all_label_keys('release')
        preferred_release_label = get_preferred_label_key(dockerfile_labels,
                                                          'release')
        old_style_label = get_all_label_keys('com.redhat.component')[1]
        release_labels_to_be_set = [preferred_release_label]
        if old_style_label in dockerfile_labels.keys():
            release_labels_to_be_set = release_labels

        # No release labels are set so set them
        for release_label in release_labels_to_be_set:
            self.log.info("setting %s=%s", release_label, next_release)

            # Write the label back to the file (this is a property setter)
            dockerfile_labels[release_label] = next_release
    def get_component_name(self):
        try:
            name_label = str(get_preferred_label_key(self.labels, "name"))
            name = self.labels[name_label]
        except KeyError:
            self.log.error('Unable to determine component from "Labels"')
            raise

        return name
    def get_component_name(self):
        try:
            name_label = str(get_preferred_label_key(self.labels, "name"))
            name = self.labels[name_label]
        except KeyError:
            self.log.error('Unable to determine component from "Labels"')
            raise

        return name
    def get_component_name(self):
        if not self.workflow.built_image_inspect:
            raise RuntimeError('There is no inspect data for built image. '
                               'Has the build succeeded?')

        try:
            labels = self.workflow.built_image_inspect[INSPECT_CONFIG]['Labels']
            name_label = str(get_preferred_label_key(labels, "name"))
            name = labels[name_label]
        except KeyError:
            self.log.error('Unable to determine "name" from "Labels"')
            raise

        return name
    def get_component_name(self):
        if not self.workflow.built_image_inspect:
            raise RuntimeError('There is no inspect data for built image. '
                               'Has the build succeeded?')

        try:
            labels = self.workflow.built_image_inspect[INSPECT_CONFIG]['Labels']
            name_label = str(get_preferred_label_key(labels, "name"))
            name = labels[name_label]
        except KeyError as e:
            self.log.error('Unable to determine "name" from "Labels"')
            raise

        return name
Esempio n. 8
0
    def run(self):
        """
        run the plugin
        """

        parser = DockerfileParser(self.workflow.builder.df_path)
        release_labels = get_all_label_keys('release')
        dockerfile_labels = parser.labels
        if any(release_label in dockerfile_labels
               for release_label in release_labels):
            self.log.debug("release set explicitly so not incrementing")
            return

        component_label = get_preferred_label_key(dockerfile_labels,
                                                  'com.redhat.component')
        try:
            component = dockerfile_labels[component_label]
        except KeyError:
            raise RuntimeError("missing label: {}".format(component_label))

        version_label = get_preferred_label_key(dockerfile_labels, 'version')
        try:
            version = dockerfile_labels[version_label]
        except KeyError:
            raise RuntimeError('missing label: {}'.format(version_label))

        build_info = {'name': component, 'version': version}
        self.log.debug('getting next release from build info: %s', build_info)
        next_release = self.xmlrpc.getNextRelease(build_info)

        # No release labels are set so set them
        for release_label in release_labels:
            self.log.info("setting %s=%s", release_label, next_release)

            # Write the label back to the file (this is a property setter)
            dockerfile_labels[release_label] = next_release
Esempio n. 9
0
    def bump(self, repo, remote):
        """
        Push a commit with an incremented release value.

        :param repo: str, GitRepo instance
        :param remote: str, git remote to push to
        """

        # Set up configuration
        repo.git(['config', 'push.default', 'simple'])
        repo.git(['config', 'user.email', self.committer_email])
        repo.git(['config', 'user.name', self.committer_name])
        if self.push_url:
            repo.git(['remote', 'set-url', '--push', remote, self.push_url])

        # Find out which label to use - we can't rely on pre_add_labels_in_df adding alias as it
        # will run after the bump plugin
        # XXX: remove the logic after transition to the new label set
        df_path = self.workflow.builder.df_path
        parser = DockerfileParser(df_path)

        label_key = get_preferred_label_key(parser.labels, 'release')

        # Bump the release label
        attrs, key = self.find_current_release(parser, label_key)
        next_release = self.get_next_release(attrs[key])
        self.log.info("New Release: %s", next_release)
        attrs[key] = next_release  # this modifies the file

        # Stage it
        repo.git(['add', os.path.basename(df_path)])

        # Commit the change
        repo.git(['commit',
                  '--author={name} <{email}>'.format(name=self.author_name,
                                                     email=self.author_email),
                  '--message={message}'.format(message=self.commit_message)])

        # Push it
        self.log.info("Pushing to git repository")
        repo.git(['push', remote])
Esempio n. 10
0
def test_preferred_labels(labels, name, expected):
    result = get_preferred_label_key(labels, name)
    assert result == expected
Esempio n. 11
0
    def run(self):
        """
        run the plugin
        """

        parser = df_parser(self.workflow.builder.df_path,
                           workflow=self.workflow)
        release_labels = get_all_label_keys('release')
        dockerfile_labels = parser.labels
        if any(release_label in dockerfile_labels
               for release_label in release_labels):
            self.log.debug("release set explicitly so not incrementing")
            return

        component_label = get_preferred_label_key(dockerfile_labels,
                                                  'com.redhat.component')
        try:
            component = dockerfile_labels[component_label]
        except KeyError:
            raise RuntimeError("missing label: {}".format(component_label))

        version_label = get_preferred_label_key(dockerfile_labels, 'version')
        try:
            version = dockerfile_labels[version_label]
        except KeyError:
            raise RuntimeError('missing label: {}'.format(version_label))

        build_info = {'name': component, 'version': version}
        self.log.debug('getting next release from build info: %s', build_info)
        next_release = self.get_patched_release(
            self.xmlrpc.getNextRelease(build_info))

        # getNextRelease will return the release of the last successful build
        # but next_release might be a failed build. Koji's CGImport doesn't
        # allow reuploading builds, so instead we should increment next_release
        # and make sure the build doesn't exist
        while True:
            build_info = {
                'name': component,
                'version': version,
                'release': next_release
            }
            self.log.debug('checking that the build does not exist: %s',
                           build_info)
            build = self.xmlrpc.getBuild(build_info)
            if not build:
                break

            next_release = self.get_patched_release(next_release,
                                                    increment=True)

        # Always set preferred release label - other will be set if old-style
        # label is present
        preferred_release_label = get_preferred_label_key(
            dockerfile_labels, 'release')
        old_style_label = get_all_label_keys('com.redhat.component')[1]
        release_labels_to_be_set = [preferred_release_label]
        if old_style_label in dockerfile_labels.keys():
            release_labels_to_be_set = release_labels

        # No release labels are set so set them
        for release_label in release_labels_to_be_set:
            self.log.info("setting %s=%s", release_label, next_release)

            # Write the label back to the file (this is a property setter)
            dockerfile_labels[release_label] = next_release
Esempio n. 12
0
def test_preferred_labels(labels, name, expected):
    result = get_preferred_label_key(labels, name)
    assert result == expected