Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
4.3 kB
1
Indexable
Never
<?php
namespace Deployer;

require 'recipe/symfony.php';


// Configuration

set('docker/php', function () {
    return 'docker exec -i langu-php-new';
});

set('docker/php/root', function () {
    return 'docker exec -i -u root langu-php-new';
});

set('docker/webserver', function () {
    return 'docker exec -i langu-webserver';
});

set('path_langu', function () {
    return '/var/www/langu';
});

set('bin/php', function () {
    return '/usr/local/bin/php';
});

set('ssh_type', 'native');
set('ssh_multiplexing', false);
set('keep_releases', 10);
set('default_stage', 'staging');

set('git_tty', true);
set('repository', 'git@gitlab.com:heylangu/langu.git');

//add('shared_files', ['app/config/parameters.yml', 'api/config/parameters.yml']);
add('copy_dirs', ['public/images/cache']);
add('shared_dirs', ['public/media/cache', 'public/uploads', 'uploads']);

add('writable_dirs', ['public/uploads', 'public/images/cache', 'public/media/cache', 'public/uploads/blog/resources', 'uploads', 'public/uploads/seo/icons', 'public/uploads/pages/photos']);
//set('clear_paths', ['public/app_dev.php', 'public/api_dev.php', 'public/config.php', 'web/apcu.php', 'web/admin_dev.php']);
// Servers

host('langu002')->hostname('88.99.120.85')
    ->user('langu')
    ->identityFile('~/id_rsa.key')
    ->stage('staging')
    ->set('env', ['env' => 'dev'])
    ->set('symfony_env', 'dev')
    ->set('branch', 'changes_recommended_sorting')
    ->set('clear_paths', ['public/config.php', 'public/apcu.php'])
    ->set('deploy_path', '/home/langu/app')
;
//
host('langu003')->hostname('195.201.21.161')
    ->user('langu')
    ->identityFile('~/id_rsa.key')
    ->stage('prod')
    ->set('env', ['env' => 'dev'])
    ->set('symfony_env', 'dev')
    ->set('branch', 'update_symfony_to_5')
    ->set('clear_paths', ['public/config.php', 'public/apcu.php'])
    ->set('deploy_path', '/home/langu/app');

// Tasks

task('deploy:vendors', function () {
    run('docker exec -i -u root langu-php-new composer install');
})->desc('Install composer');

/**
 * override original task
 */
task('deploy:assets:install', function () {
    //run('{{docker/php}} {{bin/php}} {{path_langu}}/bin/console langu:assets:install');
    //run('{{docker/php/root}} {{bin/php}} {{path_langu}}/bin/admin-console ckeditor:install');
    //run('{{docker/php}} {{bin/php}} {{path_langu}}/bin/console langu:assets:install');
})->desc('Install bundle assets');

task('deploy:create_code_for_rollback', function () {
    run('rsync -r --exclude={"var",".git"} /home/langu/app/langu-new/. /home/langu/app/langu-rollback-new');
})->desc('Create langu container for rollback');

task('deploy:update_code_in_container-langu-php', function () {
    run('rsync -r -avz --exclude={".git"} /home/langu/app/release/. /home/langu/app/langu-new');
})->desc('Update docker code in container');


task('deploy:cache:clear', function () {
    run('{{docker/php}} {{bin/php}} bin/console cache:clear --no-warmup');
});

task('deploy:cache:warmup', function () {
    run('{{docker/php}} {{bin/php}} bin/console cache:warmup -vvv');
});

task('php-fpm:kill', function () {
    run('{{docker/php/root}} killall php-fpm -q -w');
})->desc('Kill PHP-FPM service');

task('php-fpm:start', function () {
    run('{{docker/php/root}} php-fpm -D');
})->desc('Start PHP-FPM service');

task('migrate', function () {
    run('{{docker/php}} {{bin/php}} {{path_langu}}/bin/console doctrine:migrations:migrate');
    //run('{{docker/php}} {{bin/php}} {{path_langu}}/bin/admin-console doctrine:migrations:migrate --em=admin_users');
})->desc('Migrations database');


task('rollback', function () {
    run('rsync  -avz -r --exclude="vendor" /home/langu/app/langu-rollback-new/. /home/langu/app/langu-new');
    run('{{docker/php/root}} killall php-fpm -q -w');
    run('{{docker/php/root}} php-fpm -D');
})->desc('rollback');

after('deploy:lock', 'deploy:create_code_for_rollback');
after('deploy:update_code', 'deploy:update_code_in_container-langu-php');
//after('migrate', 'deploy:update_code_in_container-langu-webserver');
after('deploy:writable', 'migrate');
after('deploy:vendors', 'deploy:cache:clear');

after('deploy', 'php-fpm:kill');
after('php-fpm:kill', 'php-fpm:start');
// [Optional] if deploy fails automatically unlock.
after('deploy:failed', 'deploy:unlock');