EasyCorp / easy-deploy-bundle

The easiest way to deploy your Symfony applications
https://easycorp.io/EasyDeploy
MIT License
473 stars 103 forks source link

Tries to load dev bundle #65

Open wyllyjon opened 6 years ago

wyllyjon commented 6 years ago

Hello,

I am trying to deploy my 3.4 app, and during the Preparing app stage, I have this error :

The command "ssh -A petitecolo '(export APP_ENV=prod; cd /home/www/beta/releases/20180628172057 && /home/www/bin/composer install --no-dev --prefer-dist --no-interaction --quiet)'" failed.                     

  Exit Code: 1(General error)                                                                                                                                                                                      

  Working directory: /media/jon/Projets/Projets/LeCoinEcolo.fr/symfony                                                                                                                                             

  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:                                                                                                                                      

    Fatal error: Uncaught Symfony\Component\Debug\Exception\ClassNotFoundException: Attempted to load class "DoctrineFixturesBundle" from namespace "Doctrine\Bundle\FixturesBundle".                              

    Did you forget a "use" statement for another namespace? in /home/www/beta/releases/20180628172057/app/AppKernel.php:45                                                                                         

    Stack trace:                                                                                                                                                                                                   

    #0 /home/www/beta/releases/20180628172057/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php(492): AppKernel->registerBundles()                                                                

    #1 /home/www/beta/releases/20180628172057/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php(132): Symfony\Component\HttpKernel\Kernel->initializeBundles()                                    

    #2 /home/www/beta/releases/20180628172057/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Console/Application.php(64): Symfony\Component\HttpKernel\Kernel->boot()                                   

    #3 /home/www/beta/releases/20180628172057/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php(148): Symfony\Bundle\FrameworkBundle\Console\Application->doRun(Object(Symfony\Component\Conso  
  le\Input\ArgvInput), Object(Symfo in /home/www/beta/releases/20180628172057/app/AppKernel.php on line 45                                                                                                         

  install [--prefer-source] [--prefer-dist] [--dry-run] [--dev] [--no-dev] [--no-custom-installers] [--no-autoloader] [--no-scripts] [--no-progress] [--no-suggest] [-v|vv|vvv|--verbose] [-o|--optimize-autoload  
  er] [-a|--classmap-authoritative] [--apcu-autoloader] [--ignore-platform-reqs] [--] [<packages>]...                  

It uses APP_ENV, but I think it is a SF4 env variable (SYMFONY_ENV for SF 3.4), maybe that is why it tries to load a dev bundle (DoctrineFixturesBundle).

I tried to add in beforeStartingDeploy() a $this->runRemote('export SYMFONY_ENV=prod'); but I do have the error anyway.

Any clue ?

Thanks all !

DavidFeller commented 6 years ago

I have the same problem. As a temporary workaround I ended up overriding $this->_symfonyEnvironmentEnvVarName (line 385) in DefaultConfiguration.php, but as @wyllyjon mentioned SF3.4 always seems to be handled like a flex app.

Is there any configuration option we are not aware of?

wyllyjon commented 6 years ago

@DavidFeller, had you overridden it directly in the vendor folder or is there a way to override it properly ?

DavidFeller commented 6 years ago

I've overridden it only for testing purposes, but haven't had time to work on a proper solution, yet

YetiCGN commented 6 years ago

Yes, this is a problem if you use the Symfony 3 directory structure with 3.4 as the bundle assumes Symfony 4 directory structure and env variable name, which can't be changed from outside. See #66, too.

numediaweb commented 6 years ago

The issue is caused by those lines:

// vendor/easycorp/easy-deploy-bundle/src/Configuration/DefaultConfiguration.php:377

        } elseif (3 === $symfonyMajorVersion && 4 < $symfonyMinorVersion) {
            $this->_symfonyEnvironmentEnvVarName = 'SYMFONY_ENV';
            $this->setDirs('bin', 'app/config', 'var/cache', 'var/logs', 'src', 'app/Resources/views', 'web');
            $this->controllersToRemove(['web/app_*.php']);
            $this->sharedFiles = ['app/config/parameters.yml'];
            $this->sharedDirs = ['var/logs'];
            $this->writableDirs = ['var/cache/', 'var/logs/'];
        } elseif (4 === $symfonyMajorVersion || (3 === $symfonyMajorVersion && 4 >= $symfonyMinorVersion)) {
            $this->_symfonyEnvironmentEnvVarName = 'APP_ENV';
            $this->setDirs('bin', 'config', 'var/cache', 'var/log', 'src', 'templates', 'public');
            $this->controllersToRemove([]);
            $this->sharedDirs = ['var/log'];
            $this->writableDirs = ['var/cache/', 'var/log/'];
        }

It assumes that Symfony 3.4 is using Symfony's 4 directory structure which is wrong!

This is what fixed it for me:

      } elseif (3 === $symfonyMajorVersion) {
            $this->_symfonyEnvironmentEnvVarName = 'SYMFONY_ENV';
            $this->setDirs('bin', 'app/config', 'var/cache', 'var/logs', 'src', 'app/Resources/views', 'web');
            $this->controllersToRemove(['web/app_*.php']);
            $this->sharedFiles = ['app/config/parameters.yml'];
            $this->sharedDirs = ['var/logs'];
            $this->writableDirs = ['var/cache/', 'var/logs/'];
        } elseif (4 === $symfonyMajorVersion) {
            $this->_symfonyEnvironmentEnvVarName = 'APP_ENV';
            $this->setDirs('bin', 'config', 'var/cache', 'var/log', 'src', 'templates', 'public');
            $this->controllersToRemove([]);
            $this->sharedDirs = ['var/log'];
            $this->writableDirs = ['var/cache/', 'var/log/'];
        }
YetiCGN commented 6 years ago

@numediaweb Take a look at my PR. It enables you to set the directory layout from the outside without patching the DefaultConfiguration class. Because you could the 4 directory layout already with 3.4 and your change wouldn't work then.

wyllyjon commented 6 years ago

Hello YetiCGN !

How do you set the directory layout from outside ? I have looked at your commit, but I don't understand how it can be made ?

tks !

YetiCGN commented 6 years ago

Hi @wyllyjon,

the code to do this with the forked repo is

    return $this->getConfigBuilder()
        ->setDefaultConfiguration(\EasyCorp\Bundle\EasyDeployBundle\Configuration\DefaultConfiguration::SYMFONY_3)

(or any other of the constants) and then continuing to use the builder in your deploy.php.

wyllyjon commented 6 years ago

Ok !

Thanks for the info !

numediaweb commented 5 years ago

@javiereguiluz Can the PR from @YetiCGN be merged please?

YetiCGN commented 5 years ago

Seems this project is unmaintained / abandoned. No commit or merge for almost 6 months. If you add this block to your composer.json and switch the required version to dev-master it will pull my forked version:

[...]
"repositories": [
    {
        "type": "vcs",
        "url": "https://github.com/YetiCGN/easy-deploy-bundle"
    }
],
"require-dev": {
    "easycorp/easy-deploy-bundle": "dev-master",
[...]

Use at your own risk. Should this project be picked up again I can't guarantee to pull all changes to my fork.

javiereguiluz commented 5 years ago

@YetiCGN it may look abandoned ... but it's not. I use this bundle every day to deploy multiple personal projects. It's working fine to me :)

YetiCGN commented 5 years ago

Hey, Javier! Thanks for stopping by. I am using it (almost) every day as well to deploy a project, but I have to use my fork since it's a Symfony 3.4 project. By abandoned I meant that development has stopped almost half a year ago with no comments on 9 open pull requests from contributors. It's great to see you're still commenting here, but frankly I've decided to switch to Deployer for new projects although easy-deploy-bundle looked promising.

numediaweb commented 5 years ago

Still having this issue when using Symfony v3.4.29 @javiereguiluz can you please merge the PR?

YetiCGN commented 5 years ago

@numediaweb Switch to https://github.com/deployphp/deployer/, it's much more flexible and readily maintained. I did and never regretted it.

DavidFeller commented 5 years ago

@numediaweb: I agree with @YetiCGN. I did the same.