easy-deploy-bundle icon indicating copy to clipboard operation
easy-deploy-bundle copied to clipboard

Allow to fill parameters.yml on first deploy?

Open rubenrubiob opened this issue 7 years ago • 5 comments

Hello,

When first deploying a Symfony application, the composer install command fails when clearing the cache within the post-deployment scripts as the parameters.yml file is not filled with production parameters:

Output:                                                                                                                                                                
  ================                                                                                                                                                       
  Error Output:                                                                                                                                                          
  ================                                                                                                                                                       
  Script Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache handling the symfony-scripts event terminated with an exception                             
                                                                                                                                                                         
    [RuntimeException]                                                                                                                                                   
    An error occurred when executing the "'cache:clear --no-warmup'" command:                                                                                            
                                                                                                                                                                         
      [Doctrine\DBAL\Exception\ConnectionException]                                                                                                                      
      An exception occured in driver: SQLSTATE[HY000] [1045] Access denied for us                                                                                        
      er 'root'@'localhost' (using password: NO)                                                                                                                         
                                                                                                                                                                         
                                                                                                                                                                         
      [Doctrine\DBAL\Driver\PDOException]                                                                                                                                
      SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using pas                                                                                        
      sword: NO)                                                                                                                                                         
                                                                                                                                                                         
                                                                                                                                                                         
      [PDOException]                                                                                                                                                     
      SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using pas                                                                                        
      sword: NO)

What would be the best solution for this? One option would be removing the cache clear script from the composer.json file as the deployer takes care of that, but that would not fix the problem entirely, as the parameters.yml file would still remain with non-production values, and some other custom post-deployment scripts could fail, like executing doctrine migrations. And, even so, the cache clearing command from the deployer would fail —I have already tried.

I guess the best solution would be that the deployer prompts for parameters' values, the same way composer does when installing or updating the project. Would that be possible? If not, would there be any other workaround other than connecting to the server and filling the parameters manually?

By the way, the deployer works like a charm, at least in a little project where I tested it.

Regards!

rubenrubiob avatar May 27 '17 22:05 rubenrubiob

Thanks for reporting this issue. I had a similar report on the Symfony Slack. Looking at the error message, this looks related to a Doctrine bug that has been around during several years and was fixed recently.

As you can see in the error message, when you clear the cache ... Doctrine tries to connect to your database!!!! This happens when the server_version parameter isn't defined in your Doctrine config.

In the next stable version of Doctrine this will be fixed ... but for now, this can be fixed defining this config option:

doctrine:
    dbal:
        # ...
        server_version: 5.7

The value of this option is the exact version of your database. For example 5.7 is for MySQL 5.7, but you should replace it by your own database version.

Please try setting this option and tell us if the error is gone. Thanks!

javiereguiluz avatar May 28 '17 17:05 javiereguiluz

I have tried what you say, adding the server_version to doctrine config, and I tried to perform a clean deploy again and it works perfectly.

Although this solves the exception thrown when first deploying and, therefore, it allows to perform the first deployment, you still have to connect manually to the server to edit the parameters.yml file, add the configuration values, and then clear the cache again. And the same happens when new parameters are added to the parameters.yml.dist file, if I am not wrong.

Ideally, the deployer would allow to fill the parameters the same way composer does when executing it from command line, asking for the value for each not-defined parameter, but I guess that is not easy. Would there be an easy workaround for this?

Thank you!

rubenrubiob avatar May 28 '17 19:05 rubenrubiob

+1

gianiaz avatar Jul 23 '17 09:07 gianiaz

This will help you: https://github.com/Incenteev/ParameterHandler

This will rewrite ENV's configured in composer.json and put them into parameters.yml during composer install. It also adds new variables when they come.

fon60 avatar Jul 28 '17 22:07 fon60

ENV variables are a good way to solve this problem now. Take a look here: https://symfony.com/doc/current/configuration/external_parameters.html

patrick-mota avatar Dec 05 '17 23:12 patrick-mota