@servers(['web' => ['root@zielonepogotowie.app'],'local'=>['localhost']]) @setup $api =[ 'root_dir'=>'/var/www/html', 'dir'=>'/var/www/html/dr_kwiatek', 'repo'=>'ssh://zielone-pogotowie@dev.haifai.pl:/var/git/dr_kwiatek.git' ]; $db = [ 'password'=>'T9ev6FF%)', 'username'=>'dr_kwiatek', 'database'=>'dr_kwiatek', 'local_database'=>'dr_kwiatek' ]; $server_array = [ 'web' =>'root@zielonepogotowie.app' ]; $now = date('Y-m-d_H-i-s'); $backupName = $now . ".backup"; // $backupName = "2020-03-19_15-02-29.backup"; // TMP: @endsetup @task('supervisor:restart', ['on' => 'web']) sudo supervisorctl restart all @endtask @story('update') pull {{-- composer --}} db:backup db:migrate @endstory @story('init') clone composer permissions db:createuser db:createdb db:migrate:fresh @endstory @story('db:fetch') db:backup db:backup:fetch db:backup:remove db:backup:use @endstory @task('pull', ['on' => 'web']) eval `ssh-agent -s` ssh-add ~/.ssh/zielone_server_rsa cd {{$api['dir']}} git pull @endtask @task('clone', ['on' => 'web']) eval `ssh-agent -s` ssh-add ~/.ssh/zielone_server_rsa cd {{$api['root_dir']}} git clone {{$api['repo']}} @endtask @task('composer', ['on' => 'web']) cd {{$api['dir']}} composer install --no-dev @endtask @task('permissions', ['on' => 'web']) cd {{$api['dir']}} sudo chmod -R 777 storage @endtask @task('prepare', ['on' => 'web']) cd {{$api['dir']}} php artisan jwt:secret -f @endtask @task('db:createuser', ['on' => 'web']) su postgres createuser -Pls {{$db['username']}} {{$db['password']}} {{$db['password']}} exit @endtask @task('db:createdb', ['on' => 'web']) su postgres createdb -U postgres -O {{$db['username']}} {{$db['database']}} exit @endtask @task('db:migrate:fresh', ['on' => 'web']) cd {{$api['dir']}} php artisan migrate:fresh --seed @endtask @task('db:migrate', ['on' => 'web']) cd {{$api['dir']}} php artisan migrate --force @endtask @task('db:backup', ['on' => 'web']) cd {{$api['dir']}} su postgres pg_dump -d {{$db['database']}} -xO -b -v -f "{{$api['dir']}}/backups/{{$backupName}}" exit @endtask @task('db:backup:fetch', ['on' => 'local']) rsync -h {{$server_array['web']}}:{{$api['dir']}}/backups/{{$backupName}} backups/{{$backupName}} && echo Fetched {{$backupName}} @endtask @task('db:backup:remove', ['on' => 'web']) [ -e {{$api['dir']}}/backups/{{$backupName}} ] && rm -R {{$api['dir']}}/backups/{{$backupName}} echo Cleared. @endtask @task('db:backup:use', ['on' => 'local']) npm run db:drop || true npm run db:create docker exec -u $(id -u $(whoami)):$(id -g $(whoami)) -i dr-kwiatek-postgres psql -Upostgres -d{{$db['local_database']}} -fbackups/{{$backupName}} @endtask @task('cdn:fetch', ['on' => 'local']) sudo chmod -R 777 storage [ -e storage/app/public ] && rm -R storage/app/public rsync -rh --progress {{$server_array['web']}}:{{$api['dir']}}/storage/app/public storage/app @endtask