Last active
September 30, 2023 00:27
-
-
Save eduardogpg/eadd77dfcd45463632e4df82b3fc766a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from fabric.api import task | |
| from fabric.api import local | |
| from fabric.api import cd | |
| from fabric.api import env | |
| from fabric.api import prefix | |
| from fabric.api import sudo | |
| from fabric.api import run | |
| from fabric.api import get | |
| from fabric.api import put # scp | |
| env.user = 'eduardo' | |
| env.hosts = ['147.182.241.110'] | |
| def make_deploy(commit=''): | |
| run_test() | |
| local('git add --all') | |
| local(f'git commit -m "{commit}"') | |
| local('git push origin main') | |
| deploy() | |
| def run_test(): | |
| local('python test.py') | |
| def deploy_if_test(): | |
| run_test() | |
| deploy() | |
| def deploy(): | |
| with cd('/home/eduardo/project/tiendaDeBarrio'): | |
| run('git pull') | |
| with prefix('source env/bin/activate'): | |
| run('pip install -r requirements.txt') | |
| run('python manage.py migrate') | |
| sudo('systemctl restart django') | |
| sudo('systemctl restart nginx') | |
| @task(alias='download_log') | |
| def download_error_log(): | |
| sudo('tail -n 1 /var/log/nginx/error.log.1 > tmp.log') | |
| get( | |
| local_path='error_log.log', | |
| remote_path='/home/eduardo/tmp.log' | |
| ) | |
| sudo('rm tmp.log') | |
| @task(alias='upload') | |
| def upload_file(): | |
| put( | |
| local_path='Makefile', | |
| remote_path='/home/eduardo/Makefile' | |
| ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment