Example #1
0
    def test_safe_build(self):
        """
        Test that build actions run under the proper user.
        """
        # use the app fixture and create a repo
        here = path.abspath(path.split(__file__)[0])
        src = path.join(here, '../fixtures', self.project_name)
        dest = path.join(self.cust_dir, self.project_name)
        shutil.copytree(src, dest)
        utils.local('(cd %s; git init; git add -A; git commit -m test)' %
                    path.join(dest, 'src'))

        (bundle_name, code_revision) = bundle.bundle_app(self.project_name)
        bundle_dir = path.join(self.cust_dir, self.project_name, bundle_name)

        a_bundle_file = path.join(bundle_dir, "user-repo", "settings.py")
        self.assertFileOwnedBy(a_bundle_file, self.project_name)
Example #2
0
    def _prep_build_test_bundle(self, **kwargs):
        self.patch(taskconfig, "NR_CUSTOMER_DIR", self.dir)

        # install_requirements = self.mocker.replace(
        #     "dz.tasklib.utils.install_requirements")
        # install_requirements(["Django==1.2.5"], MATCH(os.path.isdir),
        #                      logsuffix="-django")
        # install_requirements(ANY, MATCH(os.path.isdir))
        # self.mocker.replay()

        here = path.abspath(path.split(__file__)[0])
        src = path.join(here, '../fixtures', 'app')
        dest = path.join(self.dir, 'app')

        if not os.path.isdir(dest):
            shutil.copytree(src, dest)
            utils.local('(cd %s; git init; git add -A; git commit -m test)' %
                        path.join(dest, 'src'))

        return bundle.bundle_app('app', **kwargs)
Example #3
0
def create_test_bundle_in_local_storage():
    """
    Creates a bundle for testing, and uploads it to the local storage.
    Returns the bundle's tarball's name.

    This function is used from test_nginx and perhaps other tests that
    require a bundle -- modify with care.
    """
    print "Making a bundle fixture for testing."
    bundle_name = "bundle_test_deploy_app_2011-fixture"

    here = os.path.abspath(os.path.split(__file__)[0])
    fixture_dir = os.path.join(here, '../fixtures')
    app_name = "test_deploy_app"

    # force rename the bundle
    app_dir = os.path.join(taskconfig.NR_CUSTOMER_DIR, app_name)

    if os.path.isdir(app_dir):
        utils.chown_to_me(app_dir)
        shutil.rmtree(app_dir)

    shutil.copytree(os.path.join(fixture_dir, "app"), app_dir)

    # create a git repo in app_dir and do a commit so that we can get the
    # most recent commit during bundle_app.
    utils.local(";".join([
        ("cd %s/src" % app_dir),
        "git init .",
        "git add __init__.py",
        "git commit -m 'initial test_deploy commit'"]))

    zcfg_path = os.path.join(app_dir, "zoombuild.cfg")
    zcfg_content = file(zcfg_path).read()
    # django_tarball = os.path.join(fixture_dir, 'Django-1.2.5.tar.gz')
    # we don't use pip_reqs any more
    # zcfg_content = zcfg_content.replace(
    #     "pip_reqs: Django==1.2.5", "pip_reqs: %s" % django_tarball)

    faster_zcfg = file(zcfg_path, "w")
    faster_zcfg.write(zcfg_content)
    faster_zcfg.close()

    bundle_name, code_revision = bundle.bundle_app(
        app_name,
        force_bundle_name=bundle_name)

    bundle_dir = os.path.join(taskconfig.NR_CUSTOMER_DIR,
                              app_name,
                              bundle_name)

    tarball_name = bundle.zip_and_upload_bundle(app_name,
                                                bundle_name,
                                                bundle_storage_local)

    print "Created bundle fixture in %s" % tarball_name

    # after upload, delete the dir where bundle was created
    shutil.rmtree(bundle_dir)

    return tarball_name
def build_project_bundle(zoomdb, opts):
    zoomdb.log("We're getting your project's dependencies and packaging "
               "everything up. This might take a couple of minutes.")
    bundle_name, code_revision, ue = bundle.bundle_app(
        opts["APP_ID"],
        src_repo_type=opts["SRC_REPO_TYPE"],
        return_ue=True)
    zoomdb.log("Built project into bundle: %s" % bundle_name)
    opts["BUNDLE_NAME"] = bundle_name
    # and log this bundle into zoomdb
    opts["BUNDLE_INFO"] = zoomdb.add_bundle(bundle_name, code_revision)

    post_build_hooks = opts["POST_BUILD_HOOKS"]

    bundle_runner = os.path.join(opts["APP_DIR"],
                                 bundle_name,
                                 "thisbundle_build.py")
    # write out a temporary build-time bundle runner
    utils.render_tpl_to_file('deploy/thisbundle.py.tmpl',
                             bundle_runner,
                             dbinfo=None,  # no database access yet
                             num_workers=0,
                             env=ue)
    ue.call(["chmod", "700", bundle_runner])

    def run_buildtime_managepy_cmd(cmdlist, nonzero_exit_ok=False):
        stdout, stderr, p = ue.subproc([bundle_runner] + cmdlist,
                                       nonzero_exit_ok=nonzero_exit_ok)
        return stdout, stderr, p

    if post_build_hooks is None:
        post_build_hooks = []

        _stdout, managepy_help, _p = run_buildtime_managepy_cmd(
            ["help"], nonzero_exit_ok=True)
        try:
            available_commands = [x.strip() for x in
                                  managepy_help.rsplit(
                                      "Available subcommands:",
                                      1)[1].splitlines()]

            if "collectstatic" in available_commands:
                zoomdb.log("Found that your project offers a 'collectstatic' "
                           "management command; adding that to post-build "
                           "hooks.")
                post_build_hooks.append(["collectstatic",
                                         "--link",
                                         "--noinput"])

        except IndexError:
            zoomdb.log(("Warning: Couldn't determine whether you have a "
                     "'collectstatic' command because 'manage.py help' didn't "
                     "provide a list of available subcommands as expected. "
                     "Full manage.py help output was:\n%s") % managepy_help)

    if not post_build_hooks:
        zoomdb.log("No post-build hooks found.")
    else:
        try:
            for cmdlist in post_build_hooks:
                cmdtext = " ".join(cmdlist)
                zoomdb.log("Running post-build 'manage.py %s': " % cmdtext)
                cmd_output, cmd_err, cmd_p = run_buildtime_managepy_cmd(
                    cmdlist)
                zoomdb.log("Executed: " + cmd_output + cmd_err)
        except RuntimeError, e:
            zoomdb.log("Warning: there was an error running a post-build "
                       "command. Detail:\n" + e.message,
                       zoomdb.LOG_WARN)