Commit b5a43a84 authored by Joachim Mathes's avatar Joachim Mathes

TASK: Remove fabfile

parent 66c8d3d4
'''
fabric file for proserver-box
'''
from fabric.api import *
from fabric.colors import *
from fabric import state
from fabric.utils import abort
from fabric.contrib.project import rsync_project
import os
import sys
import subprocess
env.hosts = ['172.17.28.100']
env.shell = '/usr/local/bin/bash -c'
state.output['everything'] = False
def boot_vagrant_box():
'''
Download and start proServer box. This may take some time ...
'''
print(cyan(boot_vagrant_box.__doc__))
local("vagrant up")
@runs_once
@with_settings(user='proserver')
def acquire_database_password():
'''
Acquire database password
'''
print(cyan(acquire_database_password.__doc__))
acquire_private_key_of_box()
env.database_password = run('php -r \'$configuration=include("/var/www/typo3/typo3conf/LocalConfiguration.php"); echo $configuration["DB"]["Connections"]["Default"]["password"];\'').stdout.strip()
@runs_once
@with_settings(user='proserver')
def acquire_private_key_of_box():
'''
Acquire private key of vagrant box
'''
print(cyan(acquire_private_key_of_box.__doc__))
private_key_path = subprocess.Popen("vagrant ssh-config | grep IdentityFile | awk '{print $2}'", shell=True, stdout=subprocess.PIPE).stdout.read().strip()
if env.key_filename is None and os.path.exists(private_key_path):
env.key_filename = private_key_path
@with_settings(user='vagrant')
def prepare_user_proserver():
'''
Copy authorized keys of user vagrant to user proserver and set user proserver as fabric login user
'''
print(cyan(prepare_user_proserver.__doc__))
sudo('cat /home/vagrant/.ssh/authorized_keys > /home/proserver/.ssh/authorized_keys')
@with_settings(user='proserver')
def inject_and_initialize_project():
'''
Inject project into box and install it
'''
print(cyan(inject_and_initialize_project.__doc__))
rsync_project(
remote_dir='/var/www/t3o/',
local_dir='./',
exclude='.git')
with settings(show('everything')):
with cd("/var/www/t3o"):
run('composer install')
with cd("/var/www"):
run('rm -rf typo3 && ln -s t3o/html typo3')
@with_settings(user='proserver')
def download_initialized_project():
'''
Download initialized project
'''
print(cyan(download_initialized_project.__doc__))
acquire_private_key_of_box()
rsync_project(
remote_dir='/var/www/t3o/*',
exclude=['fabfile.py'],
extra_opts='-l',
upload=False)
@with_settings(user='proserver')
def download_and_import_database():
'''
Download database from vpro0100.proserver.punkt.de and import in box.
'''
print(cyan(download_and_import_database.__doc__))
with settings(hide('stdout'), user='vagrant'):
mysql_root_password = sudo('cat /usr/local/etc/mysql-password').stdout.strip()
with cd("/tmp"):
run('curl -LsO https://vpro0100.proserver.punkt.de/sql/t3o.sql.gz')
run('mysql -u root -p%s -e "CREATE DATABASE IF NOT EXISTS t3o"' % (mysql_root_password))
run('mysql -u root -p%s -e "GRANT ALL ON t3o.* TO t3o@localhost identified by \'%s\'"' % (mysql_root_password, env.database_password))
run("gunzip < t3o.sql.gz | mysql -u root -p%s t3o" % (mysql_root_password))
@with_settings(user='vagrant')
def restart_phpfpm():
'''
Restart php-fpm in box.
'''
print(cyan(restart_phpfpm.__doc__))
sudo('/usr/local/etc/rc.d/php-fpm restart')
@task
@with_settings(user='vagrant')
def initialize_proserver_box():
'''
Initialize proServer box.
'''
print(cyan(initialize_proserver_box.__doc__))
boot_vagrant_box()
acquire_private_key_of_box()
if run('[ -d /var/www/t3o ]', quiet=True).return_code == 0:
abort(red('Project seems to be initialized already.'))
prepare_user_proserver()
inject_and_initialize_project()
acquire_database_password()
download_and_import_database()
restart_phpfpm()
download_initialized_project()
@task
@hosts('vpro0100.proserver.punkt.de')
@with_settings(user='proserver')
def dump_proserver_database():
'''
Dump TYPO3 database of proServer vpro0100.proserver.punkt.de.
=> ssh access to vpro0100.proserver.punkt.de required. <=
'''
print cyan(dump_proserver_database.__doc__)
acquire_database_password()
with cd('/var/www/surf/releases/current/html/sql/'):
run("mysqldump -u t3o -p%s t3o | gzip > t3o.sql.gz" % (env.database_password))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment