Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
t0mab committed Jun 5, 2020
2 parents ba0c32c + e950b5c commit 4c3cf45
Show file tree
Hide file tree
Showing 58 changed files with 3,040 additions and 1,544 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,4 @@ docs/_build
htmlcov
.cache
.ropeproject
.vscode
57 changes: 36 additions & 21 deletions pydiploy/bottle.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,33 @@ def wrap_deploy():
yield
except SystemExit:
fabric.api.execute(rollback)
fabric.api.abort(fabric.colors.red(
"Deploy failed rollbacking process launched"))
fabric.api.abort(
fabric.colors.red("Deploy failed rollbacking process launched")
)


@do_verbose
def application_packages(update=False):
""" Installs all packages for the app """
fabtools.require.deb.packages(['gettext'], update=update)
if env.remote_python_version >= 3:
fabric.api.execute(pydiploy.require.system.check_python3_install,
version='python%s' % env.remote_python_version)
fabric.api.execute(
pydiploy.require.system.check_python3_install,
version='python%s' % env.remote_python_version,
)
fabric.api.execute(pydiploy.require.python.utils.python_pkg)
if 'extra_ppa_to_install' in env:
fabric.api.execute(
pydiploy.require.system.install_extra_ppa,
env.extra_ppa_to_install)
pydiploy.require.system.install_extra_ppa, env.extra_ppa_to_install
)
if 'extra_source_to_install' in env:
fabric.api.execute(
pydiploy.require.system.install_extra_source,
env.extra_source_to_install)
pydiploy.require.system.install_extra_source, env.extra_source_to_install
)
if 'extra_pkg_to_install' in env:
fabric.api.execute(
pydiploy.require.system.install_extra_packages,
env.extra_pkg_to_install)
pydiploy.require.system.install_extra_packages, env.extra_pkg_to_install
)


def pre_install_backend(commands='/usr/bin/rsync', upgrade_circus=False):
Expand All @@ -47,8 +50,7 @@ def pre_install_backend(commands='/usr/bin/rsync', upgrade_circus=False):
fabric.api.execute(pydiploy.require.system.set_timezone)
fabric.api.execute(pydiploy.require.system.update_pkg_index)
fabric.api.execute(application_packages)
fabric.api.execute(pydiploy.require.circus.circus_pkg,
update=upgrade_circus)
fabric.api.execute(pydiploy.require.circus.circus_pkg, update=upgrade_circus)
fabric.api.execute(pydiploy.require.python.virtualenv.virtualenv)
fabric.api.execute(pydiploy.require.circus.upstart)

Expand All @@ -67,11 +69,10 @@ def deploy_backend(upgrade_pkg=False, **kwargs):
fabric.api.execute(pydiploy.require.releases_manager.deploy_code)
fabric.api.execute(pydiploy.require.django.utils.deploy_wsgi_file)
fabric.api.execute(
pydiploy.require.python.utils.application_dependencies,
upgrade_pkg)
pydiploy.require.python.utils.application_dependencies, upgrade_pkg
)
# TODO PUT THIS METHOD IN OTHER PACKAGE
fabric.api.execute(pydiploy.require.bottle.utils.app_settings,
**kwargs)
fabric.api.execute(pydiploy.require.bottle.utils.app_settings, **kwargs)
fabric.api.execute(pydiploy.require.bottle.utils.deploy_environ_file)
fabric.api.execute(pydiploy.require.bottle.command.bottle_prepare)
fabric.api.execute(pydiploy.require.system.permissions)
Expand Down Expand Up @@ -122,7 +123,7 @@ def set_app_up():
fabric.api.execute(pydiploy.require.nginx.set_website_up)


def install_postgres_server(user=None,dbname=None,password=None):
def install_postgres_server(user=None, dbname=None, password=None):
""" Install postgres server & add user for postgres
if no parameters are provided using (if exists) ::
Expand All @@ -134,16 +135,30 @@ def install_postgres_server(user=None,dbname=None,password=None):
"""

if not (user and dbname and password):
if all([e in env.keys() for e in ('default_db_user', 'default_db_name', 'default_db_password')]):
if all(
[
e in env.keys()
for e in ('default_db_user', 'default_db_name', 'default_db_password')
]
):
user = env.default_db_user
dbname = env.default_db_name
password = env.default_db_password
else:
fabric.api.abort('Please provide user,dbname,password parameters for postgres.')
fabric.api.abort(
'Please provide user,dbname,password parameters for postgres.'
)

fabric.api.execute(pydiploy.require.databases.postgres.install_postgres_server)
fabric.api.execute(pydiploy.require.databases.postgres.add_postgres_user,user,password=password)
fabric.api.execute(pydiploy.require.databases.postgres.add_postgres_database,dbname,owner=user,locale=env.locale)
fabric.api.execute(
pydiploy.require.databases.postgres.add_postgres_user, user, password=password
)
fabric.api.execute(
pydiploy.require.databases.postgres.add_postgres_database,
dbname,
owner=user,
locale=env.locale,
)


def install_oracle_client():
Expand Down
17 changes: 13 additions & 4 deletions pydiploy/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import fabric
from fabric.api import env


"""
Decorators
Expand All @@ -18,11 +19,19 @@ def do_verbose(view_func):

@wraps(view_func)
def wrapper(*args, **kwargs):
custom_hide = ['running', 'stdout', 'stderr'] if 'verbose_output' in\
env and not env.verbose_output else []
custom_hide = (
['running', 'stdout', 'stderr']
if 'verbose_output' in env and not env.verbose_output
else []
)
with fabric.context_managers.hide(*custom_hide):
fabric.api.puts("%s : %s" % (view_func.__name__, fabric.colors.green("Executing")))
fabric.api.puts(
"%s : %s" % (view_func.__name__, fabric.colors.green("Executing"))
)
res = view_func(*args, **kwargs)
fabric.api.puts("%s : %s" % (view_func.__name__, fabric.colors.green("Done")))
fabric.api.puts(
"%s : %s" % (view_func.__name__, fabric.colors.green("Done"))
)
return res

return wrapper
54 changes: 37 additions & 17 deletions pydiploy/django.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@

import fabric
import fabtools
import pydiploy
from fabric.api import env

import pydiploy
from pydiploy.decorators import do_verbose


Expand All @@ -22,8 +23,9 @@ def wrap_deploy():
yield
except SystemExit:
fabric.api.execute(rollback)
fabric.api.abort(fabric.colors.red(
"Deploy failed rollbacking process launched"))
fabric.api.abort(
fabric.colors.red("Deploy failed rollbacking process launched")
)


@do_verbose
Expand All @@ -32,18 +34,23 @@ def application_packages(update=False):
fabtools.require.deb.packages(['gettext'], update=update)

if env.remote_python_version >= 3:
fabric.api.execute(pydiploy.require.system.check_python3_install,
version='python%s' % env.remote_python_version)
fabric.api.execute(
pydiploy.require.system.check_python3_install,
version='python%s' % env.remote_python_version,
)
fabric.api.execute(pydiploy.require.python.utils.python_pkg)
if env.has_key('extra_ppa_to_install'):
fabric.api.execute(
pydiploy.require.system.install_extra_ppa, env.extra_ppa_to_install)
pydiploy.require.system.install_extra_ppa, env.extra_ppa_to_install
)
if env.has_key('extra_source_to_install'):
fabric.api.execute(
pydiploy.require.system.install_extra_source, env.extra_source_to_install)
pydiploy.require.system.install_extra_source, env.extra_source_to_install
)
if env.has_key('extra_pkg_to_install'):
fabric.api.execute(
pydiploy.require.system.install_extra_packages, env.extra_pkg_to_install)
pydiploy.require.system.install_extra_packages, env.extra_pkg_to_install
)


def pre_install_backend(commands='/usr/bin/rsync', upgrade_circus=False):
Expand Down Expand Up @@ -73,10 +80,9 @@ def deploy_backend(upgrade_pkg=False, **kwargs):
fabric.api.execute(pydiploy.require.django.utils.deploy_manage_file)
fabric.api.execute(pydiploy.require.django.utils.deploy_wsgi_file)
fabric.api.execute(
pydiploy.require.python.utils.application_dependencies,
upgrade_pkg)
fabric.api.execute(pydiploy.require.django.utils.app_settings,
**kwargs)
pydiploy.require.python.utils.application_dependencies, upgrade_pkg
)
fabric.api.execute(pydiploy.require.django.utils.app_settings, **kwargs)
fabric.api.execute(pydiploy.require.django.command.django_prepare)
fabric.api.execute(pydiploy.require.system.permissions)
fabric.api.execute(pydiploy.require.circus.app_reload)
Expand Down Expand Up @@ -136,7 +142,7 @@ def custom_manage_command(cmd):
fabric.api.execute(pydiploy.require.django.command.django_custom_cmd, cmd)


def install_postgres_server(user=None,dbname=None,password=None):
def install_postgres_server(user=None, dbname=None, password=None):
""" Install postgres server & add user for postgres
if no parameters are provided using (if exists) ::
Expand All @@ -148,16 +154,30 @@ def install_postgres_server(user=None,dbname=None,password=None):
"""

if not (user and dbname and password):
if all([e in env.keys() for e in ('default_db_user', 'default_db_name', 'default_db_password')]):
if all(
[
e in env.keys()
for e in ('default_db_user', 'default_db_name', 'default_db_password')
]
):
user = env.default_db_user
dbname = env.default_db_name
password = env.default_db_password
else:
fabric.api.abort('Please provide user,dbname,password parameters for postgres.')
fabric.api.abort(
'Please provide user,dbname,password parameters for postgres.'
)

fabric.api.execute(pydiploy.require.databases.postgres.install_postgres_server)
fabric.api.execute(pydiploy.require.databases.postgres.add_postgres_user,user,password=password)
fabric.api.execute(pydiploy.require.databases.postgres.add_postgres_database,dbname,owner=user,locale=env.locale)
fabric.api.execute(
pydiploy.require.databases.postgres.add_postgres_user, user, password=password
)
fabric.api.execute(
pydiploy.require.databases.postgres.add_postgres_database,
dbname,
owner=user,
locale=env.locale,
)


def install_oracle_client():
Expand Down
45 changes: 24 additions & 21 deletions pydiploy/examples/bottle_fabfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,28 @@
Fabfile example file to deploy a standard bottle webapp
"""

