EasyCorp / easy-deploy-bundle

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

.env problem #87

Open wcizmowski opened 5 years ago

wcizmowski commented 5 years ago

Hi,

I have $this->runRemote('export SYMFONY_ENV=prod');

but uppon deploy error

PHP Fatal error: Uncaught Symfony\Component\Dotenv\Exception\PathException: Unable to read the "/var/www/vhosts/iwebi.pl/app-s4.iwebi.pl/releases/20190129153613/.env" environment file. in /var/www/vhosts/iwebi.pl/app-s4.iwebi.pl/releases/20190129153613/vendor/symfony/dotenv/Dotenv.php:466

butr

kunno commented 5 years ago

In src/Deployer/DefaultDeployer.php:264 change $this->runRemote(sprintf('cp -RPp {{ deploy_dir }}/repo/* {{ project_dir }}')); to $this->runRemote(sprintf('cp -RPp {{ deploy_dir }}/repo/. {{ project_dir }}')); this will 'cp' all files including the hidden .env. Hope that helps. If you are using Symfony 4.2, there might be some more steps to do. Just comment if you run into any other issues.

Also, since you're deploying to prod you should move composer require symfony/dotenv from require-dev to require in your composer.json

ghost commented 5 years ago

I confirm that changing /repo/* to /repo/. works for Symfony 4.2.

daum commented 5 years ago

I've hit this problem too. A note is by doing the change in the repo copy it's going to copy the full .git directory over too. Instead since often you don't want all your dotfiles copied it'd be better to use beforePreparing:

    public function beforePreparing()
    {
        $this->log('<h3>Copying over the .env files</>');
        $this->runRemote('cp {{ deploy_dir }}/repo/.env {{ project_dir }}');
    }
stloc commented 5 years ago

the /release directory doesn't contain .env file while /repo dir has this .env file

gustawdaniel commented 5 years ago

Could I please describe this issue in documentation? I confused about best practices of managing .env when I using this bundle.

I was trying

    // run some local or remote commands before the deployment is started
    public function beforeStartingDeploy()
    {
         $this
             ->runLocal('./vendor/bin/simple-phpunit --env=dev');
    }

and

    // run some local or remote commands before the deployment is started
    public function beforeStartingDeploy()
    {
         $this
             ->symfonyEnvironment('dev')
             ->runLocal('./vendor/bin/simple-phpunit');
    }

But both does not works. In case of default config

    public function beforeStartingDeploy()
    {
         $this
             ->runLocal('./vendor/bin/simple-phpunit');
    }

I obtaining

The command "(export APP_ENV=prod; cd /home/daniel/pro/pregnacore/core && ./vendor/bin/simple-ph  
  punit --env=dev)" failed. 

Because of APP_ENV should be dev not prod locally during testing. Because I have test in dev requirements.

prograamer commented 5 years ago

This works for me.

public function **beforeUpdating**() { $this->runRemote('cp {{ deploy_dir }}/repo/.env {{ project_dir }}'); parent::beforeUpdating(); }

nitrique commented 5 years ago

Hi,

On my side I prefer :

public function beforePreparing() { $this->log('<h3>Copying over the .env files</>'); $this->runRemote('cp {{ deploy_dir }}/repo/.env.dist {{ project_dir }}/.env'); }

ghost commented 5 years ago

For Symfony 4.3 it should be copy .env to .env.local

On Wed, Jul 17, 2019, 2:44 PM Nicolas Guillard notifications@github.com wrote:

Hi,

On my side I prefer :

public function beforePreparing() { $this->log('

Copying over the .env files</>'); $this->runRemote('cp {{ deploy_dir }}/repo/.env.dist {{ project_dir }}/.env'); }

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/EasyCorp/easy-deploy-bundle/issues/87?email_source=notifications&email_token=AKMP3X5HWWYVCTWI5O7EGE3P74H4NA5CNFSM4GTAYAKKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD2ECEDQ#issuecomment-512238094, or mute the thread https://github.com/notifications/unsubscribe-auth/AKMP3XZJ7GYINMMFOCHDUATP74H4NANCNFSM4GTAYAKA .

nitrique commented 5 years ago

The deploy script don't seems to copy dot files on project root folder, is that only for me ?

kaizokou commented 5 years ago

I also faced this issue. As a workaround, I put the .env and .env.local file as shared file. ->sharedFilesAndDirs(['.env','.env.local'])

The drawback is that you now have to handle manually the change in your .env file as it won't be synchronized with your repo, but anyway you would have to edit your .env.local file. No big deal.

COil commented 4 years ago

Hello, I have also to put the .env as a shared file. Check out https://stackoverflow.com/q/59111354/633864, in fact I don't need to use env vars as my application only relies on .env files. Do you think I would be ok to introduce a new parameter to see if the APP_ENV env should be set?

numediaweb commented 4 years ago

Using Symfony 5 with PHP 7.4, this PR https://github.com/EasyCorp/easy-deploy-bundle/pull/114 fixes that issue.

fd6130 commented 3 years ago

I thought we shouldn't commit any secrets in .env ? If that the case we have to manual copy paste our .env.local.php each time we deploy and not relying on the .env from git.