terminal42/deployer-recipes

Create collection of deployer recipes

Closed this issue · 13 comments

We should create a collection of our recipes so we dont' need to duplicate the code every time in deploy.php.

See https://github.com/deployphp/recipes for how the repository should look like.

Please check across our projects what we could "standardize" when you're idle.

We can recommend some of our recipes - also working for contao with gitlab-ci ;-)
https://github.com/eikona-media/deployer-recipes

I have finally pushed my changes to master. @terminal42/pilots feel free to check it out.

Thank you @rabauss for providing your link, it was an inspiration for me and I also borrowed one of your recipes (maintaining copyrights of course). Hope that's fine? ☺️

Nice!
We also have to ignore config/parameters.yml (Contao 4.8), no?

I do have the following handy tasks:

task(
    'database:backup',
    static function () {
        run(
            'cd {{release_path}} && {{bin/php}} {{bin/console}} backup-manager:backup contao local -c gzip --filename ' . date('Y-m-d-H-i-s') . '.sql'
        );
    }
)->desc('Backup database prior update');


task(
    'contao_manager:download',
    static function () {
        run(
            'cd {{release_path}} && curl -LsO https://download.contao.org/contao-manager/stable/contao-manager.phar && mv contao-manager.phar web/contao-manager.phar.php'
        );
    }
)->desc('Download the Contao Manager PHAR');


task(
    'opcache:clear',
    static function () {
        run('cd {{current_path}} && echo "<?php opcache_reset();" > web/opcache.php && curl -L https://{{hostname}}/opcache.php && rm web/opcache.php');
    }
)->desc('Clearing OpCode cache');

The directory /contao-manager should be shared.

Can we use upload task instead of rsync? (Proposed by Yanick) Then we do not need to require that recipe.

We also have to ignore config/parameters.yml (Contao 4.8), no?

That's a valid point, I haven't checked the Symfony4 filestructure yet.

database:backup

We do already have it: https://github.com/terminal42/deployer-recipes/blob/master/recipe/database.php#L14

contao_manager:download

I am not sure if it should be added. What's the purpose of having Contao Manager together with the deployment system? trakked.io?

opcache:clear

We use an extra bundle for that: https://github.com/terminal42/deployer-recipes/blob/master/recipe/deploy.php#L89

Can we use upload task instead of rsync? (Proposed by Yanick) Then we do not need to require that recipe.

The upload task uses rsync behind the scenes and it does not seem to provide the exclude list option. Correct me if I'm wrong.

What's the purpose of having Contao Manager together with the deployment system? trakked.io?

Trakked. That’s correct. We can add it as recipe and everyone can enable it when needed.

We use an extra bundle for that:

Ah when I tested it on different environments I found that only the “vanilla” version works — and to clear opcache you need to do it via http https://serverfault.com/a/859937

Contao Manager task added in a74b5cc 👍🏻

The upload task uses rsync behind the scenes and it does not seem to provide the exclude list option. Correct me if I'm wrong.

Yes. It works the other way around. For every file or directory you want to upload you have to use the upload() function. It will end up in multiple rsync calls instead of just one but I actually like that one a lot better because I always forget to exclude things. Including is the better approach imho.

Then given this file structure:

/app/config/
    - parameters.yml
    - parameters.yml.dist
    - config.yml
    - services.yml

Out of this you have 2 files that should be excluded from the deployment. Using rsync we can define those in one of the recipes and forget about the rest. However with upload you would have to define a list of files for every project individually, no? That could be a bit cumbersome maybe.

add('shared_files', ['app/config/parameters.yml']);

can we somehow put this in a function and share

  • app/config/parameters.yml when on Contao < 4.8 and
  • config/parameters.yml when on Contao > 4.8?

Does this work?

set(
    'shared_files',
    static function () {
        if (file_exists('config/parameters.yml')) {
            return ['config/parameters.yml'];
        }

        return ['app/config/parameters.yml'];
    }
);

Good idea, implemented in bd804f8.

The rsync recipe is part of deployer/recipes. Do we need to require this package or is this too much overload?

"php": "^7.1"

Right, added that dependency in 1a204af.