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

Symfony flex support #1440

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions CHANGELOG.md
Expand Up @@ -4,9 +4,10 @@
[v6.0.3...master](https://github.com/deployphp/deployer/compare/v6.0.3...master)

### Changed
- Added recipe for Symfony flex
- Added support for GroupTask in invoke() [#1364]
- Magento2 recipe optimizes the autoloader after the DI compilation [#1365]
- Host's `roles()` API now can accept arrays too
- Host's `roles()` API now can accept arrays too
- Fixed bug where wrong time format is passed to touch when deploying assets [#1390]
- Added artisan:migrate:fresh task for laravel recipe
- Added platform config to composer.json [#1426]
Expand All @@ -21,7 +22,7 @@
### Changed
- Laravel version check defaults to 5.5 if not found [#1352]

### Fixed
### Fixed
- Updated Laravel recipe to not run `artisan:optimize` on Laravel >= 5.5, as that command is now deprecated ([see upgrade notes](https://laravel.com/docs/5.5/upgrade)) [#1352]

## v6.0.2
Expand Down
34 changes: 34 additions & 0 deletions recipe/symfony-flex.php
@@ -0,0 +1,34 @@
<?php

namespace Deployer;

require_once __DIR__ . '/symfony3.php';

/**
* Symfony Flex Configuration
*/

//No need to clear anything
set('clear_paths', []);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's already define in symfony3 recipe :)

Copy link
Author

@zorn-v zorn-v Jan 5, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My bad ! Sorry !


// Symfony shared dirs
set('shared_dirs', ['var/log', 'var/sessions']);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

Copy link
Author

@zorn-v zorn-v Jan 5, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also nope. var/log, not var/logs

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default directory for logs is var/log (since 3.4)


// Symfony writable dirs
set('writable_dirs', ['var/cache', 'var/log', 'var/sessions']);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also var/log


//File for DotEnv if not using env vars
set('shared_files', ['.env']);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And btw the dotenv component is in require-dev when we do a fresh install ... I'm not sure if it's a good idea

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually there is a conversation on moving dotenv to require symfony/symfony#25643


// Symfony web dir
set('web_dir', 'public');

// Assets
set('assets', ['public/css', 'public/images', 'public/js']);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

set('assets', ['{{web_dir}}/css', '{{web_dir}}/images', '{{web_dir}}/js']);


// Environment vars
set('env', function () {
return [
'APP_ENV' => get('symfony_env')
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably add documentation to tell the user to put "symfony_env" in it's host.yml

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before it was SYMFONY_ENV https://github.com/deployphp/deployer/blob/master/recipe/symfony.php#L41
But it not for flex

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe:

// Environment vars
set('env', function () {
    return [
        'SYMFONY_ENV' => get('symfony_env'),
        'APP_ENV'     => get('symfony_env'),
    ];
});

Copy link
Contributor

@gander gander Jan 12, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can not set environment variables on my server so Dotenv is also included in the production environment. There were complications. I noticed that setting APP_ENV disables reading the .env file, therefore I set only symfony_env to have all commands with --env={{symfony_env}} option. My env for now:

// Environment vars
set('env', []);

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. Maybe you are right and your solution is much better than my hacky workaround #1440 (comment)
AFAIR composer does not account --env=
Will test, and change it if all works fine.

];
});
5 changes: 3 additions & 2 deletions recipe/symfony.php
Expand Up @@ -42,9 +42,10 @@
];
});

// Adding support for the Symfony3 directory structure
// Adding support for the Symfony3 and flex directory structure
set('bin_dir', 'app');
set('var_dir', 'app');
set('web_dir', 'web');

// Symfony console bin
set('bin/console', function () {
Expand Down Expand Up @@ -92,7 +93,7 @@
* Install assets from public dir of bundles
*/
task('deploy:assets:install', function () {
run('{{bin/php}} {{bin/console}} assets:install {{console_options}} {{release_path}}/web');
run('{{bin/php}} {{bin/console}} assets:install {{console_options}} {{release_path}}/{{web_dir}}');
})->desc('Install bundle assets');


Expand Down
2 changes: 2 additions & 0 deletions src/Console/InitCommand.php
Expand Up @@ -13,6 +13,7 @@
use Deployer\Initializer\Template\CommonTemplate;
use Deployer\Initializer\Template\DrupalTemplate;
use Deployer\Initializer\Template\LaravelTemplate;
use Deployer\Initializer\Template\SymfonyFlexTemplate;
use Deployer\Initializer\Template\SymfonyTemplate;
use Deployer\Initializer\Template\Typo3Template;
use Deployer\Initializer\Template\Yii2AdvancedAppTemplate;
Expand Down Expand Up @@ -162,6 +163,7 @@ private function createInitializer()
$initializer->addTemplate('Common', new CommonTemplate());
$initializer->addTemplate('Laravel', new LaravelTemplate());
$initializer->addTemplate('Symfony', new SymfonyTemplate());
$initializer->addTemplate('Symfony flex', new SymfonyFlexTemplate());
$initializer->addTemplate('Yii', new YiiTemplate());
$initializer->addTemplate('Yii2 Basic App', new Yii2BasicAppTemplate());
$initializer->addTemplate('Yii2 Advanced App', new Yii2AdvancedAppTemplate());
Expand Down
44 changes: 44 additions & 0 deletions src/Initializer/Template/SymfonyFlexTemplate.php
@@ -0,0 +1,44 @@
<?php
/* (c) github.com/zorn-v
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Deployer\Initializer\Template;

/**
* Generate a Symfony flex deployer configuration.
*
* @author zorn-v
* @codeCoverageIgnore
*/
class SymfonyFlexTemplate extends FrameworkTemplate
{
protected function getRecipe()
{
return 'symfony-flex';
}

/**
* {@inheritDoc}
*/
protected function getExtraContent()
{
return <<<PHP

// Migrate database before symlink new release.

before('deploy:symlink', 'database:migrate');

//If you don't use DotEnv in prod just wipe it out
task('clear:env', function () {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What purpose of this task?

Copy link
Author

@zorn-v zorn-v Jan 5, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DotEnv does not run at all if APP_ENV is set https://github.com/symfony/recipes/blob/master/symfony/framework-bundle/3.3/public/index.php#L11
Same in console commands
But it need for composer install (scripts can not load deps in require-dev if APP_ENV not 'prod')

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's better not to hack APP_ENV but unstead write comment what user need to move dotenv to require section.

Copy link
Author

@zorn-v zorn-v Jan 6, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But this task needed exactly in order if DotEnv in require ;)
One more time - DotEnv does not run if APP_ENV is set.
If you don't set it in env, composer install will fail.

Yes I know that is hack. But I think that I can not convince community to change !isset($_SERVER['APP_ENV']) to file_exists(__DIR__.'/../.env')

//DotEnt does not execute if APP_ENV is set, but it required for `composer install`
\$env = get('env');
unset(\$env['APP_ENV']);
set('env', \$env);
})->setPrivate();
after('deploy:vendors', 'clear:env');
PHP;
}
}