<?php
namespace Deployer;
require 'recipe/common.php';

// Configuration
set('ssh_type', 'native');
set('ssh_multiplexing', true);

set('repository', 'https://gogs.ragnarok.yvan.hu/SIGMA/swedishchamber-granprize.git');
set('shared_files', [
    'config/autoload/local.php',
    'config/autoload/doctrine.local.php',
    'data/production.db',
]);
set('writable_dirs', []);
set('keep_releases', 3);
set('default_stage', 'staging');


// Servers
host('alfheim')
    ->stage('staging')
    ->user('yvan')
    ->forwardAgent()
    ->set('shared_files',[
        'config/autoload/local.php',
        'config/autoload/doctrine.local.php',
        'data/staging.db',
    ])
    ->set('php_service_name', 'php7.2-fpm')
    ->set('deploy_path', '/mnt/apps/granprize');

host('granprize')
    ->stage('production')
    ->user('vcreatives')
    ->forwardAgent()
    ->set('php_service_name', 'php7.2-fpm')
    ->set('deploy_path', '/var/www/granprize.swedishchamber.hu');

desc('Reload PHP-FPM service');
task('php-fpm:reload', function () {
    // The user must have rights for restart service
    // /etc/sudoers: username ALL=NOPASSWD:/bin/systemctl restart php-fpm.service
    run('sudo service {{php_service_name}} reload');
}); //->onlyOn('alfheim');
after('deploy:symlink', 'php-fpm:reload');


desc('Deploy your project');
task('deploy', [
    'deploy:prepare',
    'deploy:lock',
    'deploy:release',
    'deploy:update_code',
    'deploy:shared',
    'deploy:writable',
    'deploy:vendors',
    'deploy:clear_paths',
    'deploy:symlink',
    'deploy:unlock',
    'cleanup',
]);

after('deploy', 'success');
