def check():
    """Runs coding style checks, and Django's checking framework"""
    step('Searching for debugging statements...')
    run_local(
        "! git --no-pager grep -n -C3 -E 'import i?pdb' -- '*.py'")
    run_local(
        "! git --no-pager grep -n -C3 -E '(^| )print( |\(|$)' -- '*.py'")

    step('Checking Python code with flake8...')
    run_local('venv/bin/flake8 .')

    step('Checking Javascript code...')
    run_local('./node_modules/.bin/eslint %(box_static_src)s/js/ webpack*js')

    step('Invoking Django\'s systems check framework...')
    run_local('venv/bin/python manage.py check')

    with settings(warn_only=True), hide('warnings'):
        # Remind the user about uglyness, but do not fail (there are good
        # reasons to use the patterns warned about here).
        step('Pointing to potential tasks...')
        run_local(
            "! git --no-pager grep -n -C3 -E 'console\.log' -- '*.html' '*.js'"
        )
        run_local(
            "! git --no-pager grep -n -E '#.*noqa'"
            " -- '%(box_project_name)s/*.py'")
        run_local("! git --no-pager grep -n -E '(XXX|FIXME|TODO)'")
        complain_on_failure(
            run_local("! git --no-pager grep -n -E '^-e.+$' -- requirements/"),
            'Warning: Editable requirements found. Releases are preferred!')
Beispiel #2
0
def reward():
    from fabric.api import env
    env.host_string = 'rpi'
    reload(fabfile)
    fabfile.step()

    return 'ok'
def deploy():
    """Checks whether everything is ready for deployment"""

    step('Checking whether we are on the expected branch...')
    with settings(warn_only=True), hide('everything'):
        branch = run_local('git symbolic-ref -q --short HEAD', capture=True)

    if not branch:
        abort(red('No branch checked out, cannot continue.', bold=True))

    if branch != env.box_branch:
        puts(red(
            'Warning: The currently checked out branch is \'%s\', but'
            ' the environment \'%s\' runs on \'%s\'.' % (
                branch, env.box_environment, env.box_branch)))

        if not confirm('Continue deployment?', default=False):
            abort('Aborting.')

    execute('check.check')
    execute('check.test')
    # XXX Maybe even execute('check.primetime') if deploying to production?

    with cd('%(box_domain)s'):
        step('\nChecking for uncommitted changes on the server...')
        result = run('git status --porcelain')
        if result:
            abort(red('Uncommitted changes detected, aborting deployment.'))
Beispiel #4
0
def deploy():
    """Checks whether everything is ready for deployment"""

    step('Checking whether we are on the expected branch...')
    with settings(warn_only=True), hide('everything'):
        branch = run_local('git symbolic-ref -q --short HEAD', capture=True)

    if not branch:
        abort(red('No branch checked out, cannot continue.', bold=True))

    if branch != env.box_branch:
        puts(
            red('Warning: The currently checked out branch is \'%s\', but'
                ' the environment \'%s\' runs on \'%s\'.' %
                (branch, env.box_environment, env.box_branch)))

        if not confirm('Continue deployment?', default=False):
            abort('Aborting.')

    execute('check.check')
    execute('check.test')
    # XXX Maybe even execute('check.primetime') if deploying to production?

    with cd('%(box_domain)s'):
        step('\nChecking for uncommitted changes on the server...')
        result = run('git status --porcelain')
        if result:
            abort(red('Uncommitted changes detected, aborting deployment.'))
Beispiel #5
0
def check():
    """Runs coding style checks, and Django's checking framework"""
    step('Searching for debugging statements...')
    run_local("! git --no-pager grep -n -C3 -E 'import i?pdb' -- '*.py'")
    run_local(
        "! git --no-pager grep -n -C3 -E 'console\.log' -- '*.html' '*.js'")
    run_local("! git --no-pager grep -n -C3 -E '(^| )print( |\(|$)' -- '*.py'")

    step('Checking Python code with flake8...')
    run_local('venv/bin/flake8 .')

    step('Checking Javascript code...')
    run_local('./node_modules/.bin/jshint %(box_staticfiles)s/')

    step('Invoking Django\'s systems check framework...')
    run_local('venv/bin/python manage.py check')

    with settings(warn_only=True), hide('warnings'):
        # Remind the user about uglyness, but do not fail (there are good
        # reasons to use the patterns warned about here).
        step('Pointing to potential tasks...')
        run_local("! git --no-pager grep -n -E '#.*noqa'"
                  " -- '%(box_project_name)s/*.py'")
        run_local("! git --no-pager grep -n -E '(XXX|FIXME|TODO)'")
        complain_on_failure(
            run_local("! git --no-pager grep -n -E '^-e.+$' -- requirements/"),
            'Warning: Editable requirements found. Releases are preferred!')
