Branch: refs/heads/master Author: Enrico Tröger enrico.troeger@uvena.de Committer: Enrico Tröger enrico.troeger@uvena.de Date: Sat, 11 May 2019 11:49:05 UTC Commit: eaa8b88e93b96db6004692eb86fdafa1e816c364 https://github.com/geany/www.geany.org/commit/eaa8b88e93b96db6004692eb86fdaf...
Log Message: ----------- Add Fabfile for easy deployment
Modified Paths: -------------- fabfile.py
Modified: fabfile.py 78 lines changed, 78 insertions(+), 0 deletions(-) =================================================================== @@ -0,0 +1,78 @@ +# -*- coding: utf-8 -*- +# LICENCE: This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see http://www.gnu.org/licenses/. + +from os.path import join + +from fabric import task + + +DJANGO_HOME = '/srv/django' +PROJECT_DIRECTORY = join(DJANGO_HOME, 'www.geany.org') +PROJECT_VENV_BIN = join(PROJECT_DIRECTORY, 'venv/bin') +UWSGI_COMMAND = join(PROJECT_VENV_BIN, 'uwsgi') +UWSGI_MASTER_FIFO = join(DJANGO_HOME, 'run/www.geany.org.fifo') +PYTHON_COMMAND = join(PROJECT_VENV_BIN, 'python') +MANAGE_PY = join(PROJECT_DIRECTORY, 'manage.py') +SUDO_USER = 'django' +REMOTE_HOST = ['geany.org'] + + +# ---------------------------------------------------------------------- +def _print_command(command): + header = '-' * len(command) + print('\033[1;32m') # set color to green + print(header) + print(command) + print(header) + print(end='\033[0m', flush=True) # reset color + + +# ---------------------------------------------------------------------- +def _sudo_in_project_directory(connection, command): + # Fabric 2 still misses lots of features, like combining cd() and sudo() + # So, do it on our own :( + _print_command(command) + return connection.sudo( + 'bash -c "cd {} && {}"'.format(PROJECT_DIRECTORY, command), + user=SUDO_USER) + + +# ---------------------------------------------------------------------- +def _sudo_django_manage_command(connection, command): + return _sudo_in_project_directory( + connection, + '{} {} {}'.format(PYTHON_COMMAND, MANAGE_PY, command)) + + +# ---------------------------------------------------------------------- +@task(hosts=REMOTE_HOST) +def deploy(connection): + _sudo_in_project_directory(connection, 'git pull') + # recompile bytecode + _sudo_django_manage_command(connection, 'clean_pyc') + _sudo_django_manage_command(connection, 'compile_pyc') + # perform Django self checks + _sudo_django_manage_command(connection, 'check') + # regenerate code highlighting CSS styles + _sudo_django_manage_command(connection, 'pygments_styles') + # copy static files and compress CSS/JS + _sudo_django_manage_command(connection, 'collectstatic --clear --no-input --verbosity 0') + _sudo_django_manage_command(connection, 'compress --verbosity 0') + # run Django database migrations + _sudo_django_manage_command(connection, 'migrate --run-syncdb') + # clear the cache + _sudo_django_manage_command(connection, 'clear_cache') + + # trigger UWSGI chain reload + _sudo_in_project_directory(connection, 'echo c > {}'.format(UWSGI_MASTER_FIFO))
-------------- This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).