from fabric.api import (env, roles, execute, task)
from os.path import join

from pydiploy.prepare import (tag as pydiploy_tag,
build_env as pydiploy_build_env)
from pydiploy.bottle import (deploy_backend as pydiploy_deploy_backend,
deploy_frontend as pydiploy_deploy_frontend,
rollback as pydiploy_rollback,
post_install_backend as pydiploy_postinstall_backend,
post_install_frontend as pydiploy_postinstall_frontend,
pre_install_backend as pydiploy_preinstall_backend,
pre_install_frontend as pydiploy_preinstall_frontend,
reload_frontend as pydiploy_reload_frontend,
reload_backend as pydiploy_reload_backend,
set_app_up as pydiploy_set_up,
set_app_down as pydiploy_set_down,
install_oracle_client as pydiploy_setup_oracle,
install_postgres_server as pydiploy_setup_postgres)
from fabric.api import env, execute, roles, task
from pydiploy.bottle import deploy_backend as pydiploy_deploy_backend
from pydiploy.bottle import deploy_frontend as pydiploy_deploy_frontend
from pydiploy.bottle import install_oracle_client as pydiploy_setup_oracle
from pydiploy.bottle import install_postgres_server as pydiploy_setup_postgres
from pydiploy.bottle import post_install_backend as pydiploy_postinstall_backend
from pydiploy.bottle import post_install_frontend as pydiploy_postinstall_frontend
from pydiploy.bottle import pre_install_backend as pydiploy_preinstall_backend
from pydiploy.bottle import pre_install_frontend as pydiploy_preinstall_frontend
from pydiploy.bottle import reload_backend as pydiploy_reload_backend
from pydiploy.bottle import reload_frontend as pydiploy_reload_frontend
from pydiploy.bottle import rollback as pydiploy_rollback
from pydiploy.bottle import set_app_down as pydiploy_set_down
from pydiploy.bottle import set_app_up as pydiploy_set_up
from pydiploy.prepare import build_env as pydiploy_build_env
from pydiploy.prepare import tag as pydiploy_tag

# edit config here !

env.use_sudo = True # use sudo or not
env.use_sudo = True # use sudo or not

env.remote_owner = 'myremoteuser'
env.remote_group = 'myremotegroup'
Expand All @@ -36,8 +36,7 @@
env.remote_home = '/home/myremoteuser' # remote home root
env.remote_python_version = 3.4 # python version
env.remote_virtualenv_root = join(env.remote_home, '.virtualenvs') # venv root
env.remote_virtualenv_dir = join(env.remote_virtualenv_root,
env.application_name) # venv for webapp dir
env.remote_virtualenv_dir = join(env.remote_virtualenv_root, env.application_name) # venv for webapp dir

env.remote_repo_url = 'git@git.net:myapp.git'
env.remote_static_root = '/var/www/static' # root of static files
Expand Down Expand Up @@ -85,7 +84,7 @@

# env.socket_host='localhost' # use it in env method to force a socket host

# env.run_tests_command = 'tox'
#  env.run_tests_command = 'tox'

# env.media_folder = '/media' # path of the application's media files
# env.remote_media_folder = '/srv/media/myapp' # remote folder of the application's media files
Expand All @@ -96,6 +95,8 @@
# env.default_db_user = 'myapp_db_user'
# env.default_db_password = 'S3CR3T'

# env.no_tag_check = True # When your fabfile is not in your project git repository be sure to set this var


@task
def test():
Expand Down Expand Up @@ -150,6 +151,7 @@ def prod():
}
execute(build_env)


# dont touch after that point if you don't know what you are doing !


Expand Down Expand Up @@ -200,7 +202,7 @@ def deploy():
execute(deploy_backend)
execute(deploy_frontend)
# uncomment this to toggle app to up mode again :
#execute(set_up)
# execute(set_up)


@roles('web')
Expand Down Expand Up @@ -244,6 +246,7 @@ def post_install_frontend():
"""Post installation of frontend"""
execute(pydiploy_postinstall_frontend)


@roles('web')
@task
def install_oracle():
Expand Down
Loading

0 comments on commit 4c3cf45

Please sign in to comment.