Skip to content

Symfony flex support #1440

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

Closed
wants to merge 3 commits into from
Closed

Conversation

zorn-v
Copy link

@zorn-v zorn-v commented Dec 8, 2017

Q A
Bug fix? No
New feature? Yes
BC breaks? No
Deprecations? No
Fixed tickets #1437

@zorn-v zorn-v force-pushed the symfony-flex-compat branch from 6df4be4 to 6be861c Compare December 8, 2017 04:04
set('clear_paths', []);

// 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)

set('shared_dirs', ['var/log', 'var/sessions']);

// 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

// 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.

*/

//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 !

set('writable_dirs', ['var/cache', 'var/log', 'var/sessions']);

//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

@Cryde
Copy link

Cryde commented Jan 4, 2018

Another tought : what about commands launched that require DB access (in prod mode) ? 🤔
Like migration for instance

@zorn-v
Copy link
Author

zorn-v commented Jan 5, 2018

And now think about is it ENV vars really good for deploy ?
But you can set env from some local file that not under version control anyway... And set that vars on remote somehow ;)

@antonmedv
Copy link
Member

@zorn-v no, then don't. 😄

I really want to combine all symfony recipes into one in next v7. Let's merge it now for v6 although.

Can you add init script for symfony flex?

@zorn-v
Copy link
Author

zorn-v commented Jan 5, 2018

What do you mean by 'init script' ?

@antonmedv
Copy link
Member

@zorn-v
Copy link
Author

zorn-v commented Jan 5, 2018

Yes, I already understand what do you mean 😄
How do you think, do it with accounting of DotEnv in prod ?

"Best practice" (env vars) not so conveniently... You need to set params in 3 different places.

  1. In deployer
  2. For console commands on remote
  3. For web server on remote

@antonmedv
Copy link
Member

Let's leave it for user? 😁

Trim every thing related of setting params from recipe and add comment to init template about for to start using .env, if user want of cause :))

I like .env file.

@zorn-v zorn-v force-pushed the symfony-flex-compat branch from 2795f09 to 06b888a Compare January 5, 2018 07:02
@zorn-v
Copy link
Author

zorn-v commented Jan 5, 2018

What do you think ?
Yes there need some workaround for composer install (coz scripts in composer.json)

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')

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']);

@antonmedv
Copy link
Member

Okay, problem now with:

if (!isset($_SERVER['APP_ENV'])) {
    if (!class_exists(Dotenv::class)) {
        throw new \RuntimeException('APP_ENV environment variable is not defined. You need to define environment variables for configuration or add "symfony/dotenv" as a Composer dependency to load variables from a .env file.');
    }
    (new Dotenv())->load(__DIR__.'/../.env');
}

I think we just need mention not to refactor to:

(new Dotenv())->load(__DIR__.'/../.env');

@Cryde
Copy link

Cryde commented Jan 27, 2018

Any news on this ?

@antonmedv
Copy link
Member

Need to figure out how to properly handle env. Soon will create my recipe.

@antonmedv antonmedv mentioned this pull request Feb 14, 2018
@zorn-v
Copy link
Author

zorn-v commented Mar 3, 2018

Any news, suggestions. Maybe need some recomendations ?

@zorn-v
Copy link
Author

zorn-v commented Mar 3, 2018

In last project I just installed apache-pack and put SetEnv in .htaccess (with preg_replace with same vars for DB in deployer)
ENV for deployer only needed for doctrine migrations (except APP_ENV=prod). Maybe think in this direction ?

@antonmedv
Copy link
Member

I’m thinking on suggesting of using doyens for prod. This will require APP_ENV rrmoval

@antonmedv
Copy link
Member

Done in 443de26

@antonmedv antonmedv closed this Mar 5, 2018
@zorn-v
Copy link
Author

zorn-v commented Mar 5, 2018

Maybe var/sessions also in shared ?
And default writable_mode no so good BTW.

@antonmedv
Copy link
Member

var stands for variable?

@antonmedv
Copy link
Member

var/sessions yes, my bad. Should go to shared.

@zorn-v
Copy link
Author

zorn-v commented Mar 5, 2018

About writable_mode - I get errors with acl one. chown is my bet )

@antonmedv
Copy link
Member

But you should set writable_mode in deploy.php

@zorn-v
Copy link
Author

zorn-v commented Mar 5, 2018

Yep, but I talk about default one.
Is acl so common ?

@antonmedv
Copy link
Member

No, but chown may require sudo. acl no. And acl more flexible.

But I'm thinking to refactor it in v7.

@Cryde
Copy link

Cryde commented Mar 12, 2018

Will there be a 6.0.1 ? for the missing var/sessions ? :p

@antonmedv
Copy link
Member

Yes :)
Sorry for delay.

@Cryde
Copy link

Cryde commented Mar 12, 2018

Don't be sorry ! You do an amazing work ! We can still add it ourself :D

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

Successfully merging this pull request may close these issues.

5 participants