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

.env problem

Open wcizmowski opened this issue 6 years ago • 13 comments

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

wcizmowski avatar Jan 29 '19 14:01 wcizmowski

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

kunno avatar Jan 31 '19 23:01 kunno

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

ghost avatar Feb 17 '19 09:02 ghost

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

daum avatar Mar 07 '19 15:03 daum

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

stloc avatar Mar 18 '19 16:03 stloc

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.

gustawdaniel avatar Apr 08 '19 07:04 gustawdaniel

This works for me.

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

prograamer avatar May 08 '19 19:05 prograamer

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

nitrique avatar Jul 17 '19 12:07 nitrique

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

On Wed, Jul 17, 2019, 2:44 PM Nicolas Guillard [email protected] 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 .

ghost avatar Jul 17 '19 13:07 ghost

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

nitrique avatar Jul 17 '19 13:07 nitrique

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.

kaizokou avatar Aug 29 '19 08:08 kaizokou

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?

COil avatar Nov 30 '19 09:11 COil

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

numediaweb avatar May 31 '20 09:05 numediaweb

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.

fd6130 avatar Jan 15 '21 09:01 fd6130