Skip to content

Commit

Permalink
Change env file generation
Browse files Browse the repository at this point in the history
  • Loading branch information
loevgaard committed Aug 15, 2024
1 parent 105e57c commit 7a256a1
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/task/setono_dotenv.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Dotenv\Dotenv;
use Webmozart\Assert\Assert;
use function Deployer\upload;

/**
* This step has to come AFTER the deploy:update_code step because
Expand Down Expand Up @@ -149,16 +150,18 @@
*/
$overriddenValues = array_merge($overriddenValues, $newOverriddenValues);

/**
* This will generate a $command variable that will save a multiline text into a file
* See https://stackoverflow.com/questions/10969953/how-to-output-a-multiline-string-in-bash
*/
$command = sprintf("cat <<EOT > {{release_path}}/.env.%s.local\n", $stage);
$filename = sprintf(__DIR__ . '/.env.%s.local', $stage);

$data = '';
foreach ($overriddenValues as $key => $val) {
$command .= $key . '=' . $val . "\n";
$data .= $key . '=' . $val . "\n";
}
$command .= 'EOT';
run($command);

file_put_contents($filename, $data);

upload($filename, '{{release_path}}');

unlink($filename);

// Now we rerun the generation because we changed the environment variables
invoke('dotenv:generate');
Expand Down

0 comments on commit 7a256a1

Please sign in to comment.