Beispiel #1
0
def create_rpmbuild_content(repo, target):
    env_tags = tags_by_env(repo)
    for branch in repo.branches:
        # We only want environment branches, not manifest branches.
        if not branch.name.startswith(manifest_branch_prefix):
            manifest_branch_name = manifest_branch_prefix + branch.name
            # If there is no equivalent manifest branch, we need to
            # skip this environment.
            if manifest_branch_name not in repo.branches:
                continue
            manifest_branch = repo.branches[manifest_branch_name]
            branch.checkout()
            labelled_tags = tags_by_label(
                os.path.join(repo.working_dir, 'labels'))
            # We want to deploy all tags which have a label, as well as the latest tag.
            if env_tags.get(branch.name):
                latest_tag = max(env_tags[branch.name],
                                 key=lambda t: t.commit.committed_date)
                labelled_tags['latest'] = latest_tag.name

            #--------------- New for this ---------

            # Keep track of the labels which have tags - its those we want.
            tags = []
            envs = []
            for label, tag in labelled_tags.items():
                deployed_name = tag.split('-', 2)[2]
                label_target = deployed_name
                label_location = os.path.join(target, branch.name, label)

                env = '{}-{}'.format(branch.name, label)
                tags.append(tag)
                envs.append(env)
                # If we wanted RPMS for each label, enable this.


#                create_rpmbuild_for_label(env, tag, target)
            for tag in tags:
                create_rpmbuild_for_tag(repo, tag, target)
def create_rpmbuild_content(repo, target, config):
    rpm_prefix = config['rpm']['prefix']
    for branch in repo.branches:
        # We only want environment branches, not manifest branches.
        if not branch.name.startswith(manifest_branch_prefix):
            manifest_branch_name = manifest_branch_prefix + branch.name
            # If there is no equivalent manifest branch, we need to
            # skip this environment.
            if manifest_branch_name not in repo.branches:
                continue
            branch.checkout()
            labelled_tags = tags_by_label(os.path.join(repo.working_dir,
                                                       'labels'))

            # Get number of commits to determine the version of the env rpm.
            commit_num = len(list(Commit.iter_items(repo, branch.commit))) 

            # Keep track of the labels which have tags - its those we want.
            for label, tag in labelled_tags.items():
                create_rpmbuild_for_tag(repo, tag, target, config)
                fname = '{}-env-{}-label-{}.spec'.format(rpm_prefix, branch.name, label)
                with open(os.path.join(target, 'SPECS', fname), 'w') as fh:
                    fh.write(generate.render_env(branch.name, label,
                                                 repo, config, tag, commit_num))
 def test_some(self):
     expected = {'a': '123', 'abc123': 'foobar-again'}
     with resolve.tempdir() as labels_dir:
         label_tag.write_labels(labels_dir, expected)
         result = deploy.tags_by_label(labels_dir)
     self.assertEqual(result, expected)
 def test_no_tags(self):
     expected = {}
     with resolve.tempdir() as labels_dir:
         label_tag.write_labels(labels_dir, expected)
         result = deploy.tags_by_label(labels_dir)
     self.assertEqual(result, expected)
def create_rpmbuild_content(repo,
                            target,
                            config,
                            state,
                            env_labels=None,
                            api_user=None,
                            api_key=None):
    if env_labels is None:
        env_labels = ['*']

    rpm_prefix = config['rpm']['prefix']

    for branch in repo.branches:
        # We only want environment branches, not manifest branches.
        if not branch.name.startswith(manifest_branch_prefix):
            manifest_branch_name = manifest_branch_prefix + branch.name
            # If there is no equivalent manifest branch, we need to
            # skip this environment.
            if manifest_branch_name not in repo.branches:
                continue
            branch.checkout()
            fname = os.path.join(repo.working_dir, 'labels')
            branch_labelled_tags = tags_by_label(fname)

            # Get the number of commits in this branch, and use this as the
            # version number in the environment label RPM spec.
            commit_num = branch.commit.count()

            # Determine the environment tags that are new or have been changed
            # for each branch label, and thus require to have its associated
            # RPM build.
            if branch.name in state:
                # This branch has been built before and has a history ...
                labelled_tags = {}
                for label, tag in branch_labelled_tags.items():
                    if label in state[branch.name] and \
                            tag in state[branch.name][label]:
                        # Skip - the associated RPM already exists.
                        continue
                    # This label or this labels tag is new, so register it
                    # for RPM building.
                    labelled_tags[label] = tag
            else:
                # This is a new environment branch, so register all of its
                # labels for RPM building.
                labelled_tags = branch_labelled_tags

            # Keep track of the labels which have tags - its those we want.
            for label, tag in sorted(labelled_tags.items()):
                # Only create RPMs for environments that match the given
                # pattern.
                if _env_label_filter(branch.name, label, env_labels):
                    create_rpmbuild_for_tag(repo,
                                            tag,
                                            target,
                                            config,
                                            api_user=api_user,
                                            api_key=api_key)
                    fname = '{}-env-{}-label-{}.spec'.format(
                        rpm_prefix, branch.name, label)
                    with open(os.path.join(target, 'SPECS', fname), 'w') as fh:
                        fh.write(
                            generate.render_env(branch.name, label, config,
                                                tag, commit_num))
Beispiel #6
0
 def test_some(self):
     expected = {"a": "123", "abc123": "foobar-again"}
     with resolve.tempdir() as labels_dir:
         label_tag.write_labels(labels_dir, expected)
         result = deploy.tags_by_label(labels_dir)
     self.assertEqual(result, expected)
Beispiel #7
0
 def test_no_tags(self):
     expected = {}
     with resolve.tempdir() as labels_dir:
         label_tag.write_labels(labels_dir, expected)
         result = deploy.tags_by_label(labels_dir)
     self.assertEqual(result, expected)