Beispiel #6
0
def fetch_remote():
    step('Updating git remote...')
    env.box_idx = '' if len(env.hosts) < 2 else '-%d' % (
        env.hosts.index(env.host_string) + 1)

    with settings(warn_only=True):
        run_local('git fetch %(box_remote)s%(box_idx)s')
Beispiel #7
0
def fetch_remote():
    step('Updating git remote...')
    env.box_idx = '' if len(
        env.hosts) < 2 else '-%d' % (env.hosts.index(env.host_string) + 1)

    with settings(warn_only=True):
        run_local('git fetch %(box_remote)s%(box_idx)s')
Beispiel #8
0
def primetime():
    """Check whether this project is ready for prime time"""
    execute('check.check')
    execute('check.test')

    step('"noindex" should not hit production servers...')
    run_local(
        "! git --no-pager grep -n -C3 -E '^Disallow: /$' -- 'robots.txt'")
    run_local("! git --no-pager grep -n -C3 -E 'meta.*robots.*noindex'"
              " -- %(box_project_name)s")

    step('Checking local settings on server...')
    with cd('%(box_domain)s'):
        output = run(
            "DJANGO_SETTINGS_MODULE=%(box_project_name)s.settings"
            " venv/bin/python -c \""
            "from django.conf import settings as s;"
            "print('fd:%%s\\ndsn:%%s\\nsso:%%s\\ndebug:%%s\\nsk:%%s' %% ("
            "getattr(s, 'FORCE_DOMAIN', '-'),"
            "getattr(s, 'RAVEN_CONFIG', {}).get('dsn', ''),"
            "bool(getattr(s, 'DJANGO_ADMIN_SSO_ADD_LOGIN_BUTTON', False)),"
            "bool(s.DEBUG),"
            "s.SECRET_KEY,"
            "))\"" % env,
            quiet=True).strip()

        output = dict(row.strip().split(':', 1)
                      for row in re.split(r'[\r\n]+', output))

        if output['fd'] == '':
            puts(red('Warning: FORCE_DOMAIN is empty.'))
        elif output['fd'] == '-':
            puts(red('Warning: FORCE_DOMAIN is not defined.'))

        if output['dsn'] == '':
            puts(
                red('Warning: Sentry is not configured, fill in RAVEN_CONFIG.')
            )

        if output['sso'] != 'True':
            puts(
                red('Warning: SSO authentication for the administration is not'
                    ' configured.'))

        if output['debug'] == 'True':
            puts(red('Error: DEBUG = True!?', bold=True))

        with settings(warn_only=True), hide('everything'):
            gitgrep = run_local("! git --no-pager grep '%s'" % output['sk'],
                                capture=True)
            grep = run_local("! grep '%s' */*.py" % output['sk'], capture=True)
        if gitgrep or grep:
            puts(
                red('Error: The remote value of SECRET_KEY also exists in local'
                    ' files. Set a new value for SECRET_KEY in'
                    ' .env on the server!' % env,
                    bold=True))
Beispiel #9
0
def primetime():
    """Check whether this project is ready for prime time"""
    execute('check.check')
    execute('check.test')

    step('"noindex" should not hit production servers...')
    run_local(
        "! git --no-pager grep -n -C3 -E '^Disallow: /$' -- 'robots.txt'")
    run_local(
        "! git --no-pager grep -n -C3 -E 'meta.*robots.*noindex'"
        " -- %(box_project_name)s")

    step('Checking local settings on server...')
    with cd('%(box_domain)s'):
        output = run(
            "DJANGO_SETTINGS_MODULE=%(box_project_name)s.settings"
            " venv/bin/python -c \""
            "from django.conf import settings as s;"
            "print('fd:%%s\\ndsn:%%s\\nsso:%%s\\ndebug:%%s\\nsk:%%s' %% ("
            "getattr(s, 'FORCE_DOMAIN', '-'),"
            "getattr(s, 'RAVEN_CONFIG', {}).get('dsn', ''),"
            "bool(getattr(s, 'DJANGO_ADMIN_SSO_ADD_LOGIN_BUTTON', False)),"
            "bool(s.DEBUG),"
            "s.SECRET_KEY,"
            "))\"" % env, quiet=True).strip()

        output = dict(
            row.strip().split(':', 1) for row in re.split(r'[\r\n]+', output))

        if output['fd'] == '':
            puts(red('Warning: FORCE_DOMAIN is empty.'))
        elif output['fd'] == '-':
            puts(red('Warning: FORCE_DOMAIN is not defined.'))

        if output['dsn'] == '':
            puts(red(
                'Warning: Sentry is not configured, fill in RAVEN_CONFIG.'))

        if output['sso'] != 'True':
            puts(red(
                'Warning: SSO authentication for the administration is not'
                ' configured.'))

        if output['debug'] == 'True':
            puts(red(
                'Error: DEBUG = True!?', bold=True))

        with settings(warn_only=True), hide('everything'):
            gitgrep = run_local(
                "! git --no-pager grep '%s'" % output['sk'], capture=True)
            grep = run_local("! grep '%s' */*.py" % output['sk'], capture=True)
        if gitgrep or grep:
            puts(red(
                'Error: The remote value of SECRET_KEY also exists in local'
                ' files. Set a new value for SECRET_KEY in'
                ' .env on the server!'
                % env, bold=True))
Beispiel #10
0
def _deploy_styles_foundation5_webpack():
    step('\n Compiling static sources...')
    run_local('rm -rf %(box_static_src)s/dist' % env)
    run_local('npm run prod')

    step('\nUploading static files...')
    rsync_project(
        local_dir='%(box_static_src)s/dist' % env,
        remote_dir='%(box_domain)s/%(box_staticfiles)s/' % env,
        delete=True,
    )
    put(
        'tmp/webpack*json',
        '%(box_domain)s/tmp/' % env,
    )
Beispiel #11
0
def styles():
    """Compiles and compresses the CSS and deploys it to the server"""
    execute('check.deploy')

    step('\nBuilding and deploying assets...')

    if os.path.exists('gulpfile.js'):
        _deploy_styles_foundation5_gulp()
    elif os.path.exists('%(box_staticfiles)s/Gulpfile.js' % env):
        _deploy_styles_foundation5_grunt()
    elif os.path.exists('%(box_staticfiles)s/config.rb' % env):
        _deploy_styles_foundation4_bundler()
    else:
        abort(red('I do not know how to deploy this frontend code.'))

    with cd('%(box_domain)s'):
        run('venv/bin/python manage.py collectstatic --noinput')
Beispiel #12
0
def styles(reload=True):
    """Compiles and compresses the CSS and deploys it to the server"""
    execute('check.deploy')

    step('\nBuilding and deploying assets...')

    if os.path.exists('gulpfile.js'):
        _deploy_styles_foundation5_gulp()
    elif os.path.exists('%(box_staticfiles)s/Gulpfile.js' % env):
        _deploy_styles_foundation5_grunt()
    elif os.path.exists('%(box_staticfiles)s/config.rb' % env):
        _deploy_styles_foundation4_bundler()
    else:
        abort(red('I do not know how to deploy this frontend code.'))

    with cd('%(box_domain)s'):
        run('venv/bin/python manage.py collectstatic --noinput')

    if reload:
        execute('deploy.restart_server')
Beispiel #13
0
def code(reload=True):
    """Deploys the currently committed project state to the server, if there
    are no uncommitted changes on the server and the checking step did not
    report any problems"""
    execute('check.deploy')

    # XXX Maybe abort deployment if branch-to-be-deployed is not checked out?

    step('\nPushing changes...')
    run_local('git push origin %(box_branch)s')

    step('\nDeploying new code on server...')
    with cd('%(box_domain)s'):
        run('git fetch')
        run('git reset --hard origin/%(box_branch)s')
        run('find . -name "*.pyc" -delete')
        run('venv/bin/pip install -r requirements/production.txt'
            ' --find-links file:///home/www-data/tmp/wheel/wheelhouse/')
        run('venv/bin/python manage.py migrate --noinput')

    if reload:
        execute('deploy.restart_server')
    execute('git.fetch_remote')
def test():
    step('Running backend testsuite...')
    run_local('venv/bin/python manage.py test')
    step('We do not have a frontend testsuite yet...')
Beispiel #15
0
def test():
    step('Running backend testsuite...')
    run_local('venv/bin/python manage.py test')
    step('We do not have a frontend testsuite yet...')