5 | {% endblock %}
6 |
--------------------------------------------------------------------------------
/app/views.py:
--------------------------------------------------------------------------------
1 | from flask import Blueprint, render_template
2 |
3 | blueprint = Blueprint('main', __name__, template_folder='templates',
4 | static_folder='static')
5 |
6 | @blueprint.route('/')
7 | def index():
8 | return render_template('main/index.html')
9 |
--------------------------------------------------------------------------------
/db/alembic.ini:
--------------------------------------------------------------------------------
1 | # A generic, single database configuration.
2 |
3 | [alembic]
4 | # path to migration scripts
5 | script_location = /srv/www/app/db
6 |
7 | # template used to generate migration files
8 | # file_template = %%(rev)s_%%(slug)s
9 |
10 | # set to 'true' to run the environment during
11 | # the 'revision' command, regardless of autogenerate
12 | # revision_environment = false
13 |
14 | # Logging configuration
15 | [loggers]
16 | keys = root,sqlalchemy,alembic
17 |
18 | [handlers]
19 | keys = console
20 |
21 | [formatters]
22 | keys = generic
23 |
24 | [logger_root]
25 | level = WARN
26 | handlers = console
27 | qualname =
28 |
29 | [logger_sqlalchemy]
30 | level = WARN
31 | handlers =
32 | qualname = sqlalchemy.engine
33 |
34 | [logger_alembic]
35 | level = INFO
36 | handlers =
37 | qualname = alembic
38 |
39 | [handler_console]
40 | class = StreamHandler
41 | args = (sys.stderr,)
42 | level = NOTSET
43 | formatter = generic
44 |
45 | [formatter_generic]
46 | format = %(levelname)-5.5s [%(name)s] %(message)s
47 | datefmt = %H:%M:%S
48 |
--------------------------------------------------------------------------------
/db/env.py:
--------------------------------------------------------------------------------
1 | from __future__ import with_statement
2 | import sys
3 | from os.path import dirname, abspath
4 | from alembic import context
5 | from sqlalchemy import engine_from_config, pool
6 | from logging.config import fileConfig
7 |
8 | sys.path.append(dirname(dirname(abspath(__file__))))
9 |
10 | # Import app
11 | from app import create_app
12 | from app.db import db
13 |
14 | # this is the Alembic Config object, which provides
15 | # access to the values within the .ini file in use.
16 | config = context.config
17 |
18 | # Interpret the config file for Python logging.
19 | # This line sets up loggers basically.
20 | fileConfig(config.config_file_name)
21 |
22 | # Initialise Flask app
23 | app = create_app()
24 |
25 | # Set metadata for alembic
26 | config.set_main_option('sqlalchemy.url', app.config.get('SQLALCHEMY_DATABASE_URI'))
27 | target_metadata = db.metadata
28 |
29 | # other values from the config, defined by the needs of env.py,
30 | # can be acquired:
31 | # my_important_option = config.get_main_option("my_important_option")
32 | # ... etc.
33 |
34 |
35 | def run_migrations_offline():
36 | """Run migrations in 'offline' mode.
37 |
38 | This configures the context with just a URL
39 | and not an Engine, though an Engine is acceptable
40 | here as well. By skipping the Engine creation
41 | we don't even need a DBAPI to be available.
42 |
43 | Calls to context.execute() here emit the given string to the
44 | script output.
45 |
46 | """
47 | url = config.get_main_option("sqlalchemy.url")
48 | context.configure(url=url)
49 |
50 | with context.begin_transaction():
51 | context.run_migrations()
52 |
53 |
54 | def run_migrations_online():
55 | """Run migrations in 'online' mode.
56 |
57 | In this scenario we need to create an Engine
58 | and associate a connection with the context.
59 |
60 | """
61 | engine = engine_from_config(
62 | config.get_section(config.config_ini_section),
63 | prefix='sqlalchemy.',
64 | poolclass=pool.NullPool)
65 |
66 | connection = engine.connect()
67 | context.configure(
68 | connection=connection,
69 | target_metadata=target_metadata
70 | )
71 |
72 | try:
73 | with context.begin_transaction():
74 | context.run_migrations()
75 | finally:
76 | connection.close()
77 |
78 | if context.is_offline_mode():
79 | run_migrations_offline()
80 | else:
81 | run_migrations_online()
82 |
--------------------------------------------------------------------------------
/db/script.py.mako:
--------------------------------------------------------------------------------
1 | """
2 | ${message}
3 |
4 | Revision ID: ${up_revision}
5 | Revises: ${down_revision}
6 | Create Date: ${create_date}
7 |
8 | """
9 |
10 | # revision identifiers, used by Alembic.
11 | revision = ${repr(up_revision)}
12 | down_revision = ${repr(down_revision)}
13 |
14 | from alembic import op
15 | import sqlalchemy as sa
16 | ${imports if imports else ""}
17 |
18 | def upgrade():
19 | ${upgrades if upgrades else "pass"}
20 |
21 |
22 | def downgrade():
23 | ${downgrades if downgrades else "pass"}
24 |
--------------------------------------------------------------------------------
/fabfile/__init__.py:
--------------------------------------------------------------------------------
1 | from fabric.api import env
2 | from fabric.utils import abort
3 | from fabric.decorators import task
4 | from fabric.context_managers import settings
5 |
6 | # Load configuration
7 | import config
8 |
9 | # Fabfile modules
10 | import app
11 | import db
12 | import bootstrap as _bootstrap
13 | import deployment as code
14 | import puppet
15 | import servers
16 | import virtualenv
17 |
18 |
19 | @task
20 | def bootstrap():
21 | """
22 | Set up a new server (requires superuser credentials).
23 | """
24 | # Very important that we only do this on remote machines and not locally.
25 | if not env.host_string:
26 | abort('You must specify a server to configure using -H.')
27 |
28 | # Use sudo if we're not logging on as root
29 | if env.user != 'root':
30 | env.sudo = True
31 |
32 | # Bootstrap stuff
33 | _bootstrap.software()
34 | _bootstrap.user()
35 | _bootstrap.project()
36 |
37 | # Initial code deploy
38 | code.deploy(warn=False)
39 |
40 | # Initial puppet run
41 | puppet.run()
42 |
43 | # Fix permissions
44 | _bootstrap.chown()
45 |
46 | # Ready to deploy now
47 |
48 |
49 | @task
50 | def build():
51 | """
52 | Execute build tasks.
53 | """
54 | virtualenv.build()
55 | app.build()
56 | db.build()
57 |
58 |
59 | @task
60 | def run():
61 | """
62 | Run app in debug mode (for development).
63 | """
64 | app.run()
65 |
66 |
67 | @task
68 | def test():
69 | """Run tests."""
70 | app.test()
71 |
72 |
73 | @task
74 | def deploy():
75 | """
76 | Deploy to remote environment.
77 |
78 | Deploys code from the current git branch to the remote server and reloads
79 | services so that the new code is in effect.
80 |
81 | The remote server to deploy to is automatically determined based on the
82 | currently checked-out git branch and matched to the configuration specified
83 | in fabfile/deploy/config.py.
84 | """
85 | code.deploy()
86 | # Post-deploy tasks on the remote server
87 | with settings(host_string=servers.remote()):
88 | build()
89 | puppet.run()
90 | app.reload()
91 |
--------------------------------------------------------------------------------
/fabfile/app.py:
--------------------------------------------------------------------------------
1 | """
2 | fabfile module containing application-specific tasks.
3 | """
4 | from fabric.api import task
5 | from fabric.colors import cyan
6 | from fabfile.utils import do
7 | from fabfile.virtualenv import venv_path
8 |
9 |
10 | @task
11 | def build():
12 | """
13 | Run application build tasks.
14 | """
15 | # Generate static assets. Note that we always build assets with the
16 | # production config because dev will never point to compiled files.
17 | print(cyan('\nBuilding static assets...'))
18 | do('mkdir -p app/static/__bundles/css')
19 | do('mkdir -p app/static/__bundles/js')
20 | do('export FLASK_CONFIG=config/production.py && %s/bin/python manage.py build' % venv_path)
21 |
22 |
23 | def run():
24 | """Start app in debug mode (for development)."""
25 | do('export FLASK_CONFIG=config/dev.py && %s/bin/python manage.py runserver' % venv_path)
26 |
27 |
28 | def test():
29 | """Run unit tests"""
30 | print(cyan('\nRunning tests...'))
31 | do('FLASK_CONFIG=config/test.py %s/bin/nosetests --exclude-dir-file=\'.noseexclude\' --with-yanc --with-spec --spec-color -q' % venv_path)
32 |
33 |
34 | def coverage():
35 | """Generate test coverage report"""
36 | do('FLASK_CONFIG=config/test.py %s/bin/nosetests --exclude-dir-file=\'.noseexclude\' --with-cov --cov=app --cov-report=html' % venv_path)
37 |
38 |
39 | def start():
40 | """Start app using init."""
41 | do('sudo start uwsgi')
42 |
43 |
44 | def stop():
45 | """Stop app using init."""
46 | do('sudo stop uwsgi')
47 |
48 |
49 | def reload():
50 | """Restart app using init."""
51 | do('sudo reload uwsgi')
52 |
--------------------------------------------------------------------------------
/fabfile/bootstrap.py:
--------------------------------------------------------------------------------
1 | """
2 | fabfile module for prepping a server for deploy.
3 | """
4 | from fabric.colors import cyan
5 | from fabric.context_managers import settings, hide
6 | from fabfile.utils import do
7 |
8 |
9 | def software():
10 | """
11 | Install required software.
12 | """
13 | with settings(remote_path='/tmp'):
14 |
15 | # Install prerequisites
16 | print(cyan('\nInstalling software...'))
17 | do('apt-get -qq update')
18 | do('apt-get -qq install -y puppet git')
19 |
20 |
21 | def user():
22 | """
23 | Add and configure deploy user.
24 | """
25 | with settings(remote_path='/tmp'):
26 |
27 | # Set up deploy user
28 | print(cyan('\nSetting up deploy user...'))
29 | with settings(hide('warnings'), warn_only=True):
30 | do('useradd tobias')
31 | do('[ -e /home/tobias ] || cp -r /etc/skel /home/tobias')
32 | # Copy authorized_keys from the current user into deploy user's home
33 | do('mkdir -p /home/tobias/.ssh')
34 | do('[ -e ~/.ssh/authorized_keys ] && cp ~/.ssh/authorized_keys /home/tobias/.ssh/')
35 | do('chown -R tobias:tobias /home/tobias')
36 |
37 |
38 | def project():
39 | """
40 | Set up project directory.
41 | """
42 | with settings(remote_path='/tmp'):
43 | # Set up project directory
44 | print(cyan('\nSetting up project directory...'))
45 | do('mkdir -p /srv/www/app')
46 |
47 |
48 | def chown():
49 | """
50 | Fix project directory permissions after an initial deploy.
51 | """
52 | with settings(remote_path='/tmp'):
53 | print(cyan('\nFixing permissions...'))
54 | do('chown -R tobias:tobias /srv/www/app')
55 |
--------------------------------------------------------------------------------
/fabfile/config.py:
--------------------------------------------------------------------------------
1 | """
2 | fabfile bundle config.
3 | """
4 | import sys
5 | from fabric.api import env
6 | from fabric.context_managers import settings
7 | from fabfile.git import branch
8 |
9 | # Attempt to detect branch from git HEAD
10 | with settings(warn_only=True):
11 | env.branch = branch()
12 |
13 | env.remote_path = '/srv/www/app'
14 |
15 | # Check to see if -u was specified at the command line
16 | for opt in sys.argv:
17 | if opt.startswith('-u') or opt.startswith('--user'):
18 | # Set a flag to signifiy -u was specified
19 | env.custom_user = True
20 | break
21 |
22 | # Use -u parameter if it was specified, otherwise default to deploy user
23 | if not env.get('custom_user', False):
24 | env.user = 'tobias'
25 |
--------------------------------------------------------------------------------
/fabfile/db.py:
--------------------------------------------------------------------------------
1 | """
2 | fabfile module for managing database-related tasks.
3 | """
4 | from fabric.api import task
5 | from fabric.context_managers import settings, hide
6 | from fabric.colors import cyan
7 | from fabfile.utils import do
8 | from fabfile.virtualenv import venv_path
9 |
10 | DB = {
11 | 'name': 'app',
12 | 'user': 'www-data',
13 | }
14 |
15 |
16 | @task
17 | def build():
18 | """Initialise and migrate database to latest version."""
19 | print(cyan('\nUpdating database...'))
20 |
21 | # Ensure database exists
22 | if not _pg_db_exists(DB['name']):
23 | do('createdb -O \'%(user)s\' \'%(name)s\'' % DB)
24 |
25 | # Ensure versions folder exists
26 | do('mkdir -p db/versions')
27 |
28 | do('rm -f db/versions/*.pyc')
29 |
30 | # Run migrations
31 | do('%s/bin/alembic -c db/alembic.ini upgrade head' % venv_path)
32 |
33 | # Ensure www-data has permission on all objects
34 | do('psql -tAc \'GRANT ALL ON ALL TABLES IN SCHEMA public TO "%(user)s";\' %(name)s' % DB)
35 | do('psql -tAc \'GRANT ALL ON ALL SEQUENCES IN SCHEMA public TO "%(user)s";\' %(name)s' % DB)
36 | do('psql -tAc \'ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT ALL ON TABLES TO GROUP "%(user)s";\' %(name)s' % DB)
37 | do('psql -tAc \'ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT ALL ON SEQUENCES TO GROUP "%(user)s";\' %(name)s' % DB)
38 |
39 |
40 | @task
41 | def generate(message=None):
42 | """Generates a new Alembic revision based on DB changes."""
43 | args = ''
44 | if message:
45 | args = '-m "%s"' % message
46 | do('%s/bin/alembic -c db/alembic.ini revision --autogenerate %s' % (venv_path, args))
47 |
48 |
49 | def _pg_db_exists(database):
50 | """
51 | Helper function to check if the postgresql database exists.
52 | """
53 | with settings(hide('running', 'warnings'), warn_only=True):
54 | return do('psql -tAc "SELECT 1 FROM pg_database WHERE datname = \'%s\'" postgres |grep -q 1' % database, capture=True).succeeded
55 |
--------------------------------------------------------------------------------
/fabfile/deployment.py:
--------------------------------------------------------------------------------
1 | """
2 | fabfile module that handles deployment of the application to remote servers.
3 | """
4 | import os
5 | from fabric.api import env, local, run, put
6 | from fabric.utils import abort
7 | from fabric.colors import cyan, yellow
8 | from fabric.contrib.console import confirm
9 | from fabric.context_managers import settings, hide
10 | from fabfile.servers import remote
11 |
12 |
13 | def deploy(warn=True):
14 | """
15 | Deploy to remote environment.
16 | """
17 | with settings(host_string=remote()):
18 |
19 | if warn:
20 | # Display confirmation
21 | print('\nYou are about to deploy current branch ' + yellow('%(branch)s' % env, bold=True) + ' to ' + yellow('%(host_string)s' % env, bold=True) + '.')
22 | if not confirm('Continue?', default=False):
23 | abort('User aborted')
24 |
25 | # git-pull
26 | local('git pull origin %(branch)s' % env)
27 |
28 | # Initialise remote git repo
29 | run('git init %(remote_path)s' % env)
30 | run('git --git-dir=%(remote_path)s/.git config receive.denyCurrentBranch ignore' % env)
31 | local('cat %s/deployment/hooks/post-receive.tpl | sed \'s/\$\$BRANCH\$\$/%s/g\' > /tmp/post-receive.tmp' % (os.path.dirname(__file__), env.branch))
32 | put('/tmp/post-receive.tmp', '%(remote_path)s/.git/hooks/post-receive' % env)
33 | run('chmod +x %(remote_path)s/.git/hooks/post-receive' % env)
34 |
35 | # Add server to the local git repo config (as a git remote)
36 | with settings(hide('warnings'), warn_only=True):
37 | local('git remote rm %(branch)s' % env)
38 | local('git remote add %(branch)s ssh://%(user)s@%(host_string)s:%(port)s%(remote_path)s' % env)
39 |
40 | # Push to origin
41 | print(cyan('\nDeploying code...'))
42 | local('git push origin %(branch)s' % env)
43 | local('GIT_SSH=fabfile/deployment/ssh git push %(branch)s %(branch)s' % env)
44 |
--------------------------------------------------------------------------------
/fabfile/deployment/hooks/post-receive.tpl:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | # Git post-receive hook for deployment.
4 | #
5 | # daniel.simmons@tobias.tv
6 | # 2012-03-29
7 | #
8 |
9 | cd "$GIT_DIR/.."
10 |
11 | # These have to be unset, because the fab build (which is executed below) calls
12 | # git again, which will get confused if these variables are already set.
13 | unset GIT_WORK_TREE
14 | unset GIT_DIR
15 |
16 | # Check out correct branch
17 | git checkout $$BRANCH$$
18 |
19 | # Update working tree to reflect new changes
20 | git reset --hard
21 |
22 | echo
23 |
--------------------------------------------------------------------------------
/fabfile/deployment/ssh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | if [ -f "${0%/*}/keys/id_rsa" ]; then
3 | ssh -i "${0%/*}/keys/id_rsa" "$@"
4 | else
5 | ssh -i "${0%/*}/keys/id_rsa" "$@"
6 | fi
7 |
--------------------------------------------------------------------------------
/fabfile/git.py:
--------------------------------------------------------------------------------
1 | """
2 | fabfile module for common git commands - used as a helper by other fabfile
3 | modules.
4 | """
5 | from fabric.api import local
6 | from fabric.context_managers import hide
7 |
8 |
9 | def branch():
10 | """
11 | Returns the name of the local branch that we're currently on.
12 | """
13 | with hide('running'):
14 | result = local('git symbolic-ref -q HEAD', capture=True)
15 | try:
16 | return result.split('/')[2]
17 | except IndexError:
18 | return None
19 |
--------------------------------------------------------------------------------
/fabfile/puppet.py:
--------------------------------------------------------------------------------
1 | """
2 | fabfile module containing Puppet-related tasks.
3 | """
4 | from fabfile.utils import do
5 | from fabric.colors import cyan
6 | from fabric.context_managers import settings
7 | from fabric.contrib.console import confirm
8 | from fabric.decorators import task
9 | from fabric.tasks import execute
10 | from fabric.utils import abort
11 |
12 | import servers
13 |
14 |
15 | def check_syntax():
16 | """
17 | Syntax check on Puppet config.
18 | """
19 | print cyan('\nChecking puppet syntax...')
20 | do("find puppet -type f -name '*.pp' | xargs puppet parser validate")
21 |
22 |
23 | @task
24 | def remote(tag=None):
25 | """
26 | Run Puppet on remote servers.
27 | """
28 | if tag is None:
29 | if not confirm('Initiate Puppet run on all hosts?', default=False):
30 | abort('User aborted.')
31 |
32 | with settings(hosts=servers.remotes(tag=tag)):
33 | execute('code.deploy')
34 | execute('puppet.run')
35 |
36 |
37 | @task
38 | def run(debug=False):
39 | """
40 | Apply Puppet manifest.
41 | """
42 | check_syntax()
43 |
44 | print cyan('\nApplying puppet manifest...')
45 | if debug:
46 | debug = '--debug'
47 | else:
48 | debug = ''
49 | do('sudo /usr/bin/puppet apply puppet/manifests/default.pp '
50 | '--modulepath=puppet/modules {0}'.format(debug))
51 |
--------------------------------------------------------------------------------
/fabfile/servers.json:
--------------------------------------------------------------------------------
1 | {
2 | "uat": "",
3 | "production": ""
4 | }
5 |
--------------------------------------------------------------------------------
/fabfile/servers.py:
--------------------------------------------------------------------------------
1 | """
2 | fabfile module that provides a helper for other modules to programmatically
3 | execute a task on the remote server (as specified by the git branch/server
4 | configuration mapping).
5 | """
6 | import os
7 | import json
8 | from fabric.api import env, task
9 | from fabric.utils import abort
10 |
11 | # Read server config from JSON file.
12 | fp = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'servers.json')
13 | try:
14 | env.servers = json.load(open(fp, 'r'))
15 | except:
16 | env.servers = {}
17 |
18 |
19 | def remote():
20 | """
21 | Returns the current remote server (host_string). If there is none, look up
22 | the remote server from the current git branch and branch/server config.
23 | """
24 | if env.host_string:
25 | # If host_string is already specified, use that. This allows the user to
26 | # override the target deploy server on the command-line.
27 | return env.host_string
28 | else:
29 | branch = env.branch
30 | if branch not in env.servers:
31 | abort('Branch does not correspond to server and no host specified.')
32 | return env.servers[branch]
33 |
34 |
35 | def save():
36 | """
37 | Write server config to JSON file.
38 | """
39 | json.dump(env.servers, open(fp, 'w'), indent=4)
40 |
--------------------------------------------------------------------------------
/fabfile/utils.py:
--------------------------------------------------------------------------------
1 | """
2 | fabfile module that provides generic helper functions for other modules.
3 | """
4 | import os
5 | from fabric.api import env, local, run as fab_run
6 | from fabric.context_managers import cd, lcd
7 |
8 |
9 | def do(cmd, capture=False, *args, **kwargs):
10 | """
11 | Runs command locally or remotely depending on whether a remote host has
12 | been specified.
13 | """
14 | if env.host_string or env.host or env.hosts:
15 | with cd(env.remote_path):
16 | if env.get('sudo', False):
17 | cmd = 'sudo %s' % cmd
18 | return fab_run(cmd, *args, **kwargs)
19 | else:
20 | # project root path is the default working directory
21 | path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
22 | if env['lcwd']:
23 | # lcd has already been invoked. If it's with a relative path, let's
24 | # make that relative to the project root
25 | if not env['lcwd'].startswith('/'):
26 | path = '%s/%s' % (path, env['lcwd'])
27 | else:
28 | # Honour the current lcd contact if it's an absolute path
29 | path = env['lcwd']
30 | with lcd(path):
31 | # Add shell envs
32 | for name, val in env.shell_env.iteritems():
33 | cmd = 'export {name}="{val}" && {cmd}'.format(name=name,
34 | val=val,
35 | cmd=cmd)
36 | # Add command prefixes to local commands
37 | for prefix in env.command_prefixes:
38 | cmd = '{prefix} && {cmd}'.format(prefix=prefix, cmd=cmd)
39 | return local(cmd, *args, capture=capture, **kwargs)
40 |
--------------------------------------------------------------------------------
/fabfile/virtualenv.py:
--------------------------------------------------------------------------------
1 | """
2 | fabfile module that handles virtualenv-related tasks.
3 | """
4 | from fabric.context_managers import settings, hide
5 | from fabric.colors import cyan, red
6 | from fabric.utils import abort
7 | from fabfile.utils import do
8 |
9 | venv_path = '.venv'
10 | pip_cache_path = '.cache/pip'
11 |
12 |
13 | def build():
14 | """Build or update the virtualenv."""
15 | with settings(hide('stdout')):
16 | print(cyan('\nUpdating venv, installing packages...'))
17 | do('[ -e %s ] || virtualenv %s --distribute --no-site-packages' % (venv_path, venv_path))
18 | do('mkdir -p %s' % pip_cache_path)
19 | # annoyingly, pip prints errors to stdout (instead of stderr), so we
20 | # have to check the return code and output only if there's an error.
21 | with settings(warn_only=True):
22 | pip = do('%s/bin/pip install --download-cache %s -r requirements.txt' % (venv_path, pip_cache_path), capture=True)
23 | if pip.failed:
24 | print(red(pip))
25 | abort("pip exited with return code %i" % pip.return_code)
26 |
--------------------------------------------------------------------------------
/manage.py:
--------------------------------------------------------------------------------
1 | import subprocess
2 | from os.path import join
3 | from app import create_app
4 | from flask import current_app
5 | from flask.ext.script import Shell, Manager, Server
6 |
7 | manager = Manager(create_app)
8 |
9 |
10 | def _make_shell_context():
11 | """
12 | Shell context: import helper objects here.
13 | """
14 | return dict(app=current_app)
15 |
16 |
17 | manager.add_option('--flask-config', dest='config', help='Specify Flask config file', required=False)
18 | manager.add_command('shell', Shell(make_context=_make_shell_context))
19 | manager.add_command('runserver', Server(host='0.0.0.0'))
20 |
21 |
22 | @manager.command
23 | def build():
24 | """
25 | Build static assets.
26 | """
27 | from app.assets import init
28 | assets = init(current_app)
29 | assets.build_all()
30 |
31 |
32 | if __name__ == '__main__':
33 | manager.run()
34 |
--------------------------------------------------------------------------------
/puppet/manifests/bootstrap/apt-update.pp:
--------------------------------------------------------------------------------
1 | #
2 | # apt-update bootstrap
3 | #
4 | # Ubuntu vagrant boxes ship with US apt mirrors which are slow. Here
5 | # we overwrite them with the UK ones prior to running an apt-get update.
6 | #
7 |
8 | include apt
9 |
10 | class { 'apt::sources':
11 | mirror => 'http://gb.archive.ubuntu.com/ubuntu/',
12 | }
13 |
--------------------------------------------------------------------------------
/puppet/manifests/config.pp:
--------------------------------------------------------------------------------
1 | #
2 | # Global variables.
3 | #
4 |
5 | # User that is installed to facilitate app deploys
6 | $deploy_user = 'deploy'
7 |
8 | # Path to the application
9 | $app_path = '/srv/www/app'
10 |
--------------------------------------------------------------------------------
/puppet/manifests/default.pp:
--------------------------------------------------------------------------------
1 | import 'config.pp'
2 | import 'lib/*.pp'
3 |
4 | # Import node config for different environments
5 | import 'environments/*.pp'
6 |
7 | #
8 | # Defaults.
9 | #
10 | node default {
11 | include cssmin
12 | include fabric
13 | include git
14 | include nginx
15 | include openssl
16 | include postfix
17 | include postgresql
18 | include puppet::sudoers
19 | include python::packages
20 | include rsyslog
21 | include sysctl
22 | include uglifyjs
23 |
24 | # Set timezone to Europe/London
25 | file { '/etc/localtime':
26 | source => '/usr/share/zoneinfo/Europe/London',
27 | # Restart syslog so log times are correct
28 | notify => Service[rsyslog],
29 | }
30 |
31 | # Create postgresql roles for the app and deploy user
32 | postgresql::role { 'www-data':
33 | ensure => present,
34 | }
35 | }
36 |
37 |
38 | #
39 | # Base class for externally hosted production nodes.
40 | #
41 | class site inherits default {
42 | include users::deploy
43 |
44 | # Firewall
45 | class { 'ferm':
46 | public_ports => [
47 | 'http',
48 | 'https',
49 | ],
50 | }
51 |
52 | # Newrelic server monitoring
53 | class { 'newrelic::servermon':
54 | key => '3c11e611ab565cd0936ed88137ba555ca1500dc0',
55 | }
56 |
57 | # Give deploy user access to create and update the database
58 | postgresql::role { $::deploy_user:
59 | ensure => present,
60 | createdb => true, # This user creates the
61 | grant => 'www-data', # app database.
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/puppet/manifests/environments/production.pp:
--------------------------------------------------------------------------------
1 | #
2 | # Production node(s). Rename or inherit from this.
3 | #
4 | node production inherits site {
5 | include uwsgi
6 |
7 | nginx::site { 'app':
8 | ssl_cert => '/etc/ssl/certs/your-cert-here.pem',
9 | ssl_cert_key => '/etc/ssl/private/your-key-here.key',
10 | }
11 |
12 | uwsgi::app { 'app':
13 | uwsgi_options => [
14 | [ processes => $::processorcount ],
15 | [ module => 'app:create_app()' ],
16 | [ env => [
17 | 'FLASK_CONFIG=config/production.py',
18 | ]],
19 | ],
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/puppet/manifests/environments/vagrant.pp:
--------------------------------------------------------------------------------
1 | #
2 | # Standalone manifest - for dev Vagrant box.
3 | #
4 | node vagrant-ubuntu-trusty-64 inherits default {
5 | include vagrant
6 | include vagrant::pip
7 |
8 | postgresql::role { 'vagrant':
9 | ensure => present,
10 | createdb => true,
11 | grant => 'www-data',
12 | }
13 |
14 | nginx::site { 'app':
15 | ssl_cert => '/etc/ssl/certs/ssl-cert-snakeoil.pem',
16 | ssl_cert_key => '/etc/ssl/private/ssl-cert-snakeoil.key',
17 | }
18 |
19 | # Install uwsgi, but don't run automatically at boot
20 | class { 'uwsgi':
21 | ensure => stopped,
22 | }
23 |
24 | uwsgi::app { 'app':
25 | uwsgi_options => [
26 | [ processes => $::processorcount ],
27 | [ module => 'app:create_app()' ],
28 | [ env => [
29 | 'FLASK_CONFIG=config/dev.py',
30 | ]],
31 | ],
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/puppet/manifests/lib/line.pp:
--------------------------------------------------------------------------------
1 | define line($file, $line, $ensure = 'present') {
2 | case $ensure {
3 | default : { err ( "unknown ensure value ${ensure}" ) }
4 | present: {
5 | exec { "/bin/echo '${line}' >> '${file}'":
6 | unless => "/bin/grep -qFx '${line}' '${file}'"
7 | }
8 | }
9 | absent: {
10 | exec { "/bin/grep -vFx '${line}' '${file}' | /usr/bin/tee '${file}' >/dev/null 2>&1":
11 | onlyif => "/bin/grep -qFx '${line}' '${file}'"
12 | }
13 | }
14 | uncomment: {
15 | exec { "/bin/sed -i -e'/${line}/s/#\\+//' '${file}'":
16 | onlyif => "/bin/grep '${line}' '${file}' | /bin/grep '^#' | /usr/bin/wc -l"
17 | }
18 | }
19 | comment: {
20 | exec { "/bin/sed -i -e'/${line}/s/\\(.\\+\\)$/#\\1/' '${file}'":
21 | onlyif => "/usr/bin/test `/bin/grep '${line}' '${file}' | /bin/grep -v '^#' | /usr/bin/wc -l` -ne 0"
22 | }
23 | }
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/puppet/modules/apt/manifests/init.pp:
--------------------------------------------------------------------------------
1 | #
2 | # Ensure apt sources cache is up-to-date.
3 | #
4 | class apt {
5 | exec { 'apt-update':
6 | command => '/usr/bin/apt-get -qq update'
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/puppet/modules/apt/manifests/sources.pp:
--------------------------------------------------------------------------------
1 | #
2 | # Installs the default Ubuntu apt sources.
3 | #
4 | class apt::sources(
5 | $dist = 'trusty',
6 | $mirror = 'http://gb.archive.ubuntu.com/ubuntu/'
7 | ) {
8 | file { '/etc/apt/sources.list':
9 | content => template("apt/${dist}.list.tpl"),
10 | before => Exec['apt-update'],
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/puppet/modules/apt/templates/precise.list.tpl:
--------------------------------------------------------------------------------
1 | #
2 |
3 | # deb cdrom:[Ubuntu-Server 12.04 LTS _Precise Pangolin_ - Release amd64 (20120424.1)]/ dists/precise/main/binary-i386/
4 | # deb cdrom:[Ubuntu-Server 12.04 LTS _Precise Pangolin_ - Release amd64 (20120424.1)]/ dists/precise/restricted/binary-i386/
5 | # deb cdrom:[Ubuntu-Server 12.04 LTS _Precise Pangolin_ - Release amd64 (20120424.1)]/ precise main restricted
6 |
7 | # deb cdrom:[Ubuntu-Server 12.04 LTS _Precise Pangolin_ - Release amd64 (20120424.1)]/ dists/precise/main/binary-i386/
8 | # deb cdrom:[Ubuntu-Server 12.04 LTS _Precise Pangolin_ - Release amd64 (20120424.1)]/ dists/precise/restricted/binary-i386/
9 | # deb cdrom:[Ubuntu-Server 12.04 LTS _Precise Pangolin_ - Release amd64 (20120424.1)]/ precise main restricted
10 |
11 | # See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
12 | # newer versions of the distribution.
13 | deb <%= mirror %> precise main restricted
14 | deb-src <%= mirror %> precise main restricted
15 |
16 | ## Major bug fix updates produced after the final release of the
17 | ## distribution.
18 | deb <%= mirror %> precise-updates main restricted
19 | deb-src <%= mirror %> precise-updates main restricted
20 |
21 | ## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
22 | ## team. Also, please note that software in universe WILL NOT receive any
23 | ## review or updates from the Ubuntu security team.
24 | deb <%= mirror %> precise universe
25 | deb-src <%= mirror %> precise universe
26 | deb <%= mirror %> precise-updates universe
27 | deb-src <%= mirror %> precise-updates universe
28 |
29 | ## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
30 | ## team, and may not be under a free licence. Please satisfy yourself as to
31 | ## your rights to use the software. Also, please note that software in
32 | ## multiverse WILL NOT receive any review or updates from the Ubuntu
33 | ## security team.
34 | deb <%= mirror %> precise multiverse
35 | deb-src <%= mirror %> precise multiverse
36 | deb <%= mirror %> precise-updates multiverse
37 | deb-src <%= mirror %> precise-updates multiverse
38 |
39 | ## N.B. software from this repository may not have been tested as
40 | ## extensively as that contained in the main release, although it includes
41 | ## newer versions of some applications which may provide useful features.
42 | ## Also, please note that software in backports WILL NOT receive any review
43 | ## or updates from the Ubuntu security team.
44 | deb <%= mirror %> precise-backports main restricted universe multiverse
45 | deb-src <%= mirror %> precise-backports main restricted universe multiverse
46 |
47 | deb http://security.ubuntu.com/ubuntu precise-security main restricted
48 | deb-src http://security.ubuntu.com/ubuntu precise-security main restricted
49 | deb http://security.ubuntu.com/ubuntu precise-security universe
50 | deb-src http://security.ubuntu.com/ubuntu precise-security universe
51 | deb http://security.ubuntu.com/ubuntu precise-security multiverse
52 | deb-src http://security.ubuntu.com/ubuntu precise-security multiverse
53 |
54 | ## Uncomment the following two lines to add software from Canonical's
55 | ## 'partner' repository.
56 | ## This software is not part of Ubuntu, but is offered by Canonical and the
57 | ## respective vendors as a service to Ubuntu users.
58 | # deb http://archive.canonical.com/ubuntu precise partner
59 | # deb-src http://archive.canonical.com/ubuntu precise partner
60 |
61 | ## Uncomment the following two lines to add software from Ubuntu's
62 | ## 'extras' repository.
63 | ## This software is not part of Ubuntu, but is offered by third-party
64 | ## developers who want to ship their latest software.
65 | # deb http://extras.ubuntu.com/ubuntu precise main
66 | # deb-src http://extras.ubuntu.com/ubuntu precise main
67 |
--------------------------------------------------------------------------------
/puppet/modules/apt/templates/trusty.list.tpl:
--------------------------------------------------------------------------------
1 | ## Note, this file is written by cloud-init on first boot of an instance
2 | ## modifications made here will not survive a re-bundle.
3 | ## if you wish to make changes you can:
4 | ## a.) add 'apt_preserve_sources_list: true' to /etc/cloud/cloud.cfg
5 | ## or do the same in user-data
6 | ## b.) add sources in /etc/apt/sources.list.d
7 | ## c.) make changes to template file /etc/cloud/templates/sources.list.tmpl
8 | #
9 |
10 | # See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
11 | # newer versions of the distribution.
12 | deb <%= @mirror %> trusty main
13 | deb-src <%= @mirror %> trusty main
14 |
15 | ## Major bug fix updates produced after the final release of the
16 | ## distribution.
17 | deb <%= @mirror %> trusty-updates main
18 | deb-src <%= @mirror %> trusty-updates main
19 |
20 | ## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
21 | ## team. Also, please note that software in universe WILL NOT receive any
22 | ## review or updates from the Ubuntu security team.
23 | deb <%= @mirror %> trusty universe
24 | deb-src <%= @mirror %> trusty universe
25 | deb <%= @mirror %> trusty-updates universe
26 | deb-src <%= @mirror %> trusty-updates universe
27 |
28 | ## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
29 | ## team, and may not be under a free licence. Please satisfy yourself as to
30 | ## your rights to use the software. Also, please note that software in
31 | ## multiverse WILL NOT receive any review or updates from the Ubuntu
32 | ## security team.
33 | # deb <%= @mirror %> trusty multiverse
34 | # deb-src <%= @mirror %> trusty multiverse
35 | # deb <%= @mirror %> trusty-updates multiverse
36 | # deb-src <%= @mirror %> trusty-updates multiverse
37 |
38 | ## Uncomment the following two lines to add software from the 'backports'
39 | ## repository.
40 | ## N.B. software from this repository may not have been tested as
41 | ## extensively as that contained in the main release, although it includes
42 | ## newer versions of some applications which may provide useful features.
43 | ## Also, please note that software in backports WILL NOT receive any review
44 | ## or updates from the Ubuntu security team.
45 | # deb <%= @mirror %> trusty-backports main restricted universe multiverse
46 | # deb-src <%= @mirror %> trusty-backports main restricted universe multiverse
47 |
48 | ## Uncomment the following two lines to add software from Canonical's
49 | ## 'partner' repository.
50 | ## This software is not part of Ubuntu, but is offered by Canonical and the
51 | ## respective vendors as a service to Ubuntu users.
52 | # deb http://archive.canonical.com/ubuntu trusty partner
53 | # deb-src http://archive.canonical.com/ubuntu trusty partner
54 |
55 | deb http://security.ubuntu.com/ubuntu trusty-security main
56 | deb-src http://security.ubuntu.com/ubuntu trusty-security main
57 | deb http://security.ubuntu.com/ubuntu trusty-security universe
58 | deb-src http://security.ubuntu.com/ubuntu trusty-security universe
59 | # deb http://security.ubuntu.com/ubuntu trusty-security multiverse
60 | # deb-src http://security.ubuntu.com/ubuntu trusty-security multiverse
61 |
--------------------------------------------------------------------------------
/puppet/modules/cssmin/manifests/init.pp:
--------------------------------------------------------------------------------
1 | class cssmin {
2 | package {'cssmin':
3 | ensure => installed,
4 | }
5 | }
6 |
--------------------------------------------------------------------------------
/puppet/modules/fabric/manifests/init.pp:
--------------------------------------------------------------------------------
1 | #
2 | # Ensure Fabric is installed.
3 | #
4 | # Fabric is used for app deployment.
5 | #
6 | class fabric {
7 | package { 'fabric':
8 | ensure => 'present',
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/puppet/modules/ferm/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 |
635 | Copyright (C)
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | Copyright (C)
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
675 |
--------------------------------------------------------------------------------
/puppet/modules/ferm/README:
--------------------------------------------------------------------------------
1 |
2 | Overview
3 | ========
4 |
5 | This puppet module manages ferm and its rules.
6 |
7 | Variables
8 | =========
9 |
10 |
11 | Classes
12 | =======
13 |
14 | ferm
15 | ----
16 |
17 | The ferm class performs all steps needed to the use of ferm such as package
18 | installation and configuration. Specific rules can be added later with
19 | ferm::rule or specific classes.
20 |
21 |
22 | Defines
23 | =======
24 |
25 | ferm::rule
26 | ----------
27 |
28 | Add a rule to the ferm rules.d directory
29 |
30 | Variables used :
31 | $host = false,
32 | $table="filter",
33 | $chain="INPUT",
34 | $rule,
35 | $description="",
36 | $prio="00",
37 | $notarule=false
38 |
39 | ferm::hook
40 | ----------
41 |
42 | Add a hook to the ferm conf.d directory.
43 |
44 | Example:
45 |
46 | ferm::hook { 'conntrack_ftp':
47 | description => 'Module nf_conntrack_ftp pour proftpd',
48 | content_hook => 'modprobe nf_conntrack_ftp'
49 | }
50 |
51 | Licensing
52 | =========
53 |
54 | This puppet module is licensed under the GPL version 3 or later. Redistribution
55 | and modification is encouraged.
56 |
57 | The GPL version 3 license text can be found in the "LICENSE" file accompanying
58 | this puppet module, or at the following URL:
59 |
60 | http://www.gnu.org/licenses/gpl-3.0.html
61 |
--------------------------------------------------------------------------------
/puppet/modules/ferm/files/ferm.conf:
--------------------------------------------------------------------------------
1 | ##
2 | ## THIS FILE IS UNDER PUPPET CONTROL. DON'T EDIT IT HERE.
3 | ##
4 |
5 | # -*- shell-script -*-
6 |
7 | @include 'conf.d/';
8 |
9 | domain (ip ip6) {
10 | table filter {
11 |
12 | chain INPUT {
13 | policy DROP;
14 | # connection tracking
15 | mod state state INVALID DROP;
16 | mod state state (ESTABLISHED RELATED) ACCEPT;
17 |
18 | # allow ping
19 | proto icmp ACCEPT;
20 |
21 | # allow local packet
22 | interface lo ACCEPT;
23 | }
24 |
25 | chain OUTPUT {
26 | policy ACCEPT;
27 | # connection tracking
28 | mod state state (ESTABLISHED RELATED) ACCEPT;
29 | }
30 |
31 | chain FORWARD {
32 | policy ACCEPT;
33 | # connection tracking
34 | mod state state INVALID DROP;
35 | mod state state (ESTABLISHED RELATED) ACCEPT;
36 | }
37 | }
38 | }
39 |
40 | @include 'rules.d/';
41 |
42 | # vim:set et:
43 |
--------------------------------------------------------------------------------
/puppet/modules/ferm/files/ferm.default:
--------------------------------------------------------------------------------
1 | # configuration for /etc/init.d/ferm
2 |
3 | # use iptables-restore for fast firewall initialization?
4 | FAST=yes
5 |
6 | # cache the output of ferm --lines in /var/cache/ferm?
7 | CACHE=yes
8 |
9 | # additional paramaters for ferm (like --def '$foo=bar')
10 | OPTIONS=
11 |
12 | # Enable ferm on bootup?
13 | ENABLED=yes
14 |
15 |
--------------------------------------------------------------------------------
/puppet/modules/ferm/manifests/hook.pp:
--------------------------------------------------------------------------------
1 | define ferm::hook (
2 | $description=undef,
3 | $content_hook=undef
4 | )
5 | {
6 | file { "/etc/ferm/conf.d/hook_${name}":
7 | ensure => present,
8 | owner => root,
9 | group => root,
10 | mode => 0400,
11 | content => template('ferm/hook.erb'),
12 | notify => Service['ferm'];
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/puppet/modules/ferm/manifests/init.pp:
--------------------------------------------------------------------------------
1 | class ferm {
2 |
3 | package { 'ferm':
4 | ensure => installed
5 | }
6 |
7 | file {
8 | '/etc/ferm/rules.d':
9 | ensure => directory,
10 | purge => true,
11 | owner => root,
12 | group => root,
13 | force => true,
14 | recurse => true,
15 | notify => Service['ferm'],
16 | require => Package['ferm'];
17 | '/etc/ferm':
18 | ensure => directory,
19 | owner => root,
20 | group => root,
21 | mode => 0755;
22 | '/etc/ferm/conf.d':
23 | ensure => directory,
24 | owner => root,
25 | group => root,
26 | require => Package['ferm'];
27 | '/etc/default/ferm':
28 | source => 'puppet:///modules/ferm/ferm.default',
29 | owner => root,
30 | group => root,
31 | require => Package['ferm'],
32 | notify => Service['ferm'];
33 | '/etc/ferm/ferm.conf':
34 | source => 'puppet:///modules/ferm/ferm.conf',
35 | owner => root,
36 | group => root,
37 | require => Package['ferm'],
38 | mode => 0400,
39 | notify => Service['ferm'];
40 | '/etc/ferm/conf.d/defs.conf':
41 | content => template('ferm/defs.conf.erb'),
42 | owner => root,
43 | group => root,
44 | require => Package['ferm'],
45 | mode => 0400,
46 | notify => Service['ferm'];
47 | }
48 |
49 | service { 'ferm':
50 | ensure => running,
51 | require => Package['ferm']
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/puppet/modules/ferm/manifests/rule.pp:
--------------------------------------------------------------------------------
1 | define ferm::rule
2 | (
3 | $host=false,
4 | $table='filter',
5 | $chain='INPUT',
6 | $rules,
7 | $description='',
8 | $prio='00',
9 | $notarule=false
10 | )
11 | {
12 | file { "/etc/ferm/rules.d/${prio}_${name}":
13 | ensure => present,
14 | owner => root,
15 | group => root,
16 | mode => 0400,
17 | content => template('ferm/ferm-rule.erb'),
18 | notify => Service['ferm'];
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/puppet/modules/ferm/manifests/rule/custom.pp:
--------------------------------------------------------------------------------
1 | define ferm::rule::custom
2 | (
3 | $content = '',
4 | $prio = "50",
5 | )
6 | {
7 | file { "/etc/ferm/rules.d/${prio}_${name}":
8 | ensure => present,
9 | owner => root,
10 | group => root,
11 | mode => 0400,
12 | content => $content,
13 | notify => Service['ferm'];
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/puppet/modules/ferm/manifests/rules/bittorrent.pp:
--------------------------------------------------------------------------------
1 | class ferm::bittorrent {
2 | @ferm::rule { "bittorrent":
3 | description => "Allow smtp access",
4 | rule => "&SERVICE( ( tcp udp), 51413 )"
5 | }
6 | @ferm::rule { "bttrack":
7 | description => "Allow bttrack access",
8 | rule => "&SERVICE( tcp, 6969 )"
9 | }
10 | }
11 |
12 |
--------------------------------------------------------------------------------
/puppet/modules/ferm/manifests/rules/dns.pp:
--------------------------------------------------------------------------------
1 | class ferm::dns {
2 | @ferm::rule { "dns":
3 | description => "Allow dns access",
4 | rule => "&SERVICE( (tcp udp), domain)"
5 | }
6 | }
7 |
8 |
--------------------------------------------------------------------------------
/puppet/modules/ferm/manifests/rules/ftp.pp:
--------------------------------------------------------------------------------
1 | class ferm::ftp {
2 | @ferm::rule { "dsa-ftp":
3 | description => "Allow ftp access",
4 | rule => "&SERVICE(tcp, 21)"
5 | }
6 | }
7 |
--------------------------------------------------------------------------------
/puppet/modules/ferm/manifests/rules/git.pp:
--------------------------------------------------------------------------------
1 | class ferm::git {
2 | @ferm::rule { "git":
3 | description => "Allow git access",
4 | rule => "&SERVICE(tcp, 9418)"
5 | }
6 | }
7 |
8 |
--------------------------------------------------------------------------------
/puppet/modules/ferm/manifests/rules/imaps.pp:
--------------------------------------------------------------------------------
1 | class ferm::imaps {
2 | @ferm::rule { "imaps":
3 | description => "Allow imaps access",
4 | rule => "&SERVICE( tcp, imaps)"
5 | }
6 | }
7 |
8 |
--------------------------------------------------------------------------------
/puppet/modules/ferm/manifests/rules/jabber.pp:
--------------------------------------------------------------------------------
1 | class ferm::jabber {
2 | @ferm::rule { "jabber":
3 | description => "Allow jabber access",
4 | rule => "&SERVICE(tcp, (5222 5223 5269 5280))"
5 | }
6 | }
7 |
8 |
--------------------------------------------------------------------------------
/puppet/modules/ferm/manifests/rules/rsync.pp:
--------------------------------------------------------------------------------
1 | class ferm::rsync {
2 | @ferm::rule { "dsa-rsync":
3 | description => "Allow rsync access",
4 | rule => "&SERVICE(tcp, 873)"
5 | }
6 | }
7 |
8 |
--------------------------------------------------------------------------------
/puppet/modules/ferm/manifests/rules/smtp.pp:
--------------------------------------------------------------------------------
1 | class ferm::smtp {
2 | @ferm::rule { "smtp":
3 | description => "Allow smtp access",
4 | rule => "&SERVICE(tcp, smtp)"
5 | }
6 | }
7 |
8 |
--------------------------------------------------------------------------------
/puppet/modules/ferm/manifests/rules/www.pp:
--------------------------------------------------------------------------------
1 | class ferm::www {
2 | @ferm::rule { "www":
3 | description => "Allow www access",
4 | rule => "&SERVICE(tcp, (http https))"
5 | }
6 | }
7 |
8 |
--------------------------------------------------------------------------------
/puppet/modules/ferm/templates/defs.conf.erb:
--------------------------------------------------------------------------------
1 | ##
2 | ## THIS FILE IS UNDER PUPPET CONTROL. DON'T EDIT IT HERE.
3 | ##
4 |
5 | @def &SERVICE($proto, $port) = {
6 | proto $proto mod state state (NEW) dport $port ACCEPT;
7 | }
8 |
9 | @def &SERVICE_RANGE($proto, $port, $srange) = {
10 | proto $proto mod state state (NEW) dport $port @subchain "$port" { saddr @ipfilter($srange) ACCEPT; }"
11 | }
12 |
13 | @def &TCP_UDP_SERVICE($port) = {
14 | proto (tcp udp) mod state state (NEW) dport $port ACCEPT;
15 | }
16 |
17 | @def &TCP_UDP_SERVICE_RANGE($port, $srange) = {
18 | proto (tcp udp) mod state state (NEW) dport $port @subchain "$port" { saddr @ipfilter($srange) ACCEPT; }"
19 | }
20 |
--------------------------------------------------------------------------------
/puppet/modules/ferm/templates/ferm-rule.erb:
--------------------------------------------------------------------------------
1 | ##
2 | ## THIS FILE IS UNDER PUPPET CONTROL. DON'T EDIT IT HERE.
3 | ## <%= description %>
4 | ##
5 |
6 | table <%= table %> {
7 | chain <%= chain %> {
8 | <% if host != false %>saddr <%= host %> {
9 | <% end -%>
10 | <% rules.each do |rule| %> <%= rule %>;
11 | <% end -%>
12 | <% if host != false %>}<% end -%>
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/puppet/modules/ferm/templates/hook.erb:
--------------------------------------------------------------------------------
1 | ##
2 | ## THIS FILE IS UNDER PUPPET CONTROL. DON'T EDIT IT HERE.
3 | ## <%= description %>
4 | ##
5 |
6 | @hook pre "<%= content_hook %>";
7 |
--------------------------------------------------------------------------------
/puppet/modules/git/manifests/init.pp:
--------------------------------------------------------------------------------
1 | #
2 | # Ensure git is installed.
3 | #
4 | class git {
5 | package { 'git':
6 | ensure => installed,
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/puppet/modules/newrelic/files/newrelic.gpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dansimau/flask-bootstrap/4a026d58f8722a008d22ce86bec3531850f64ba9/puppet/modules/newrelic/files/newrelic.gpg
--------------------------------------------------------------------------------
/puppet/modules/newrelic/files/newrelic.list:
--------------------------------------------------------------------------------
1 | deb http://apt.newrelic.com/debian/ newrelic non-free
2 |
--------------------------------------------------------------------------------
/puppet/modules/newrelic/manifests/servermon.pp:
--------------------------------------------------------------------------------
1 | #
2 | # Ensure New Relic server monitoring daemon is installed and up-to-date.
3 | #
4 | class newrelic::servermon( $key = $::newrelic_key ) {
5 | # Add newrelic apt repo
6 | file { '/etc/apt/sources.list.d/newrelic.list':
7 | ensure => present,
8 | owner => root,
9 | group => root,
10 | mode => '0644',
11 | source => 'puppet:///modules/newrelic/newrelic.list'
12 | }
13 | file { '/etc/apt/trusted.gpg.d/newrelic.gpg':
14 | ensure => present,
15 | owner => root,
16 | group => root,
17 | mode => '0644',
18 | source => 'puppet:///modules/newrelic/newrelic.gpg',
19 | subscribe => File['/etc/apt/sources.list.d/newrelic.list'],
20 | }
21 | exec { 'newrelic-apt-refresh':
22 | command => '/usr/bin/apt-get update',
23 | subscribe => File['/etc/apt/trusted.gpg.d/newrelic.gpg'],
24 | refreshonly => true,
25 | }
26 | package { 'newrelic-sysmond':
27 | ensure => latest,
28 | subscribe => Exec['newrelic-apt-refresh']
29 | }
30 | # Configuration
31 | file { '/etc/newrelic/nrsysmond.cfg':
32 | ensure => present,
33 | owner => root,
34 | group => newrelic,
35 | mode => '0640',
36 | content => template('newrelic/nrsysmond.cfg.tpl'),
37 | require => Package['newrelic-sysmond'],
38 | }
39 | service { 'newrelic-sysmond':
40 | ensure => running,
41 | subscribe => File['/etc/newrelic/nrsysmond.cfg']
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/puppet/modules/newrelic/templates/nrsysmond.cfg.tpl:
--------------------------------------------------------------------------------
1 | #
2 | # New Relic Server Monitor configuration file.
3 | #
4 | # Lines that begin with a # are comment lines and are ignored by the server
5 | # monitor. For those options that have command line equivalents, if the
6 | # option is specified on the command line it will over-ride any value set
7 | # in this file.
8 | #
9 |
10 | #
11 | # Option : license_key
12 | # Value : 40-character hexadecimal string provided by New Relic. This is
13 | # required in order for the server monitor to start.
14 | # Default: none
15 | #
16 | license_key=<%= key %>
17 |
18 | #
19 | # Option : loglevel
20 | # Value : Level of detail you want in the log file (as defined by the logfile
21 | # setting below. Valid values are (in increasing levels of verbosity):
22 | # error - show errors only
23 | # warning - show errors and warnings
24 | # info - show minimal additional information messages
25 | # verbose - show more detailed information messages
26 | # debug - show debug messages
27 | # verbosedebug - show very detailed debug messages
28 | # Default: error
29 | # Note : Can also be set with the -d command line option.
30 | #
31 | loglevel=info
32 |
33 | #
34 | # Option : logfile
35 | # Value : Name of the file where the server monitor will store it's log
36 | # messages. The amount of detail stored in this file is controlled
37 | # by the loglevel option (above).
38 | # Default: none. However it is highly recommended you set a value for this.
39 | # Note : Can also be set with the -l command line option.
40 | #
41 | logfile=/var/log/newrelic/nrsysmond.log
42 |
43 | #
44 | # Option : proxy
45 | # Value : The name and optional login credentials of the proxy server to use
46 | # for all communication with the New Relic collector. In its simplest
47 | # form this setting is just a hostname[:port] setting. The default
48 | # port if none is specified is 1080. If your proxy requires a user
49 | # name, use the syntax user@host[:port]. If it also requires a
50 | # password use the format user:password@host[:port]. For example:
51 | # fred:secret@proxy.mydomain.com:8181
52 | # Default: none (use a direct connection)
53 | #
54 | #proxy=
55 |
56 | #
57 | # Option : ssl
58 | # Value : Whether or not to use the Secure Sockets Layer (SSL) for all
59 | # communication with the New Relic collector. Possible values are
60 | # true/on or false/off. In certain rare cases you may need to modify
61 | # the SSL certificates settings below.
62 | # Default: false
63 | #
64 | #ssl=false
65 |
66 | #
67 | # Option : ssl_ca_bundle
68 | # Value : The name of a PEM-encoded Certificate Authority (CA) bundle to use
69 | # for SSL connections. This very rarely needs to be set. The monitor
70 | # will attempt to find the bundle in the most common locations. If
71 | # you need to use SSL and the monitor is unable to locate a CA bundle
72 | # then either set this value or the ssl_ca_path option below.
73 | # Default: /etc/ssl/certs/ca-certificates.crt or
74 | # /etc/pki/tls/certs/ca-bundle.crt
75 | # Note : Can also be set with the -b command line option.
76 | #
77 | #ssl_ca_bundle=/path/to/your/bundle.crt
78 |
79 | #
80 | # Option : ssl_ca_path
81 | # Value : If your SSL installation does not use CA bundles, but rather has a
82 | # directory with PEM-encoded Certificate Authority files, set this
83 | # option to the name of the directory that contains all the CA files.
84 | # Default: /etc/ssl/certs
85 | # Note : Can also be set with the -S command line option.
86 | #
87 | #ssl_ca_path=/etc/ssl/certs
88 |
89 | #
90 | # Option : pidfile
91 | # Value : Name of a file where the server monitoring daemon will store it's
92 | # process ID (PID). This is used by the startup and shutdown script
93 | # to determine if the monitor is already running, and to start it up
94 | # or shut it down.
95 | # Default: /tmp/nrsysmond.pid
96 | # Note : Can also be set with the -p command line option.
97 | #
98 | #pidfile=/var/run/newrelic/nrsysmond.pid
99 |
100 | #
101 | # Option : collector_host
102 | # Value : The name of the New Relic collector to connect to. This should only
103 | # ever be changed on advise from a New Relic support staff member.
104 | # The format is host[:port]. Using a port number of 0 means the default
105 | # port, which is 80 (if not using the ssl option - see below) or 443
106 | # if SSL is enabled. If the port is omitted the default value is used.
107 | # Default: collector.newrelic.com
108 | #
109 | #collector_host=collector.newrelic.com
110 |
111 | #
112 | # Option : timeout
113 | # Value : How long the monitor should wait to contact the collector host. If
114 | # the connection cannot be established in this period of time, the
115 | # monitor will progressively back off in 15-second increments, up to
116 | # a maximum of 300 seconds. Once the initial connection has been
117 | # established, this value is reset back to the value specified here
118 | # (or the default). This then sets the maximum time to wait for
119 | # a connection to the collector to report data. There is no back-off
120 | # once the original connection has been made. The value is in seconds.
121 | # Default: 30
122 | #
123 | #timeout=30
124 |
125 |
--------------------------------------------------------------------------------
/puppet/modules/nginx/manifests/init.pp:
--------------------------------------------------------------------------------
1 | #
2 | # Nginx
3 | #
4 | class nginx {
5 | include nginx::ssl
6 |
7 | package { 'nginx':
8 | ensure => installed,
9 | }
10 | # Disable default nginx site
11 | file { '/etc/nginx/sites-enabled/default':
12 | ensure => absent,
13 | before => Service[nginx]
14 | }
15 | service { 'nginx':
16 | ensure => running,
17 | require => Exec['nginx:ssl::generate-dhparams'],
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/puppet/modules/nginx/manifests/site.pp:
--------------------------------------------------------------------------------
1 | #
2 | # For defining nginx sites.
3 | #
4 | define nginx::site(
5 | $auth = false,
6 | $app_path = $::app_path,
7 | $ssl_cert = '/etc/ssl/certs/ssl-cert-snakeoil.pem',
8 | $ssl_cert_key = '/etc/ssl/private/ssl-cert-snakeoil.key',
9 | $redirects = false)
10 | {
11 | file { "/etc/nginx/sites-available/${name}":
12 | ensure => present,
13 | owner => root,
14 | group => root,
15 | mode => '0644',
16 | content => template("nginx/${name}.erb"),
17 | require => Package['nginx'],
18 | notify => Service['nginx']
19 | }
20 |
21 | file { "/etc/nginx/sites-enabled/${name}":
22 | ensure => link,
23 | target => "/etc/nginx/sites-available/${name}",
24 | notify => Service['nginx']
25 | }
26 |
27 | if $auth {
28 | file {"/etc/nginx/htpasswd-${name}":
29 | ensure => present,
30 | owner => root,
31 | group => root,
32 | mode => '0644',
33 | content => template('nginx/auth.erb'),
34 | require => Package['nginx'],
35 | }
36 | }
37 |
38 | # Ensure SSL key is secured
39 | file { $ssl_cert_key:
40 | owner => root,
41 | group => 'ssl-cert',
42 | mode => '0640',
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/puppet/modules/nginx/manifests/ssl.pp:
--------------------------------------------------------------------------------
1 | #
2 | # Configure nginx for secure SSL by default.
3 | #
4 | class nginx::ssl {
5 | # Generate secure Diffie-Hellman params for PFS
6 | exec {'nginx:ssl::generate-dhparams':
7 | command => '/usr/bin/openssl dhparam -out /etc/ssl/private/dhparam.pem 2048 && chmod 0600 /etc/ssl/private/dhparam.pem &',
8 | creates => '/etc/ssl/private/dhparam.pem',
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/puppet/modules/nginx/templates/app.erb:
--------------------------------------------------------------------------------
1 | upstream <%= @name %>_uwsgi {
2 | server unix:/tmp/<%= @name %>.uwsgi.sock;
3 | }
4 |
5 | server {
6 | listen 80;
7 | rewrite ^/(.*) https://$host$request_uri? permanent;
8 | }
9 |
10 | server {
11 | listen 443 ssl;
12 |
13 | ssl_certificate <%= @ssl_cert %>;
14 | ssl_certificate_key <%= @ssl_cert_key %>;
15 |
16 | ssl_session_timeout 5m;
17 | ssl_session_cache shared:SSL:50m;
18 | ssl_dhparam /etc/ssl/private/dhparam.pem;
19 |
20 | ssl_protocols TLSv1.1 TLSv1.2;
21 | ssl_ciphers 'ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!3DES:!MD5:!PSK';
22 | ssl_prefer_server_ciphers on;
23 |
24 | ssl_stapling on;
25 | ssl_stapling_verify on;
26 |
27 | <%= scope.function_template(['nginx/uwsgi.erb']) %>
28 |
29 | }
30 |
--------------------------------------------------------------------------------
/puppet/modules/nginx/templates/redirects.erb:
--------------------------------------------------------------------------------
1 | <% redirects.each do |source, dest| -%>
2 | server {
3 | listen 80;
4 | server_name <%= source %>;
5 | rewrite ^/(.*) http://<%= dest %>/$1 permanent;
6 | }
7 | <% end -%>
8 |
--------------------------------------------------------------------------------
/puppet/modules/nginx/templates/uwsgi.erb:
--------------------------------------------------------------------------------
1 | client_max_body_size 4G;
2 | server_name _;
3 |
4 | root <%= @app_path %>;
5 |
6 | keepalive_timeout 5;
7 |
8 | # Enable gzip
9 | gzip on;
10 | gzip_vary on;
11 | gzip_disable "MSIE [1-6].(?!.*SV1)";
12 | gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
13 |
14 | <%- if @auth -%>
15 | # password-protect site
16 | auth_basic "Restricted";
17 | auth_basic_user_file htpasswd-<%= @name %>;
18 | <%- end -%>
19 |
20 | location /static {
21 | alias <%= @app_path %>/app/static;
22 |
23 | expires max;
24 | add_header Pragma cache;
25 | add_header cache-control public;
26 | }
27 |
28 | location / {
29 | uwsgi_pass <%= @name %>_uwsgi;
30 | include uwsgi_params;
31 |
32 | # Ensure HTTPS is set when it's supposed to be
33 | uwsgi_param HTTPS $https;
34 | }
35 |
--------------------------------------------------------------------------------
/puppet/modules/openssl/manifests/init.pp:
--------------------------------------------------------------------------------
1 | #
2 | # Ensures OpenSSL libraries are kept up-to-date.
3 | #
4 | # NOTE: This does not automatically restart services that rely on openssl.
5 | # Services still need to be restarted manually to ensure the latest version of
6 | # openssl is loaded.
7 | #
8 | class openssl {
9 | # Ensure openssl is latest.
10 | package { ['openssl', 'libssl1.0.0']:
11 | ensure => latest,
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/puppet/modules/postfix/manifests/init.pp:
--------------------------------------------------------------------------------
1 | class postfix {
2 | package { 'postfix':
3 | ensure => installed,
4 | }
5 | service { 'postfix':
6 | ensure => running,
7 | require => Package[postfix]
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/puppet/modules/postgresql/manifests/init.pp:
--------------------------------------------------------------------------------
1 | #
2 | # Ensure PostgreSQL is installed and running.
3 | #
4 | class postgresql {
5 | # postgresql-dev required for Python's psycopg2
6 | package { [ 'postgresql', 'postgresql-server-dev-all' ]:
7 | ensure => 'installed',
8 | }
9 | service { 'postgresql':
10 | ensure => running,
11 | require => Package[postgresql],
12 | }
13 | }
14 |
15 | #
16 | # Mechanism to create roles.
17 | #
18 | define postgresql::role(
19 | $ensure = 'present',
20 | $createdb = false,
21 | $createrole = false,
22 | $superuser = false,
23 | $grant = false
24 | ) {
25 | case $ensure {
26 | present: {
27 |
28 | if $createdb { $createdb_param = '-d' } else { $createdb_param = '-D' }
29 | if $createrole { $createrole_param = '-r' } else { $createrole_param = '-R' }
30 | if $superuser { $superuser_param = '-s' } else { $superuser_param = '-S' }
31 |
32 | exec { "postgresql::role::${name}::create":
33 | command => "/usr/bin/createuser ${createdb_param} ${createrole_param} ${superuser_param} \"${name}\"",
34 | user => postgres,
35 | unless => "/usr/bin/psql -tAc \"SELECT 1 FROM pg_roles WHERE rolname = \'${name}\'\" |grep -q 1",
36 | require => Service[postgresql],
37 | }
38 | if ( $grant != false ) {
39 | exec { "/usr/bin/psql -c \'GRANT \"${grant}\" TO \"${name}\";\'":
40 | user => postgres,
41 | unless => "/usr/bin/psql -tAc \"SELECT 1 FROM pg_authid p INNER JOIN pg_auth_members am ON (p.oid = am.roleid) INNER JOIN pg_authid m ON (am.member = m.oid) INNER JOIN pg_authid g ON (am.grantor = g.oid) WHERE p.rolname = '${grant}' AND m.rolname = '${name}';\" |grep -q 1",
42 | require => [
43 | Service[postgresql],
44 | Exec["postgresql::role::${name}::create"],
45 | ],
46 | }
47 | }
48 | }
49 | absent: {
50 | exec { "postgresql::role::${name}::delete":
51 | command => "/usr/bin/dropuser \"${name}\"",
52 | user => postgres,
53 | onlyif => "/usr/bin/psql -tAc \"SELECT 1 FROM pg_roles WHERE rolname = \'${name}\'\" |grep -q 1",
54 | require => Service[postgresql],
55 | }
56 | }
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/puppet/modules/puppet/manifests/sudoers.pp:
--------------------------------------------------------------------------------
1 | #
2 | # Ensures the deploy user can run Puppet via sudo.
3 | #
4 | class puppet::sudoers (
5 | $app_path = $::app_path,
6 | $deploy_user = $::deploy_user
7 | ) {
8 | file { '/etc/sudoers.d/puppet':
9 | owner => root,
10 | group => root,
11 | mode => '0440',
12 | content => "${deploy_user} ALL = (root) NOPASSWD : /usr/bin/puppet apply --modulepath='${app_path}/modules' '${app_path}/puppet/manifests/site.pp'\n",
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/puppet/modules/python/manifests/packages.pp:
--------------------------------------------------------------------------------
1 | #
2 | # Python packages required by the app.
3 | #
4 | class python::packages {
5 | package { [ 'python-virtualenv', 'python-dev', ]:
6 | ensure => installed
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/puppet/modules/rsyslog/manifests/init.pp:
--------------------------------------------------------------------------------
1 | #
2 | # Ensure syslog is installed and running.
3 | #
4 | # Also provides the rsyslog Puppet service resource primarily so it can be
5 | # notified about system timezone changes (otherwise syslog timestamps are
6 | # wrong).
7 | #
8 | class rsyslog {
9 | package { 'rsyslog':
10 | ensure => installed,
11 | }
12 | service { 'rsyslog':
13 | ensure => running,
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/puppet/modules/sysctl/manifests/init.pp:
--------------------------------------------------------------------------------
1 | class sysctl {
2 | # This service is always stopped, but needs to be refreshed when a value
3 | # changes.
4 | exec { 'sysctl::reload':
5 | command => '/etc/init.d/procps start',
6 | refreshonly => true,
7 | }
8 | }
9 |
10 | define sysctl::parameter ( $value ) {
11 | file { "/etc/sysctl.d/60-${name}.conf":
12 | ensure => present,
13 | content => "${name} = ${value}\n",
14 | notify => Exec['sysctl::reload'],
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/puppet/modules/uglifyjs/manifests/init.pp:
--------------------------------------------------------------------------------
1 | class uglifyjs {
2 | package { 'node-uglify':
3 | ensure => installed,
4 | }
5 | }
6 |
--------------------------------------------------------------------------------
/puppet/modules/users/manifests/deploy.pp:
--------------------------------------------------------------------------------
1 | #
2 | # Set up deploy user.
3 | #
4 | class users::deploy($deploy_user = $::deploy_user) {
5 |
6 | user { $deploy_user:
7 | ensure => present,
8 | comment => 'App deployment user',
9 | managehome => true,
10 | shell => '/bin/bash',
11 | }
12 |
13 | # Grant sudo access
14 | file { "/etc/sudoers.d/${deploy_user}":
15 | owner => root,
16 | group => root,
17 | mode => '0440',
18 | content => "${deploy_user} ALL = (root) NOPASSWD : ALL\n"
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/puppet/modules/uwsgi/files/etc/init/uwsgi.conf:
--------------------------------------------------------------------------------
1 | # Emperor uWSGI script
2 |
3 | description "uWSGI Emperor"
4 | start on runlevel [2345]
5 | stop on runlevel [06]
6 |
7 | exec /usr/local/bin/uwsgi --include /etc/uwsgi/uwsgi.ini
8 |
--------------------------------------------------------------------------------
/puppet/modules/uwsgi/files/etc/logrotate.d/uwsgi:
--------------------------------------------------------------------------------
1 | "/var/log/uwsgi/*.log" "/var/log/uwsgi/*/*.log" {
2 | copytruncate
3 | daily
4 | rotate 5
5 | compress
6 | delaycompress
7 | missingok
8 | notifempty
9 | }
10 |
--------------------------------------------------------------------------------
/puppet/modules/uwsgi/files/etc/uwsgi/uwsgi.ini:
--------------------------------------------------------------------------------
1 | [uwsgi]
2 | emperor = /etc/uwsgi/apps-enabled
3 | logto = /var/log/uwsgi/emperor.log
4 | uid = www-data
5 | gid = www-data
6 |
--------------------------------------------------------------------------------
/puppet/modules/uwsgi/manifests/init.pp:
--------------------------------------------------------------------------------
1 | #
2 | # Latest uWSGI, installed using pip.
3 | #
4 | class uwsgi ($ensure = 'running') {
5 |
6 | include uwsgi::tuning
7 |
8 | package { 'uwsgi':
9 | ensure => installed,
10 | name => 'uWSGI',
11 | provider => 'pip',
12 | }
13 |
14 | file { ['/etc/uwsgi', '/etc/uwsgi/apps-available', '/etc/uwsgi/apps-enabled']:
15 | ensure => directory,
16 | owner => root,
17 | group => root,
18 | mode => '0755',
19 | require => Package['uwsgi'],
20 | }
21 |
22 | file { '/etc/init/uwsgi.conf':
23 | ensure => file,
24 | owner => root,
25 | group => root,
26 | mode => '0644',
27 | source => 'puppet:///modules/uwsgi/etc/init/uwsgi.conf',
28 | require => Package['uwsgi'],
29 | notify => Service['uwsgi'],
30 | }
31 |
32 | file { '/etc/uwsgi/uwsgi.ini':
33 | ensure => file,
34 | owner => root,
35 | group => root,
36 | mode => '0644',
37 | source => 'puppet:///modules/uwsgi/etc/uwsgi/uwsgi.ini',
38 | require => File['/etc/uwsgi'],
39 | notify => Service['uwsgi'],
40 | }
41 |
42 | file { '/etc/logrotate.d/uwsgi':
43 | ensure => file,
44 | owner => root,
45 | group => root,
46 | mode => '0644',
47 | source => 'puppet:///modules/uwsgi/etc/logrotate.d/uwsgi',
48 | }
49 |
50 | file { '/etc/init.d/uwsgi':
51 | ensure => link,
52 | target => '/lib/init/upstart-job',
53 | owner => root,
54 | group => root,
55 | mode => '0644',
56 | }
57 |
58 | file { '/var/log/uwsgi':
59 | ensure => directory,
60 | owner => 'www-data',
61 | group => 'www-data',
62 | require => Package['uwsgi'],
63 | }
64 |
65 | service { 'uwsgi':
66 | ensure => $ensure,
67 | provider => upstart,
68 | enable => true,
69 | require => File['/etc/uwsgi/uwsgi.ini'],
70 | }
71 | }
72 |
73 | #
74 | # For defining uWSGI app instances.
75 | #
76 | define uwsgi::app($port = 8000, $uwsgi_options = []) {
77 |
78 | $settings = $::environment ? {
79 | undef => 'settings.dev',
80 | default => "settings.${::environment}",
81 | }
82 |
83 | $venv = $::venv ? {
84 | undef => '/srv/www/app/venv',
85 | default => $::venv,
86 | }
87 |
88 | file { "/etc/uwsgi/apps-available/${name}.ini":
89 | ensure => present,
90 | content => template('uwsgi/app.ini.erb'),
91 | notify => Service['uwsgi'],
92 | }
93 |
94 | file { "/var/log/uwsgi/${name}.log":
95 | ensure => present,
96 | }
97 |
98 | file { "/etc/uwsgi/apps-enabled/${name}.ini":
99 | ensure => link,
100 | target => "/etc/uwsgi/apps-available/${name}.ini",
101 | notify => Service['uwsgi'],
102 | }
103 | }
104 |
--------------------------------------------------------------------------------
/puppet/modules/uwsgi/manifests/tuning.pp:
--------------------------------------------------------------------------------
1 | #
2 | # uWSGI system tuning
3 | #
4 | class uwsgi::tuning {
5 | # Increase system max socket queue
6 | sysctl::parameter { 'net.core.somaxconn':
7 | value => 2048,
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/puppet/modules/uwsgi/templates/app.ini.erb:
--------------------------------------------------------------------------------
1 | [uwsgi]
2 | socket = /tmp/<%= @name %>.uwsgi.sock
3 | chdir = /srv/www/app
4 | uid = www-data
5 | logto = /var/log/uwsgi/<%= @name %>.log
6 | reload-mercy = 30
7 | single-interpreter = true
8 | enable-threads = true
9 | virtualenv = <%= @venv %>
10 | listen = 2048
11 |
12 | <%- if @uwsgi_options -%>
13 | # Custom options
14 | <%- @uwsgi_options.each do | key, value | -%>
15 | <%- if value.kind_of?(Array) -%>
16 | <%- value.each do | value | -%>
17 | <%= key %>=<%= value %>
18 | <%- end -%>
19 | <%- else -%>
20 | <%= key %>=<%= value %>
21 | <%- end -%>
22 | <%- end -%>
23 | <%- end -%>
24 |
--------------------------------------------------------------------------------
/puppet/modules/vagrant/files/pip/pip.conf:
--------------------------------------------------------------------------------
1 | [global]
2 | download_cache = /vagrant/.cache/pip
3 |
--------------------------------------------------------------------------------
/puppet/modules/vagrant/manifests/init.pp:
--------------------------------------------------------------------------------
1 | #
2 | # For developement environment.
3 | #
4 | class vagrant {
5 |
6 | # Set up app directory
7 | file { '/srv/www':
8 | ensure => directory,
9 | }
10 | file { '/srv/www/app':
11 | ensure => link,
12 | target => '/vagrant',
13 | }
14 |
15 | # Active the app venv on login
16 | line { 'line-venv-activate':
17 | ensure => present,
18 | file => '/home/vagrant/.bashrc',
19 | line => 'cd /vagrant && source .venv/bin/activate',
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/puppet/modules/vagrant/manifests/pip.pp:
--------------------------------------------------------------------------------
1 | class vagrant::pip {
2 | # Create pip.conf for vagrant
3 | file { '/home/vagrant/.pip':
4 | source => 'puppet:///modules/vagrant/pip',
5 | recurse => remote,
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/puppet/modules/vagrant/manifests/postgresql.pp:
--------------------------------------------------------------------------------
1 | #
2 | # Create vagrant postgresql user for development.
3 | #
4 | class vagrant::postgresql {
5 | postgresql::role { 'vagrant':
6 | ensure => present,
7 | createdb => true,
8 | createrole => true,
9 | superuser => true,
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/requirements.txt:
--------------------------------------------------------------------------------
1 | Fabric
2 | Flask
3 | Flask-Script
4 | Flask-SQLAlchemy
5 | alembic
6 | git+git://github.com/tobiasandtobias/flask-assetslite.git@dev-cache#egg=Flask_AssetsLite
7 | psycopg2
8 | nose
9 |
--------------------------------------------------------------------------------