mirror of
https://github.com/coollabsio/coolify.git
synced 2026-10-28 09:34:36 +08:00
Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: Andras Bacsai <5845193+andrasbacsai@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Furox <177975472+Furox-Art@users.noreply.github.com> Co-authored-by: johandenhollander <johan.den.hollander@finalist.nl> Co-authored-by: João Cruz <161638790+SrJooJ@users.noreply.github.com> Co-authored-by: Saim Hashmi <hashmisaim037@gmail.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
50 lines
1.9 KiB
PHP
50 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace App\Traits;
|
|
|
|
use App\Services\DatabaseStartCommandExecutor;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Support\Collection;
|
|
use Spatie\Activitylog\Models\Activity;
|
|
|
|
trait ExecutesDatabaseStartCommands
|
|
{
|
|
private function executeDatabaseStartCommands(array $commands, Model $database, ?Activity $activity = null): Activity
|
|
{
|
|
if ($activity) {
|
|
return app(DatabaseStartCommandExecutor::class)->execute($commands, $database, $activity);
|
|
}
|
|
|
|
return remote_process($commands, $database->destination->server, callEventOnFinish: 'DatabaseStatusChanged', queue: deployment_queue());
|
|
}
|
|
|
|
/**
|
|
* Whether a `KEY=value` list already defines the exact key (not just a key or value containing it).
|
|
*
|
|
* @param Collection<int, string> $environmentVariables
|
|
*/
|
|
private function hasEnvironmentVariable(Collection $environmentVariables, string $key): bool
|
|
{
|
|
return $environmentVariables->contains(fn ($variable) => str($variable)->before('=')->value() === $key);
|
|
}
|
|
|
|
/**
|
|
* Adds the Coolify variables that applications and services also get. A key that the user
|
|
* defines wins.
|
|
*
|
|
* @param Collection<int, string> $environmentVariables
|
|
*/
|
|
private function addCoolifyEnvironmentVariables(Collection $environmentVariables): void
|
|
{
|
|
$definedKeys = $environmentVariables->map(fn ($variable) => str($variable)->before('=')->value());
|
|
$coolifyVariables = collect([
|
|
'COOLIFY_RESOURCE_UUID' => $this->database->uuid,
|
|
'COOLIFY_CONTAINER_NAME' => $this->database->uuid,
|
|
])->except($definedKeys->all())->merge(coolifyDefaultEnvironmentVariables($this->database, $definedKeys));
|
|
|
|
foreach ($coolifyVariables as $key => $value) {
|
|
$environmentVariables->push($key.'='.escapeDollarSign($value));
|
|
}
|
|
}
|
|
}
|