Exemplo n.º 1
0
def run_tests():
    server.setup() # Install otto on server
    git.push() # Upload repository to otto server
Exemplo n.º 2
0
def stage(target=None):
    """Upload site content to web server.

    When you run the stage task, Otto pushes your code to the server and then
    runs the `clean` and `build` tasks at the server to produce your web site
    files. The clean task is run to ensure files removed from the repository
    are also removed from the build. You are responsible for ensuring `clean`
    does the right thing!

    Otto then uses rsync to copy the content to a staging directory from which
    it can be deployed. If necessary, Otto will setup Otto on your server, and
    add the otto remote to your local repo.

    If no tag name is supplied as an argument, Otto will attempt to tag the
    HEAD of the current branch, or if you are operating with a detached HEAD
    (ouch!), the branch named in `env['otto.git.staging_branch']`. However,
    Otto will refuse to do so if you have modifications in your local
    workspace, as this could result in the remote build being different from
    the local build.
    """
    # Perform the server setup just in time 
    if not remotefile.exists(paths.repos()):
        setup()

    deploy_ts = make_timestamp()

    if target == None:
        target = local("git branch | grep '^\*' | awk '{print $2}'", capture=True)
        if not target:
            target = env['otto.git.staging_branch']
        mods = git.local_modifications()
        if mods != None:
            print colors.red('Local modifications! You may get unexpected results from your build.')
            abort(" Specify a tag to stage or check in your workspace.")

    tagname = "otto-" + deploy_ts
    local('git tag -f %s %s' % (tagname, target))
    git.push()

    # Check out the tag into the workspace
    basename = env['otto.site']
    remote_repo = paths.repos(basename)
    workspace = paths.workspace(basename)
    git.clone_or_update(workspace, remote_repo)

    with cd(workspace):
        run('git reset --hard ' + tagname)

        # Ensure the virtualenv has been built
        checksum = run("md5sum requirements.txt | awk '{print $1}'")
        virtualenv_path = paths.virtualenvs(checksum)
        venv_activate = paths.virtualenvs(checksum, 'bin', 'activate')
        if not remotefile.exists(venv_activate):
            run('virtualenv --system-site-packages ' + virtualenv_path)
            run('pip install -r requirements.txt -E ' + virtualenv_path)

        # Activate the virtualenv and run the build task
        build_dir = paths.workspace(env['otto.site'], env['otto.build_dir'])
        if not build_dir.endswith('/'):
            build_dir += '/'
        stage_dir = paths.site_dir(deploy_ts)
        with prefix('source ' + venv_activate):
            has_clean = run("fab --shortlist | grep '^clean$'")
            if has_clean.succeeded:
                run('fab clean')
            run('fab build')
        run('mkdir -p ' + stage_dir)
        run('rsync -a %s %s' % (build_dir, stage_dir))
        with cd(paths.site_dir()):
            run('ln -sfn %s staged' % deploy_ts)