예제 #1
0
 def cleanup(self):
     # remove SSH identities
     LOG.debug("removing SSH identities")
     commands.execute_command(self.build,
                              "ssh-add -D",
                              log_command=False,
                              message_log=False,
                              output_log=False)
예제 #2
0
파일: command.py 프로젝트: xinity/vespene
    def execute_hook(self, build, context):

        command = self.args
        command = template(command, context)
        commands.execute_command(build,
                                 command,
                                 log_command=True,
                                 output_log=False,
                                 message_log=True)
예제 #3
0
 def ssh_add_without_passphrase(self, keyfile):
     LOG.debug(keyfile)
     cmd = "ssh-add %s < /dev/null" % keyfile
     commands.execute_command(self.build,
                              cmd,
                              env=None,
                              log_command=False,
                              message_log=False,
                              output_log=False)
예제 #4
0
파일: importer.py 프로젝트: xinity/vespene
 def make_working_dir(self, build):
     # FIXME: this is copied from builder.py and really should be moved into common code in workers/common.py
     # or something similar.
     #
     # TODO: this isn't cross platform yet but is seemingly more reliable than 'os' functions on OS X
     # will need to detect the platform and make the appropriate changes for Windows.
     path = os.path.join(settings.BUILD_ROOT, str(build.id))
     commands.execute_command(build, "mkdir -p %s" % path)
     commands.execute_command(build, "chmod 770 %s" % path)
     build.working_dir = path
     build.save()
     return path
예제 #5
0
파일: builder.py 프로젝트: zypox/vespene
    def assign_working_dir(self):
        """
        Determine a temporary build directory for this build and create it.
        """

        # TODO: this isn't cross platform yet but is seemingly more reliable than 'os' functions on OS X
        # will need to detect the platform and make the appropriate changes for Windows.
        path = os.path.join(settings.BUILD_ROOT, str(self.build.id))
        commands.execute_command(self.build, "mkdir -p %s" % path)
        commands.execute_command(self.build, "chmod 770 %s" % path)
        self.build.working_dir = path
        self.build.save()
        return path
예제 #6
0
    def checkout(self):
        # Git checkout implementation.
        self.build.append_message("----------\nCloning repository...")

        # TODO: may need to make SSH options more configurable, possibly using settings file?
        answer_file = None
        ask_pass = ""
        key_mgmt = dict()

        if self.repo.startswith("http://") or self.repo.startswith("https://"):
            # if using a http repo and a scm login password is set, tell git to execute
            # a file to retrieve the password
            if self.project.scm_login and self.project.scm_login.password is not None:
                answer_file = commands.answer_file(
                    self.project.scm_login.get_password())
                ask_pass = "******"bash %s\"" % answer_file
            else:
                # it's not set, we can avoid an error if it asks for a password and
                # we have ALREADY added the username to the URL if we could, but if not
                # there's a slim chance this could go interactive on OS X laptops. See
                # development setup docs for how to turn this off.
                ask_pass = "******"
        else:
            # if using SSH, there's a chance we haven't seen the repo before, and need to be cool about it.
            # TODO: we may allow people to turn this off by adding this as a setting default.
            key_mgmt = {
                "GIT_SSH_COMMAND":
                "ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no",
            }

            if not self.project.ssh_keys.count():
                raise Exception(
                    "add one or more SSH keys to the project or use a http:// or https:// URL"
                )

        branch_spec = ""
        if self.project.repo_branch:
            branch_spec = "-b %s --single-branch " % shlex.quote(
                self.project.repo_branch)

        try:
            # run it
            cmd = "git clone %s%s %s%s -v" % (branch_spec,
                                              shlex.quote(self.repo),
                                              self.build.working_dir, ask_pass)
            # we should be a BIT smarter than this, but for now use the timeout command to kill the build if the SSH
            # unlock password or something might be wrong. We can modifiy this later to have watch phrases
            # that kill the command automatically when we see certain output.
            output = commands.execute_command(self.build,
                                              cmd,
                                              output_log=False,
                                              message_log=True,
                                              timeout=600,
                                              env=key_mgmt)
        finally:
            # delete the answer file if we had one
            if answer_file:
                os.remove(answer_file)

        return output
예제 #7
0
파일: ssh_agent.py 프로젝트: xinity/vespene
 def ssh_add_with_passphrase(self, keyfile, passphrase):
     (_, fname) = tempfile.mkstemp()
     fh = open(fname, "w")
     script = """
     #!/usr/bin/expect -f
     spawn ssh-add %s
     expect "Enter passphrase*:"
     send "%s\n";
     expect "Identity added*"
     interact
     """ % (keyfile, passphrase)
     fh.write(script)
     fh.close()
     commands.execute_command(self.build, "/usr/bin/expect -f %s" % fname, output_log=False, message_log=False)
     os.remove(fname)
     return fname
예제 #8
0
    def clone_repo(self, organization, build, repo, count):

        # much of code is borrowed from plugins.scm.git - but adapted enough that
        # sharing is probably not worthwhile. For instance, this doesn't have
        # to deal with SSH checkouts.

        build.append_message("cloning repo...")

        repo = self.fix_scm_url(repo, organization.scm_login.username)
        answer_file = commands.answer_file(organization.scm_login.get_password())
        ask_pass = "******"bash %s\"" % answer_file
        # TODO: add --depth 1 to git.py checkouts as well
        branch_spec = "--depth 1 --single-branch "

        clone_path = os.path.join(build.working_dir, str(count))

        try:
            # run it
            cmd = "git clone %s %s %s %s" % (shlex.quote(repo), clone_path, ask_pass, branch_spec)
            output = commands.execute_command(build, cmd, output_log=False, message_log=True)
        finally:
            # delete the answer file if we had one
            os.remove(answer_file)

        return clone_path
예제 #9
0
 def get_revision(self):
     # Implementation of revision lookup for git
     cmd = "(cd %s; git rev-parse --short HEAD)" % self.build.working_dir
     out = commands.execute_command(self.build,
                                    cmd,
                                    output_log=False,
                                    message_log=True)
     return out.split("\n")[0].strip()
예제 #10
0
 def checkout(self):
     self.build.append_message("----------\nCloning repository...")
     cmd = "svn checkout --non-interactive --quiet %s %s" % (shlex.quote(
         self.repo), self.build.working_dir)
     return commands.execute_command(self.build,
                                     cmd,
                                     output_log=False,
                                     message_log=True)
예제 #11
0
 def get_last_commit_user(self):
     # Implementation of last commit user lookup for git
     cmd = "(cd %s; git --no-pager log -n 1 --abbrev-commit --format='%s')" % (
         self.build.working_dir, '%aE')
     out = commands.execute_command(self.build,
                                    cmd,
                                    output_log=False,
                                    message_log=True)
     return out.split("\n")[0].strip()
예제 #12
0
 def info_extract(self, attribute):
     cmd = "(cd %s; svn info | grep \"%s\")" % (self.build.working_dir,
                                                attribute)
     out = commands.execute_command(self.build,
                                    cmd,
                                    output_log=False,
                                    message_log=True)
     if ":" in out:
         return out.split(":")[-1].strip()
     return None
예제 #13
0
파일: ssh_agent.py 프로젝트: zypox/vespene
 def ssh_add_with_passphrase(self, keyfile, passphrase):
     (_, fname) = tempfile.mkstemp()
     fh = open(fname, "w")
     script = """
     #!/usr/bin/expect -f
     spawn ssh-add %s
     expect "Enter passphrase*:"
     send "%s\n";
     expect "Identity added*"
     interact
     """ % (keyfile, passphrase)
     # FIMXE: REMOVE THIS!!!
     fh.write(script)
     fh.close()
     LOG.debug(fname)
     LOG.debug(keyfile)
     # FIXME: this should NOT be on True!!! self.build needs to be none!
     commands.execute_command(None, "/usr/bin/expect -f %s" % fname)
     os.remove(fname)
     return fname
예제 #14
0
파일: sudo.py 프로젝트: xinity/vespene
 def execute(self):
     self.build.append_message("----------\nBuilding...")
     commands.execute_command(self.build,
                              "chmod -R %s %s" %
                              (self.chmod, self.build.working_dir),
                              output_log=False,
                              message_log=True)
     commands.execute_command(self.build,
                              "chmod a+x %s" % self.script_file_name,
                              output_log=False,
                              message_log=True)
     if shutil.which('timeout'):
         timeout = "timeout %d " % (self.build.project.timeout * 60)
     else:
         timeout = ""
     sudo_command = "sudo -Snk -u %s %s%s" % (self.sudo_user, timeout,
                                              self.script_file_name)
     self.build.append_message("see 'Output'")
     commands.execute_command(self.build,
                              sudo_command,
                              log_command=False,
                              output_log=True,
                              message_log=False)
예제 #15
0
    def execute(self):

        self.build.append_message("----------\nBuilding...")

        img = "vespene_%s" % self.build.id

        cmd = "docker build . -t %s" % img
        commands.execute_command(self.build,
                                 cmd,
                                 log_command=True,
                                 output_log=True,
                                 message_log=False)
        cmd = "docker run -d %s --name %s" % (img, img)
        commands.execute_command(self.build,
                                 cmd,
                                 log_command=True,
                                 output_log=True,
                                 message_log=False)
        cmd = "docker ps -a | grep %s" % img
        out = commands.execute_command(self.build,
                                       cmd,
                                       log_command=True,
                                       output_log=True,
                                       message_log=True)
        token = out.split("\n")[0].split(" ")[0]
        cmd = "docker cp %s:/tmp/buildroot ." % (token)
        commands.execute_command(self.build,
                                 cmd,
                                 log_command=True,
                                 output_log=False,
                                 message_log=True)
        cmd = "cp -r buildroot/* ."
        commands.execute_command(self.build,
                                 cmd,
                                 log_command=True,
                                 output_log=False,
                                 message_log=True)
        cmd = "rm -R buildroot"
        commands.execute_command(self.build,
                                 cmd,
                                 log_command=True,
                                 output_log=False,
                                 message_log=True)
        cmd = "docker container stop %s" % (token)
        commands.execute_command(self.build,
                                 cmd,
                                 log_command=True,
                                 output_log=False,
                                 message_log=True)
        cmd = "docker container rm %s" % (token)
        commands.execute_command(self.build,
                                 cmd,
                                 log_command=True,
                                 output_log=False,
                                 message_log=True)
        cmd = "docker image rm %s" % (img)
        commands.execute_command(self.build,
                                 cmd,
                                 log_command=True,
                                 output_log=False,
                                 message_log=True)
예제 #16
0
파일: ssh_agent.py 프로젝트: zypox/vespene
 def ssh_add_without_passphrase(self, keyfile):  
     LOG.debug(keyfile)
     cmd = "ssh-add %s < /dev/null" % keyfile
     commands.execute_command(None, cmd, env=None)
예제 #17
0
파일: ssh_agent.py 프로젝트: zypox/vespene
 def cleanup(self):
     # remove SSH identities
     LOG.debug("removing SSH identities")
     commands.execute_command(self.build, "ssh-add -D")