コード例 #1
0
 def push(self):
     if self.noninteractive or tools.decision("Do you want to push the commit?"):
         print("")
         logger.info("Pushing change to the upstream repository...")
         cmd = ["git", "push", "-q", "origin", self.branch]
         logger.debug("Running command '%s'" % ' '.join(cmd))
         subprocess.check_output(cmd)
         logger.info("Change pushed.")
     else:
         logger.info("Changes are not pushed, exiting")
         sys.exit(0)
コード例 #2
0
ファイル: osbs.py プロジェクト: rnc/cekit
 def push(self):
     if self.noninteractive or tools.decision("Do you want to push the commit?"):
         print("")
         LOGGER.info("Pushing change to the upstream repository...")
         cmd = ["git", "push", "-q", "origin", self.branch]
         LOGGER.debug("Running command '{}'".format(' '.join(cmd)))
         subprocess.check_call(cmd)
         LOGGER.info("Change pushed.")
     else:
         LOGGER.info("Changes are not pushed, exiting")
         sys.exit(0)
コード例 #3
0
ファイル: osbs.py プロジェクト: hmlnarik/cekit
    def commit(self, commit_msg):
        if not commit_msg:
            commit_msg = "Sync"

            if self.source_repo_name:
                commit_msg += " with %s" % self.source_repo_name

            if self.source_repo_commit:
                commit_msg += ", commit %s" % self.source_repo_commit

        # Commit the change
        LOGGER.info("Committing with message: '{}'".format(commit_msg))
        subprocess.check_call(["git", "commit", "-q", "-m", commit_msg])

        untracked = subprocess.check_output(
            ["git", "ls-files", "--others",
             "--exclude-standard"]).decode("utf8")

        if untracked:
            LOGGER.warning(
                "There are following untracked files: {}. Please review your commit."
                .format(", ".join(untracked.splitlines())))

        diffs = subprocess.check_output(["git", "diff-files",
                                         "--name-only"]).decode("utf8")

        if diffs:
            LOGGER.warning(
                "There are uncommitted changes in following files: '{}'. "
                "Please review your commit.".format(", ".join(
                    diffs.splitlines())))

        if not self.noninteractive:
            subprocess.call(["git", "status"])
            subprocess.call(["git", "show"])

        if not (self.noninteractive
                or tools.decision("Are you ok with the changes?")):
            LOGGER.info(
                "Executing bash in the repo directory. "
                "After fixing the issues, exit the shell and Cekit will continue."
            )
            subprocess.call(
                ["bash"],
                env={
                    "PS1": "cekit $ ",
                    "TERM": os.getenv("TERM", "xterm"),
                    "HOME": os.getenv("HOME", "")
                })
コード例 #4
0
ファイル: osbs.py プロジェクト: luck3y/cekit
    def build(self):
        cmd = [self._rhpkg]

        if self._user:
            cmd += ['--user', self._user]
        cmd.append("container-build")

        if self._target:
            cmd += ['--target', self._target]

        if self._nowait:
            cmd += ['--nowait']

        if self._rhpkg_set_url_repos:
            cmd += ['--repo-url']
            cmd += self._rhpkg_set_url_repos

        if not self._release:
            cmd.append("--scratch")

        with Chdir(self.dist_git_dir):
            self.dist_git.add()
            self.update_lookaside_cache()

            if self.dist_git.stage_modified():
                self.dist_git.commit(self._commit_msg)
                self.dist_git.push()
            else:
                logger.info("No changes made to the code, committing skipped")

            logger.info("About to execute '%s'." % ' '.join(cmd))
            if tools.decision("Do you want to build the image in OSBS?"):
                build_type = "release" if self._release else "scratch"
                logger.info("Executing %s container build in OSBS..." %
                            build_type)

                subprocess.check_call(cmd)
コード例 #5
0
    def run(self):
        cmd = [self._koji]

        if self.params.user:
            cmd += ['--user', self.params.user]

        cmd += ['call', '--python', 'buildContainer', '--kwargs']

        with Chdir(self.dist_git_dir):
            self.dist_git.add()
            self.update_lookaside_cache()

            if self.dist_git.stage_modified():
                self.dist_git.commit(self.params.commit_message)
                self.dist_git.push()
            else:
                LOGGER.info("No changes made to the code, committing skipped")

            # Get the url of the repository
            url = subprocess.check_output(
                ["git", "config", "--get",
                 "remote.origin.url"]).strip().decode("utf8")
            # Get the latest commit hash
            commit = subprocess.check_output(["git", "rev-parse",
                                              "HEAD"]).strip().decode("utf8")
            # Parse the dist-git repository url
            url = urlparse(url)
            # Construct the url again, with a hash and removed username and password, if any
            src = "git://{}{}#{}".format(url.hostname, url.path, commit)

            target = "{}-containers-candidate".format(self.dist_git.branch)

            if self.params.koji_target:
                target = self.params.koji_target

            scratch = True

            if self.params.release:
                scratch = False

            kwargs = "{{'src': '{}', 'target': '{}', 'opts': {{'scratch': {}, 'git_branch': '{}', 'yum_repourls': {}}}}}".format(
                src, target, scratch, self.dist_git.branch,
                self._rhpkg_set_url_repos)

            cmd.append(kwargs)

            LOGGER.info("About to execute '%s'." % ' '.join(cmd))

            if tools.decision("Do you want to build the image in OSBS?"):
                build_type = "scratch" if scratch else "release"
                LOGGER.info("Executing %s container build in OSBS..." %
                            build_type)

                try:
                    task_id = subprocess.check_output(cmd).strip().decode(
                        "utf8")

                except subprocess.CalledProcessError as ex:
                    raise CekitError("Building container image in OSBS failed",
                                     ex)

                LOGGER.info(
                    "Task {0} was submitted, you can watch the progress here: {1}/taskinfo?taskID={0}"
                    .format(task_id, self._koji_url))

                if self.params.nowait:
                    return

                self._wait_for_osbs_task(task_id)

                LOGGER.info("Image was built successfully in OSBS!")
コード例 #6
0
ファイル: osbs.py プロジェクト: hmlnarik/cekit
    def run(self):
        if self.params.sync_only:
            LOGGER.info(
                "The --sync-only parameter was specified, build will not be executed, exiting"
            )
            return

        cmd = [self._koji]

        if self.params.user:
            cmd += ['--user', self.params.user]

        cmd += ['call', '--python', 'buildContainer', '--kwargs']

        with Chdir(self.dist_git_dir):
            # Get the url of the repository
            url = subprocess.check_output(
                ["git", "config", "--get",
                 "remote.origin.url"]).strip().decode("utf8")
            # Get the latest commit hash
            commit = subprocess.check_output(["git", "rev-parse",
                                              "HEAD"]).strip().decode("utf8")
            # Parse the dist-git repository url
            url = urlparse(url)
            # Construct the url again, with a hash and removed username and password, if any
            src = "git://{}{}#{}".format(url.hostname, url.path, commit)

            target = self.generator.image.get('osbs', {}).get('koji_target')

            # If target was not specified in the image descriptor
            if not target:
                # Default to computed target based on branch
                target = "{}-containers-candidate".format(self.dist_git.branch)

            # Check if it was specified on command line
            # TODO: Remove in 3.6
            if self.params.koji_target:
                target = self.params.koji_target

            scratch = True

            if self.params.release:
                scratch = False

            kwargs = "{{'src': '{}', 'target': '{}', 'opts': {{'scratch': {}, 'git_branch': '{}', 'yum_repourls': {}}}}}".format(
                src, target, scratch, self.dist_git.branch,
                self._rhpkg_set_url_repos)

            cmd.append(kwargs)

            LOGGER.info("About to execute '{}'.".format(' '.join(cmd)))

            if self.params.assume_yes or tools.decision(
                    "Do you want to build the image in OSBS?"):
                build_type = "scratch" if scratch else "release"
                LOGGER.info("Executing {} container build in OSBS...".format(
                    build_type))

                try:
                    task_id = subprocess.check_output(cmd).strip().decode(
                        "utf8")

                except subprocess.CalledProcessError as ex:
                    raise CekitError("Building container image in OSBS failed",
                                     ex)

                LOGGER.info(
                    "Task {0} was submitted, you can watch the progress here: {1}/taskinfo?taskID={0}"
                    .format(task_id, self._koji_url))

                if self.params.nowait:
                    return

                self._wait_for_osbs_task(task_id)

                LOGGER.info("Image was built successfully in OSBS!")