Skip to content

Commit aea92c2

Browse files
xel1045Gandhi11
authored andcommitted
feat: allow dotenv-vars to be configured when deploying
1 parent c885301 commit aea92c2

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

Envoy.blade.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
$deploy = new Exolnet\Envoy\ConfigDeploy(get_defined_vars());
55
$environment = $deploy->getEnvironment();
66
extract($environment->extractVariables());
7+
8+
$dotenvVars = array_filter(explode(PHP_EOL, $dotenvVars ?? ''));
79
@endsetup
810

911
@servers(['web' => $serverString])
@@ -49,6 +51,7 @@
4951
deploy:git
5052
deploy:link
5153
deploy:copy
54+
deploy:dotenv
5255
deploy:composer
5356
deploy:npm
5457
deploy:provisioned
@@ -80,6 +83,7 @@
8083
deploy:git
8184
deploy:link
8285
deploy:copy
86+
deploy:dotenv
8387
deploy:composer
8488
deploy:npm
8589
deploy:provisioned
@@ -254,6 +258,24 @@
254258
@endforeach
255259
@endtask
256260

261+
@task('deploy:dotenv')
262+
cd "{{ $releasePath }}"
263+
264+
echo "Updating .env file with provided variables"
265+
echo "---->{{ json_encode($dotenvVars) }}"
266+
267+
@foreach($dotenvVars as $dotenvVar)
268+
@php
269+
[$dotenvVarName, $dotenvVarValue] = explode('=', $dotenvVar, 2);
270+
271+
$dotenvVarName = trim(escapeshellarg(trim($dotenvVarName)), '\'');
272+
$dotenvVarValue = trim(escapeshellarg(trim($dotenvVarValue)), '\'');
273+
@endphp
274+
echo "Setting ---->{{ $dotenvVarName }}-- to -->{{ $dotenvVarValue }}"
275+
sed -i -E "s/^(#\\s*)?{{ $dotenvVarName }}=.*/{{ $dotenvVarName }}={{ $dotenvVarValue }}/" .env
276+
@endforeach
277+
@endtask
278+
257279
@task('deploy:composer')
258280
@foreach (array_unique([$releasePath, $assetsPath]) as $path)
259281
cd "{{ $path }}"

0 commit comments

Comments
 (0)