def _install_code(): sudo('mkdir -p /opt/djangoprojects/') with cd('/opt/djangoprojects/'): sudo('git clone https://github.com/ryanniemeyer/uriz.git') with cd('/opt/djangoprojects/uriz/'): # Swap in our nginx conf sudo('chmod 744 /opt/djangoprojects/uriz/config/nginx.conf') sudo( 'ln -s /opt/djangoprojects/uriz/config/nginx.conf /etc/nginx/nginx.conf' ) # Swap in our apache conf sudo('chmod 744 /opt/djangoprojects/uriz/config/apache2.conf') sudo( 'ln -s /opt/djangoprojects/uriz/config/apache2.conf /etc/apache2/apache2.conf' ) # Install all of our Python dependencies with prefix('workon uriz'): run('pip install -r requirements.txt') # Add in the AWS key and secret that you should have in my_aws_settings.py locally, # but is not checked into github... with cd('/opt/djangoprojects/uriz/uriz/'): sudo('touch my_aws_settings.py') file_append('my_aws_settings.py', [ 'AWS_ACCESS_KEY_ID = "{0}"'.format(AWS_ACCESS_KEY_ID), 'AWS_SECRET_ACCESS_KEY = "{0}"'.format(AWS_SECRET_ACCESS_KEY) ], use_sudo=True, partial=False, escape=True)
def _install_code(): sudo('mkdir -p /opt/djangoprojects/') with cd('/opt/djangoprojects/'): sudo('git clone https://[email protected]/sambao21/uriz.git') with cd('/opt/djangoprojects/uriz/'): # Swap in our nginx conf sudo('chmod 744 /opt/djangoprojects/uriz/config/nginx.conf') sudo('ln -s /opt/djangoprojects/uriz/config/nginx.conf /etc/nginx/nginx.conf') # Swap in our apache conf sudo('chmod 744 /opt/djangoprojects/uriz/config/apache2.conf') sudo('ln -s /opt/djangoprojects/uriz/config/apache2.conf /etc/apache2/apache2.conf') # Install all of our Python dependencies with prefix('workon uriz'): run('pip install -r requirements.txt') # Add in the AWS key and secret that you should have in my_aws_settings.py locally, # but is not checked into github... with cd('/opt/djangoprojects/uriz/uriz/'): sudo('touch my_aws_settings.py') file_append('my_aws_settings.py', ['AWS_ACCESS_KEY_ID = "{0}"'.format(AWS_ACCESS_KEY_ID), 'AWS_SECRET_ACCESS_KEY = "{0}"'.format(AWS_SECRET_ACCESS_KEY)], use_sudo=True, partial=False, escape=True)
def disable_env_reset_on_sudo(log=False): """ updates /etc/sudoers so that users from %wheel keep their environment when executing a sudo call """ if log: bookshelf2.logging_helpers.log_green('disabling env reset on sudo') file_append('/etc/sudoers', 'Defaults:%wheel !env_reset,!secure_path', use_sudo=True, partial=True) return True
def apt_add_repository_from_apt_string(apt_string, apt_file): """ adds a new repository file for apt """ apt_file_path = '/etc/apt/sources.list.d/%s' % apt_file if not file_contains(apt_file_path, apt_string.lower(), use_sudo=True): file_append(apt_file_path, apt_string.lower(), use_sudo=True) with hide('running', 'stdout'): output = sudo("DEBIAN_FRONTEND=noninteractive /usr/bin/apt-get update") if 'Some index files failed to download' in output: raise SystemExit(1) else: # if we didn't abort above, we should return True return True
def apt_add_repository_from_apt_string(apt_string, apt_file): """ adds a new repository file for apt """ apt_file_path = '/etc/apt/sources.list.d/%s' % apt_file if not file_contains(apt_file_path, apt_string.lower(), use_sudo=True): file_append(apt_file_path, apt_string.lower(), use_sudo=True) with hide('running', 'stdout'): output = sudo("/usr/bin/apt-get update") if 'Some index files failed to download' in output: raise SystemExit(1) else: # if we didn't abort above, we should return True return True
def _install_python_schtuff(): # Get easy_install and pip sudo('apt-get -y -q install python-setuptools') sudo('easy_install pip') # Setup the uriz virtualenv... sudo('pip install virtualenv') sudo('pip install virtualenvwrapper') with cd('~'): run('mkdir .virtualenvs') file_append('.bash_profile', ['# virtualenvwrapper', 'export WORKON_HOME=~/.virtualenvs', 'source /usr/local/bin/virtualenvwrapper.sh', 'export PIP_VIRTUALENV_BASE=$WORKON_HOME', 'export PIP_RESPECT_VIRTUALENV=true'], use_sudo=False, partial=False, escape=True) run('source ~/.bash_profile') run('mkvirtualenv uriz')
def _install_python_schtuff(): # Get easy_install and pip sudo('apt-get -y -q install python-setuptools') sudo('easy_install pip') # Setup the uriz virtualenv... sudo('pip install virtualenv') sudo('pip install virtualenvwrapper') with cd('~'): run('mkdir .virtualenvs') file_append('.bash_profile', [ '# virtualenvwrapper', 'export WORKON_HOME=~/.virtualenvs', 'source /usr/local/bin/virtualenvwrapper.sh', 'export PIP_VIRTUALENV_BASE=$WORKON_HOME', 'export PIP_RESPECT_VIRTUALENV=true' ], use_sudo=False, partial=False, escape=True) run('source ~/.bash_profile') run('mkvirtualenv uriz')
def fix_umask(username): """ Sets umask to 022 fix an issue with the the build package process where it fails, due the files in the produced package have the wrong permissions. """ with settings(hide('warnings', 'running', 'stdout', 'stderr'), warn_only=True, capture=True): sed('/etc/login.defs', 'USERGROUPS_ENAB.*yes', 'USERGROUPS_ENAB no', use_sudo=True) sed('/etc/login.defs', 'UMASK.*', 'UMASK 022', use_sudo=True) homedir = '/home/' + username + '/' for f in [homedir + '.bash_profile', homedir + '.bashrc']: file_append(filename=f, text='umask 022') file_attribs(f, mode=750, owner=username)