0

I'm developing a deployment script which makes some extra tasks. Those tasks require some sensitive passwords so I thought about Laravel .env variables to avoid hardcoding them. Is it possible to use my declared .env variables within Envoy tasks?

Bhargav Rao
  • 50,140
  • 28
  • 121
  • 140
Alan
  • 2,559
  • 4
  • 32
  • 53

2 Answers2

1

The following is what has allowed me to properly use environment variables with Envoy:

@include('vendor/autoload.php');
@setup
  $dotenv = new \Dotenv\Dotenv(__DIR__);
  $dotenv->load();
@endsetup

@servers(['staging' => getenv('STAGING_SSH_HOST')])

## Get remote git status.    
@task('git.status', ['on' => 'staging'])
    echo "Fetching git status on staging environment ..."
    cd {{ getenv('STAGING_ROOT') }}
    git status
@endtask

The very similar approach presented by drinke9 did not work for me, I had to use this specific setup.

user2094178
  • 9,204
  • 10
  • 41
  • 70
0
@task('env')
  db_name=$(cat .env | grep DB_USERNAME)
  echo $db_name
@endtask

OR

@include('vendor/autoload.php')
@servers(['web' => 'foot@xxx.xxxx.com'])

@setup
    Dotenv\Dotenv::create(__DIR__)->load();
    $db=$_ENV['DB_DATABASE']
@endsetup

@task('env')
    echo {{$db}}
@endtask
drinke9
  • 1
  • 3