Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deployer configuration #19

Open
wachterjohannes opened this issue Jul 7, 2017 · 3 comments
Open

Deployer configuration #19

wachterjohannes opened this issue Jul 7, 2017 · 3 comments

Comments

@wachterjohannes
Copy link
Member

No description provided.

@alexander-schranz
Copy link
Member

alexander-schranz commented Nov 17, 2017

Here an example with doctrine migrations, nanbando backup, multiple prod server and one stage

<?php

namespace Deployer;

use Symfony\Component\Console\Helper\QuestionHelper;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Question\ConfirmationQuestion;

require 'vendor/deployer/deployer/recipe/symfony3.php';
require 'vendor/nanbando/deployer-recipe/recipe.php';

// options

option('force', null, InputOption::VALUE_NONE, 'Force deploy (skip tag check)');

// Configuration

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

set('repository', '[email protected]:sulu/sulu-demo.git');

set('shared_dirs', ['var/indexes', 'var/sessions', 'var/sitemaps', 'var/uploads', 'web/uploads']);

set('writable_dirs',
    // FIXME var/uploads is network share and setfacl can't use there
    ['var/cache', 'var/indexes', 'var/logs', 'var/sessions', 'web/uploads']
);

set('http_user', 'www-data');
set('http_group', 'www-data');

set('composer_options', '{{composer_action}} --verbose --prefer-dist --no-progress --no-interaction --no-dev --optimize-autoloader --apcu-autoloader');

# backup over nanbando
set('bin/nanbando', '/usr/local/bin/nanbando');
set('nanbando_push', false);
set('nanbando_backup_options', '{{release_name}} --process database');

set('tasks', true);

// Servers

//stage
host('stage.example.org')
    ->user('deployer')
    ->forwardAgent()
    ->set('deploy_path', '/var/www/stage.example.org')
    ->set('branch', function () {
        return input()->getOption('branch') ?: 'develop';
    })
    ->set('nanbando', false)
    ->stage('stage');

// web01 prod
host('node01.example.org')
    ->user('deployer')
    ->forwardAgent()
    ->set('deploy_path', '/var/www/example.org')
    ->set('branch', function () {
        return input()->getOption('branch') ?: 'master';
    })
    ->stage('prod');

// web02 prod
host('node02.example.org')
    ->user('deployer')
    ->forwardAgent()
    ->set('deploy_path', '/var/www/example.org')
    ->set('branch', function () {
        return input()->getOption('branch') ?: 'master';
    })
    ->stage('prod');

// Tasks
desc('Check requirements');
task('deploy:check', function () {
    if (!input()->hasArgument('stage') || !input()->hasOption('tag') || !input()->hasOption('force')) {
        return;
    }

    $stage = input()->getArgument('stage');
    if (false === strpos($stage, ':prod') || input()->getOption('tag')) {
        return;
    }

    if (input()->getOption('tag')) {
        return;
    }

    if (input()->getOption('force')) {
        $question = new ConfirmationQuestion('Do you really want to deploy to "prod" without tag? [y, N] ', false);

        $helper = new QuestionHelper();
        $result = $helper->ask(input(), output(), $question);

        if (!$result) {
            throw new \Exception('You have aborted the deploy.');
        }

        return;
    }

    throw new \Exception('Tag options is required for stage "prod".');
});
before('deploy', 'deploy:check');

desc('Restart PHP-FPM service');
task('php-fpm:restart', function () {
    // The user must have rights for restart service
    run('sudo service php7.0-fpm restart');
});
after('deploy:symlink', 'php-fpm:restart');

desc('Reload nginx configuration');
task('nginx:reload', function () {
    // The user must have rights for reload nginx configuration
    run('sudo service nginx reload');
});
after('deploy:symlink', 'nginx:reload');

// [Optional] if deploy fails automatically unlock.
after('deploy:failed', 'deploy:unlock');

// Migrate database before symlink new release.
before('deploy:symlink', 'database:migrate');

desc('Schedule schedule-tasks');
task('task:schedule:system-tasks', function () {
    if (!get('tasks')) {
        return;
    }

    run('{{bin/php}} {{bin/console}} task:schedule:system-tasks {{console_options}}');
});
after('database:migrate', 'task:schedule:system-tasks');

@wachterjohannes
Copy link
Member Author

@alexander-schranz we should add some examples directly to the repository:

  • `deployer.minimum.php´: single server with database-migration
  • deployer.php: single server + single stage with database-migration and backup
  • deployer.advanced.php: multiple servers + single stage with database-migration, backup and tag deployment (could be a open-source recipe in a own repository)

@alexander-schranz
Copy link
Member

In some projects it maybe also make sense to add bin/adminconsole doctrine:cache:clear-metadata to it where the metadata cache is for example in redis

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants