MORE PARSERS
This commit is contained in:
@@ -5,6 +5,7 @@ namespace App\Models;
|
|||||||
use App\Enums\ApplicationDeploymentStatus;
|
use App\Enums\ApplicationDeploymentStatus;
|
||||||
use App\Enums\ProxyTypes;
|
use App\Enums\ProxyTypes;
|
||||||
use App\Jobs\ServerFilesFromServerJob;
|
use App\Jobs\ServerFilesFromServerJob;
|
||||||
|
use App\Livewire\Project\Shared\Destination;
|
||||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||||
|
@@ -253,7 +253,7 @@ function generateServiceSpecificFqdns(ServiceApplication|Application $resource)
|
|||||||
|
|
||||||
return $payload;
|
return $payload;
|
||||||
}
|
}
|
||||||
function fqdnLabelsForCaddy(string $network, string $uuid, Collection $domains, bool $is_force_https_enabled = false, $onlyPort = null, ?Collection $serviceLabels = null, ?bool $is_gzip_enabled = true, ?bool $is_stripprefix_enabled = true, ?string $service_name = null, ?string $image = null, string $redirect_direction = 'both')
|
function fqdnLabelsForCaddy(string $network, string $uuid, Collection $domains, bool $is_force_https_enabled = false, $onlyPort = null, ?Collection $serviceLabels = null, ?bool $is_gzip_enabled = true, ?bool $is_stripprefix_enabled = true, ?string $service_name = null, ?string $image = null, string $redirect_direction = 'both', ?string $predefinedPort = null)
|
||||||
{
|
{
|
||||||
$labels = collect([]);
|
$labels = collect([]);
|
||||||
if ($serviceLabels) {
|
if ($serviceLabels) {
|
||||||
@@ -272,6 +272,9 @@ function fqdnLabelsForCaddy(string $network, string $uuid, Collection $domains,
|
|||||||
if (is_null($port) && ! is_null($onlyPort)) {
|
if (is_null($port) && ! is_null($onlyPort)) {
|
||||||
$port = $onlyPort;
|
$port = $onlyPort;
|
||||||
}
|
}
|
||||||
|
if (is_null($port) && $predefinedPort) {
|
||||||
|
$port = $predefinedPort;
|
||||||
|
}
|
||||||
$labels->push("caddy_{$loop}={$schema}://{$host}");
|
$labels->push("caddy_{$loop}={$schema}://{$host}");
|
||||||
$labels->push("caddy_{$loop}.header=-Server");
|
$labels->push("caddy_{$loop}.header=-Server");
|
||||||
$labels->push("caddy_{$loop}.try_files={path} /index.html /index.php");
|
$labels->push("caddy_{$loop}.try_files={path} /index.html /index.php");
|
||||||
|
@@ -63,27 +63,27 @@ function base_configuration_dir(): string
|
|||||||
}
|
}
|
||||||
function application_configuration_dir(): string
|
function application_configuration_dir(): string
|
||||||
{
|
{
|
||||||
return base_configuration_dir().'/applications';
|
return base_configuration_dir() . '/applications';
|
||||||
}
|
}
|
||||||
function service_configuration_dir(): string
|
function service_configuration_dir(): string
|
||||||
{
|
{
|
||||||
return base_configuration_dir().'/services';
|
return base_configuration_dir() . '/services';
|
||||||
}
|
}
|
||||||
function database_configuration_dir(): string
|
function database_configuration_dir(): string
|
||||||
{
|
{
|
||||||
return base_configuration_dir().'/databases';
|
return base_configuration_dir() . '/databases';
|
||||||
}
|
}
|
||||||
function database_proxy_dir($uuid): string
|
function database_proxy_dir($uuid): string
|
||||||
{
|
{
|
||||||
return base_configuration_dir()."/databases/$uuid/proxy";
|
return base_configuration_dir() . "/databases/$uuid/proxy";
|
||||||
}
|
}
|
||||||
function backup_dir(): string
|
function backup_dir(): string
|
||||||
{
|
{
|
||||||
return base_configuration_dir().'/backups';
|
return base_configuration_dir() . '/backups';
|
||||||
}
|
}
|
||||||
function metrics_dir(): string
|
function metrics_dir(): string
|
||||||
{
|
{
|
||||||
return base_configuration_dir().'/metrics';
|
return base_configuration_dir() . '/metrics';
|
||||||
}
|
}
|
||||||
|
|
||||||
function generate_readme_file(string $name, string $updated_at): string
|
function generate_readme_file(string $name, string $updated_at): string
|
||||||
@@ -118,8 +118,8 @@ function refreshSession(?Team $team = null): void
|
|||||||
$team = User::find(auth()->user()->id)->teams->first();
|
$team = User::find(auth()->user()->id)->teams->first();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Cache::forget('team:'.auth()->user()->id);
|
Cache::forget('team:' . auth()->user()->id);
|
||||||
Cache::remember('team:'.auth()->user()->id, 3600, function () use ($team) {
|
Cache::remember('team:' . auth()->user()->id, 3600, function () use ($team) {
|
||||||
return $team;
|
return $team;
|
||||||
});
|
});
|
||||||
session(['currentTeam' => $team]);
|
session(['currentTeam' => $team]);
|
||||||
@@ -148,7 +148,7 @@ function handleError(?Throwable $error = null, ?Livewire\Component $livewire = n
|
|||||||
$message = null;
|
$message = null;
|
||||||
}
|
}
|
||||||
if ($customErrorMessage) {
|
if ($customErrorMessage) {
|
||||||
$message = $customErrorMessage.' '.$message;
|
$message = $customErrorMessage . ' ' . $message;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($livewire)) {
|
if (isset($livewire)) {
|
||||||
@@ -393,7 +393,7 @@ function send_user_an_email(MailMessage $mail, string $email, ?string $cc = null
|
|||||||
Mail::send(
|
Mail::send(
|
||||||
[],
|
[],
|
||||||
[],
|
[],
|
||||||
fn (Message $message) => $message
|
fn(Message $message) => $message
|
||||||
->to($email)
|
->to($email)
|
||||||
->replyTo($email)
|
->replyTo($email)
|
||||||
->cc($cc)
|
->cc($cc)
|
||||||
@@ -404,7 +404,7 @@ function send_user_an_email(MailMessage $mail, string $email, ?string $cc = null
|
|||||||
Mail::send(
|
Mail::send(
|
||||||
[],
|
[],
|
||||||
[],
|
[],
|
||||||
fn (Message $message) => $message
|
fn(Message $message) => $message
|
||||||
->to($email)
|
->to($email)
|
||||||
->subject($mail->subject)
|
->subject($mail->subject)
|
||||||
->html((string) $mail->render())
|
->html((string) $mail->render())
|
||||||
@@ -627,19 +627,19 @@ function queryResourcesByUuid(string $uuid)
|
|||||||
function generatTagDeployWebhook($tag_name)
|
function generatTagDeployWebhook($tag_name)
|
||||||
{
|
{
|
||||||
$baseUrl = base_url();
|
$baseUrl = base_url();
|
||||||
$api = Url::fromString($baseUrl).'/api/v1';
|
$api = Url::fromString($baseUrl) . '/api/v1';
|
||||||
$endpoint = "/deploy?tag=$tag_name";
|
$endpoint = "/deploy?tag=$tag_name";
|
||||||
$url = $api.$endpoint;
|
$url = $api . $endpoint;
|
||||||
|
|
||||||
return $url;
|
return $url;
|
||||||
}
|
}
|
||||||
function generateDeployWebhook($resource)
|
function generateDeployWebhook($resource)
|
||||||
{
|
{
|
||||||
$baseUrl = base_url();
|
$baseUrl = base_url();
|
||||||
$api = Url::fromString($baseUrl).'/api/v1';
|
$api = Url::fromString($baseUrl) . '/api/v1';
|
||||||
$endpoint = '/deploy';
|
$endpoint = '/deploy';
|
||||||
$uuid = data_get($resource, 'uuid');
|
$uuid = data_get($resource, 'uuid');
|
||||||
$url = $api.$endpoint."?uuid=$uuid&force=false";
|
$url = $api . $endpoint . "?uuid=$uuid&force=false";
|
||||||
|
|
||||||
return $url;
|
return $url;
|
||||||
}
|
}
|
||||||
@@ -650,7 +650,7 @@ function generateGitManualWebhook($resource, $type)
|
|||||||
}
|
}
|
||||||
if ($resource->getMorphClass() === 'App\Models\Application') {
|
if ($resource->getMorphClass() === 'App\Models\Application') {
|
||||||
$baseUrl = base_url();
|
$baseUrl = base_url();
|
||||||
$api = Url::fromString($baseUrl)."/webhooks/source/$type/events/manual";
|
$api = Url::fromString($baseUrl) . "/webhooks/source/$type/events/manual";
|
||||||
|
|
||||||
return $api;
|
return $api;
|
||||||
}
|
}
|
||||||
@@ -852,7 +852,7 @@ function parseEnvVariable(Str|string $value)
|
|||||||
'port' => $port,
|
'port' => $port,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
function generateEnvValue(string $command, ?Service $service = null)
|
function generateEnvValue(string $command, Service|Application|null $service = null)
|
||||||
{
|
{
|
||||||
switch ($command) {
|
switch ($command) {
|
||||||
case 'PASSWORD':
|
case 'PASSWORD':
|
||||||
@@ -927,7 +927,8 @@ function generateEnvValue(string $command, ?Service $service = null)
|
|||||||
$generatedValue = $token->toString();
|
$generatedValue = $token->toString();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
$generatedValue = Str::random(16);
|
// $generatedValue = Str::random(16);
|
||||||
|
$generatedValue = null;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -980,7 +981,7 @@ function validate_dns_entry(string $fqdn, Server $server)
|
|||||||
$query = new DNSQuery($dns_server);
|
$query = new DNSQuery($dns_server);
|
||||||
$results = $query->query($host, $type);
|
$results = $query->query($host, $type);
|
||||||
if ($results === false || $query->hasError()) {
|
if ($results === false || $query->hasError()) {
|
||||||
ray('Error: '.$query->getLasterror());
|
ray('Error: ' . $query->getLasterror());
|
||||||
} else {
|
} else {
|
||||||
foreach ($results as $result) {
|
foreach ($results as $result) {
|
||||||
if ($result->getType() == $type) {
|
if ($result->getType() == $type) {
|
||||||
@@ -990,7 +991,7 @@ function validate_dns_entry(string $fqdn, Server $server)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if ($result->getData() === $ip) {
|
if ($result->getData() === $ip) {
|
||||||
ray($host.' has IP address '.$result->getData());
|
ray($host . ' has IP address ' . $result->getData());
|
||||||
ray($result->getString());
|
ray($result->getString());
|
||||||
$found_matching_ip = true;
|
$found_matching_ip = true;
|
||||||
break;
|
break;
|
||||||
@@ -1038,15 +1039,15 @@ function checkIfDomainIsAlreadyUsed(Collection|array $domains, ?string $teamId =
|
|||||||
$applications = Application::ownedByCurrentTeamAPI($teamId)->get(['fqdn', 'uuid']);
|
$applications = Application::ownedByCurrentTeamAPI($teamId)->get(['fqdn', 'uuid']);
|
||||||
$serviceApplications = ServiceApplication::ownedByCurrentTeamAPI($teamId)->get(['fqdn', 'uuid']);
|
$serviceApplications = ServiceApplication::ownedByCurrentTeamAPI($teamId)->get(['fqdn', 'uuid']);
|
||||||
if ($uuid) {
|
if ($uuid) {
|
||||||
$applications = $applications->filter(fn ($app) => $app->uuid !== $uuid);
|
$applications = $applications->filter(fn($app) => $app->uuid !== $uuid);
|
||||||
$serviceApplications = $serviceApplications->filter(fn ($app) => $app->uuid !== $uuid);
|
$serviceApplications = $serviceApplications->filter(fn($app) => $app->uuid !== $uuid);
|
||||||
}
|
}
|
||||||
$domainFound = false;
|
$domainFound = false;
|
||||||
foreach ($applications as $app) {
|
foreach ($applications as $app) {
|
||||||
if (is_null($app->fqdn)) {
|
if (is_null($app->fqdn)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$list_of_domains = collect(explode(',', $app->fqdn))->filter(fn ($fqdn) => $fqdn !== '');
|
$list_of_domains = collect(explode(',', $app->fqdn))->filter(fn($fqdn) => $fqdn !== '');
|
||||||
foreach ($list_of_domains as $domain) {
|
foreach ($list_of_domains as $domain) {
|
||||||
if (str($domain)->endsWith('/')) {
|
if (str($domain)->endsWith('/')) {
|
||||||
$domain = str($domain)->beforeLast('/');
|
$domain = str($domain)->beforeLast('/');
|
||||||
@@ -1065,7 +1066,7 @@ function checkIfDomainIsAlreadyUsed(Collection|array $domains, ?string $teamId =
|
|||||||
if (str($app->fqdn)->isEmpty()) {
|
if (str($app->fqdn)->isEmpty()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$list_of_domains = collect(explode(',', $app->fqdn))->filter(fn ($fqdn) => $fqdn !== '');
|
$list_of_domains = collect(explode(',', $app->fqdn))->filter(fn($fqdn) => $fqdn !== '');
|
||||||
foreach ($list_of_domains as $domain) {
|
foreach ($list_of_domains as $domain) {
|
||||||
if (str($domain)->endsWith('/')) {
|
if (str($domain)->endsWith('/')) {
|
||||||
$domain = str($domain)->beforeLast('/');
|
$domain = str($domain)->beforeLast('/');
|
||||||
@@ -1115,7 +1116,7 @@ function check_domain_usage(ServiceApplication|Application|null $resource = null
|
|||||||
});
|
});
|
||||||
$apps = Application::all();
|
$apps = Application::all();
|
||||||
foreach ($apps as $app) {
|
foreach ($apps as $app) {
|
||||||
$list_of_domains = collect(explode(',', $app->fqdn))->filter(fn ($fqdn) => $fqdn !== '');
|
$list_of_domains = collect(explode(',', $app->fqdn))->filter(fn($fqdn) => $fqdn !== '');
|
||||||
foreach ($list_of_domains as $domain) {
|
foreach ($list_of_domains as $domain) {
|
||||||
if (str($domain)->endsWith('/')) {
|
if (str($domain)->endsWith('/')) {
|
||||||
$domain = str($domain)->beforeLast('/');
|
$domain = str($domain)->beforeLast('/');
|
||||||
@@ -1134,7 +1135,7 @@ function check_domain_usage(ServiceApplication|Application|null $resource = null
|
|||||||
}
|
}
|
||||||
$apps = ServiceApplication::all();
|
$apps = ServiceApplication::all();
|
||||||
foreach ($apps as $app) {
|
foreach ($apps as $app) {
|
||||||
$list_of_domains = collect(explode(',', $app->fqdn))->filter(fn ($fqdn) => $fqdn !== '');
|
$list_of_domains = collect(explode(',', $app->fqdn))->filter(fn($fqdn) => $fqdn !== '');
|
||||||
foreach ($list_of_domains as $domain) {
|
foreach ($list_of_domains as $domain) {
|
||||||
if (str($domain)->endsWith('/')) {
|
if (str($domain)->endsWith('/')) {
|
||||||
$domain = str($domain)->beforeLast('/');
|
$domain = str($domain)->beforeLast('/');
|
||||||
@@ -1177,7 +1178,7 @@ function parseCommandsByLineForSudo(Collection $commands, Server $server): array
|
|||||||
});
|
});
|
||||||
$commands = $commands->map(function ($line) use ($server) {
|
$commands = $commands->map(function ($line) use ($server) {
|
||||||
if (Str::startsWith($line, 'sudo mkdir -p')) {
|
if (Str::startsWith($line, 'sudo mkdir -p')) {
|
||||||
return "$line && sudo chown -R $server->user:$server->user ".Str::after($line, 'sudo mkdir -p').' && sudo chmod -R o-rwx '.Str::after($line, 'sudo mkdir -p');
|
return "$line && sudo chown -R $server->user:$server->user " . Str::after($line, 'sudo mkdir -p') . ' && sudo chmod -R o-rwx ' . Str::after($line, 'sudo mkdir -p');
|
||||||
}
|
}
|
||||||
|
|
||||||
return $line;
|
return $line;
|
||||||
@@ -1208,7 +1209,7 @@ function parseLineForSudo(string $command, Server $server): string
|
|||||||
$command = "sudo $command";
|
$command = "sudo $command";
|
||||||
}
|
}
|
||||||
if (Str::startsWith($command, 'sudo mkdir -p')) {
|
if (Str::startsWith($command, 'sudo mkdir -p')) {
|
||||||
$command = "$command && sudo chown -R $server->user:$server->user ".Str::after($command, 'sudo mkdir -p').' && sudo chmod -R o-rwx '.Str::after($command, 'sudo mkdir -p');
|
$command = "$command && sudo chown -R $server->user:$server->user " . Str::after($command, 'sudo mkdir -p') . ' && sudo chmod -R o-rwx ' . Str::after($command, 'sudo mkdir -p');
|
||||||
}
|
}
|
||||||
if (str($command)->contains('$(') || str($command)->contains('`')) {
|
if (str($command)->contains('$(') || str($command)->contains('`')) {
|
||||||
$command = str($command)->replace('$(', '$(sudo ')->replace('`', '`sudo ')->value();
|
$command = str($command)->replace('$(', '$(sudo ')->replace('`', '`sudo ')->value();
|
||||||
@@ -1341,7 +1342,6 @@ function parseServiceVolumes($serviceVolumes, $resource, $topLevelVolumes, $pull
|
|||||||
$isDirectory = true;
|
$isDirectory = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
if ($type?->value() === 'bind') {
|
if ($type?->value() === 'bind') {
|
||||||
if ($source->value() === '/var/run/docker.sock') {
|
if ($source->value() === '/var/run/docker.sock') {
|
||||||
@@ -1351,9 +1351,9 @@ function parseServiceVolumes($serviceVolumes, $resource, $topLevelVolumes, $pull
|
|||||||
return $volume;
|
return $volume;
|
||||||
}
|
}
|
||||||
if (get_class($resource) === "App\Models\Application") {
|
if (get_class($resource) === "App\Models\Application") {
|
||||||
$dir = base_configuration_dir().'/applications/'.$resource->uuid;
|
$dir = base_configuration_dir() . '/applications/' . $resource->uuid;
|
||||||
} else {
|
} else {
|
||||||
$dir = base_configuration_dir().'/services/'.$resource->service->uuid;
|
$dir = base_configuration_dir() . '/services/' . $resource->service->uuid;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($source->startsWith('.')) {
|
if ($source->startsWith('.')) {
|
||||||
@@ -1363,7 +1363,7 @@ function parseServiceVolumes($serviceVolumes, $resource, $topLevelVolumes, $pull
|
|||||||
$source = $source->replaceFirst('~', $dir);
|
$source = $source->replaceFirst('~', $dir);
|
||||||
}
|
}
|
||||||
if ($pull_request_id !== 0) {
|
if ($pull_request_id !== 0) {
|
||||||
$source = $source."-pr-$pull_request_id";
|
$source = $source . "-pr-$pull_request_id";
|
||||||
}
|
}
|
||||||
if (! $resource?->settings?->is_preserve_repository_enabled || $foundConfig?->is_based_on_git) {
|
if (! $resource?->settings?->is_preserve_repository_enabled || $foundConfig?->is_based_on_git) {
|
||||||
LocalFileVolume::updateOrCreate(
|
LocalFileVolume::updateOrCreate(
|
||||||
@@ -1819,7 +1819,7 @@ function parseDockerComposeFile(Service|Application $resource, bool $isNew = fal
|
|||||||
|
|
||||||
if (! $isDatabase) {
|
if (! $isDatabase) {
|
||||||
if ($savedService->fqdn) {
|
if ($savedService->fqdn) {
|
||||||
data_set($savedService, 'fqdn', $savedService->fqdn.','.$fqdn);
|
data_set($savedService, 'fqdn', $savedService->fqdn . ',' . $fqdn);
|
||||||
} else {
|
} else {
|
||||||
data_set($savedService, 'fqdn', $fqdn);
|
data_set($savedService, 'fqdn', $fqdn);
|
||||||
}
|
}
|
||||||
@@ -1879,7 +1879,7 @@ function parseDockerComposeFile(Service|Application $resource, bool $isNew = fal
|
|||||||
if (Str::lower($forService) === $serviceName) {
|
if (Str::lower($forService) === $serviceName) {
|
||||||
$fqdn = generateFqdn($resource->server, $containerName);
|
$fqdn = generateFqdn($resource->server, $containerName);
|
||||||
} else {
|
} else {
|
||||||
$fqdn = generateFqdn($resource->server, Str::lower($forService).'-'.$resource->uuid);
|
$fqdn = generateFqdn($resource->server, Str::lower($forService) . '-' . $resource->uuid);
|
||||||
}
|
}
|
||||||
if ($port) {
|
if ($port) {
|
||||||
$fqdn = "$fqdn:$port";
|
$fqdn = "$fqdn:$port";
|
||||||
@@ -2083,7 +2083,6 @@ function parseDockerComposeFile(Service|Application $resource, bool $isNew = fal
|
|||||||
updateCompose($savedService);
|
updateCompose($savedService);
|
||||||
|
|
||||||
return $service;
|
return $service;
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
$envs_from_coolify = $resource->environment_variables()->get();
|
$envs_from_coolify = $resource->environment_variables()->get();
|
||||||
@@ -2215,7 +2214,7 @@ function parseDockerComposeFile(Service|Application $resource, bool $isNew = fal
|
|||||||
$name = $volume->before(':');
|
$name = $volume->before(':');
|
||||||
$mount = $volume->after(':');
|
$mount = $volume->after(':');
|
||||||
if ($name->startsWith('.') || $name->startsWith('~')) {
|
if ($name->startsWith('.') || $name->startsWith('~')) {
|
||||||
$dir = base_configuration_dir().'/applications/'.$resource->uuid;
|
$dir = base_configuration_dir() . '/applications/' . $resource->uuid;
|
||||||
if ($name->startsWith('.')) {
|
if ($name->startsWith('.')) {
|
||||||
$name = $name->replaceFirst('.', $dir);
|
$name = $name->replaceFirst('.', $dir);
|
||||||
}
|
}
|
||||||
@@ -2223,12 +2222,12 @@ function parseDockerComposeFile(Service|Application $resource, bool $isNew = fal
|
|||||||
$name = $name->replaceFirst('~', $dir);
|
$name = $name->replaceFirst('~', $dir);
|
||||||
}
|
}
|
||||||
if ($pull_request_id !== 0) {
|
if ($pull_request_id !== 0) {
|
||||||
$name = $name."-pr-$pull_request_id";
|
$name = $name . "-pr-$pull_request_id";
|
||||||
}
|
}
|
||||||
$volume = str("$name:$mount");
|
$volume = str("$name:$mount");
|
||||||
} else {
|
} else {
|
||||||
if ($pull_request_id !== 0) {
|
if ($pull_request_id !== 0) {
|
||||||
$name = $name."-pr-$pull_request_id";
|
$name = $name . "-pr-$pull_request_id";
|
||||||
$volume = str("$name:$mount");
|
$volume = str("$name:$mount");
|
||||||
if ($topLevelVolumes->has($name)) {
|
if ($topLevelVolumes->has($name)) {
|
||||||
$v = $topLevelVolumes->get($name);
|
$v = $topLevelVolumes->get($name);
|
||||||
@@ -2267,7 +2266,7 @@ function parseDockerComposeFile(Service|Application $resource, bool $isNew = fal
|
|||||||
$name = $volume->before(':');
|
$name = $volume->before(':');
|
||||||
$mount = $volume->after(':');
|
$mount = $volume->after(':');
|
||||||
if ($pull_request_id !== 0) {
|
if ($pull_request_id !== 0) {
|
||||||
$name = $name."-pr-$pull_request_id";
|
$name = $name . "-pr-$pull_request_id";
|
||||||
}
|
}
|
||||||
$volume = str("$name:$mount");
|
$volume = str("$name:$mount");
|
||||||
}
|
}
|
||||||
@@ -2278,7 +2277,7 @@ function parseDockerComposeFile(Service|Application $resource, bool $isNew = fal
|
|||||||
$read_only = data_get($volume, 'read_only');
|
$read_only = data_get($volume, 'read_only');
|
||||||
if ($source && $target) {
|
if ($source && $target) {
|
||||||
if ((str($source)->startsWith('.') || str($source)->startsWith('~'))) {
|
if ((str($source)->startsWith('.') || str($source)->startsWith('~'))) {
|
||||||
$dir = base_configuration_dir().'/applications/'.$resource->uuid;
|
$dir = base_configuration_dir() . '/applications/' . $resource->uuid;
|
||||||
if (str($source, '.')) {
|
if (str($source, '.')) {
|
||||||
$source = str($source)->replaceFirst('.', $dir);
|
$source = str($source)->replaceFirst('.', $dir);
|
||||||
}
|
}
|
||||||
@@ -2286,21 +2285,21 @@ function parseDockerComposeFile(Service|Application $resource, bool $isNew = fal
|
|||||||
$source = str($source)->replaceFirst('~', $dir);
|
$source = str($source)->replaceFirst('~', $dir);
|
||||||
}
|
}
|
||||||
if ($pull_request_id !== 0) {
|
if ($pull_request_id !== 0) {
|
||||||
$source = $source."-pr-$pull_request_id";
|
$source = $source . "-pr-$pull_request_id";
|
||||||
}
|
}
|
||||||
if ($read_only) {
|
if ($read_only) {
|
||||||
data_set($volume, 'source', $source.':'.$target.':ro');
|
data_set($volume, 'source', $source . ':' . $target . ':ro');
|
||||||
} else {
|
} else {
|
||||||
data_set($volume, 'source', $source.':'.$target);
|
data_set($volume, 'source', $source . ':' . $target);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if ($pull_request_id !== 0) {
|
if ($pull_request_id !== 0) {
|
||||||
$source = $source."-pr-$pull_request_id";
|
$source = $source . "-pr-$pull_request_id";
|
||||||
}
|
}
|
||||||
if ($read_only) {
|
if ($read_only) {
|
||||||
data_set($volume, 'source', $source.':'.$target.':ro');
|
data_set($volume, 'source', $source . ':' . $target . ':ro');
|
||||||
} else {
|
} else {
|
||||||
data_set($volume, 'source', $source.':'.$target);
|
data_set($volume, 'source', $source . ':' . $target);
|
||||||
}
|
}
|
||||||
if (! str($source)->startsWith('/')) {
|
if (! str($source)->startsWith('/')) {
|
||||||
if ($topLevelVolumes->has($source)) {
|
if ($topLevelVolumes->has($source)) {
|
||||||
@@ -2339,7 +2338,7 @@ function parseDockerComposeFile(Service|Application $resource, bool $isNew = fal
|
|||||||
$name = $volume->before(':');
|
$name = $volume->before(':');
|
||||||
$mount = $volume->after(':');
|
$mount = $volume->after(':');
|
||||||
if ($name->startsWith('.') || $name->startsWith('~')) {
|
if ($name->startsWith('.') || $name->startsWith('~')) {
|
||||||
$dir = base_configuration_dir().'/applications/'.$resource->uuid;
|
$dir = base_configuration_dir() . '/applications/' . $resource->uuid;
|
||||||
if ($name->startsWith('.')) {
|
if ($name->startsWith('.')) {
|
||||||
$name = $name->replaceFirst('.', $dir);
|
$name = $name->replaceFirst('.', $dir);
|
||||||
}
|
}
|
||||||
@@ -2347,13 +2346,13 @@ function parseDockerComposeFile(Service|Application $resource, bool $isNew = fal
|
|||||||
$name = $name->replaceFirst('~', $dir);
|
$name = $name->replaceFirst('~', $dir);
|
||||||
}
|
}
|
||||||
if ($pull_request_id !== 0) {
|
if ($pull_request_id !== 0) {
|
||||||
$name = $name."-pr-$pull_request_id";
|
$name = $name . "-pr-$pull_request_id";
|
||||||
}
|
}
|
||||||
$volume = str("$name:$mount");
|
$volume = str("$name:$mount");
|
||||||
} else {
|
} else {
|
||||||
if ($pull_request_id !== 0) {
|
if ($pull_request_id !== 0) {
|
||||||
$uuid = $resource->uuid;
|
$uuid = $resource->uuid;
|
||||||
$name = $uuid."-$name-pr-$pull_request_id";
|
$name = $uuid . "-$name-pr-$pull_request_id";
|
||||||
$volume = str("$name:$mount");
|
$volume = str("$name:$mount");
|
||||||
if ($topLevelVolumes->has($name)) {
|
if ($topLevelVolumes->has($name)) {
|
||||||
$v = $topLevelVolumes->get($name);
|
$v = $topLevelVolumes->get($name);
|
||||||
@@ -2372,7 +2371,7 @@ function parseDockerComposeFile(Service|Application $resource, bool $isNew = fal
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$uuid = $resource->uuid;
|
$uuid = $resource->uuid;
|
||||||
$name = str($uuid."-$name");
|
$name = str($uuid . "-$name");
|
||||||
$volume = str("$name:$mount");
|
$volume = str("$name:$mount");
|
||||||
if ($topLevelVolumes->has($name->value())) {
|
if ($topLevelVolumes->has($name->value())) {
|
||||||
$v = $topLevelVolumes->get($name->value());
|
$v = $topLevelVolumes->get($name->value());
|
||||||
@@ -2395,7 +2394,7 @@ function parseDockerComposeFile(Service|Application $resource, bool $isNew = fal
|
|||||||
$name = $volume->before(':');
|
$name = $volume->before(':');
|
||||||
$mount = $volume->after(':');
|
$mount = $volume->after(':');
|
||||||
if ($pull_request_id !== 0) {
|
if ($pull_request_id !== 0) {
|
||||||
$name = $name."-pr-$pull_request_id";
|
$name = $name . "-pr-$pull_request_id";
|
||||||
}
|
}
|
||||||
$volume = str("$name:$mount");
|
$volume = str("$name:$mount");
|
||||||
}
|
}
|
||||||
@@ -2407,7 +2406,7 @@ function parseDockerComposeFile(Service|Application $resource, bool $isNew = fal
|
|||||||
if ($source && $target) {
|
if ($source && $target) {
|
||||||
$uuid = $resource->uuid;
|
$uuid = $resource->uuid;
|
||||||
if ((str($source)->startsWith('.') || str($source)->startsWith('~') || str($source)->startsWith('/'))) {
|
if ((str($source)->startsWith('.') || str($source)->startsWith('~') || str($source)->startsWith('/'))) {
|
||||||
$dir = base_configuration_dir().'/applications/'.$resource->uuid;
|
$dir = base_configuration_dir() . '/applications/' . $resource->uuid;
|
||||||
if (str($source, '.')) {
|
if (str($source, '.')) {
|
||||||
$source = str($source)->replaceFirst('.', $dir);
|
$source = str($source)->replaceFirst('.', $dir);
|
||||||
}
|
}
|
||||||
@@ -2415,20 +2414,20 @@ function parseDockerComposeFile(Service|Application $resource, bool $isNew = fal
|
|||||||
$source = str($source)->replaceFirst('~', $dir);
|
$source = str($source)->replaceFirst('~', $dir);
|
||||||
}
|
}
|
||||||
if ($read_only) {
|
if ($read_only) {
|
||||||
data_set($volume, 'source', $source.':'.$target.':ro');
|
data_set($volume, 'source', $source . ':' . $target . ':ro');
|
||||||
} else {
|
} else {
|
||||||
data_set($volume, 'source', $source.':'.$target);
|
data_set($volume, 'source', $source . ':' . $target);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if ($pull_request_id === 0) {
|
if ($pull_request_id === 0) {
|
||||||
$source = $uuid."-$source";
|
$source = $uuid . "-$source";
|
||||||
} else {
|
} else {
|
||||||
$source = $uuid."-$source-pr-$pull_request_id";
|
$source = $uuid . "-$source-pr-$pull_request_id";
|
||||||
}
|
}
|
||||||
if ($read_only) {
|
if ($read_only) {
|
||||||
data_set($volume, 'source', $source.':'.$target.':ro');
|
data_set($volume, 'source', $source . ':' . $target . ':ro');
|
||||||
} else {
|
} else {
|
||||||
data_set($volume, 'source', $source.':'.$target);
|
data_set($volume, 'source', $source . ':' . $target);
|
||||||
}
|
}
|
||||||
if (! str($source)->startsWith('/')) {
|
if (! str($source)->startsWith('/')) {
|
||||||
if ($topLevelVolumes->has($source)) {
|
if ($topLevelVolumes->has($source)) {
|
||||||
@@ -2463,7 +2462,7 @@ function parseDockerComposeFile(Service|Application $resource, bool $isNew = fal
|
|||||||
|
|
||||||
if ($pull_request_id !== 0 && count($serviceDependencies) > 0) {
|
if ($pull_request_id !== 0 && count($serviceDependencies) > 0) {
|
||||||
$serviceDependencies = $serviceDependencies->map(function ($dependency) use ($pull_request_id) {
|
$serviceDependencies = $serviceDependencies->map(function ($dependency) use ($pull_request_id) {
|
||||||
return $dependency."-pr-$pull_request_id";
|
return $dependency . "-pr-$pull_request_id";
|
||||||
});
|
});
|
||||||
data_set($service, 'depends_on', $serviceDependencies->toArray());
|
data_set($service, 'depends_on', $serviceDependencies->toArray());
|
||||||
}
|
}
|
||||||
@@ -2634,7 +2633,7 @@ function parseDockerComposeFile(Service|Application $resource, bool $isNew = fal
|
|||||||
if (Str::lower($forService) === $serviceName) {
|
if (Str::lower($forService) === $serviceName) {
|
||||||
$fqdn = generateFqdn($server, $containerName);
|
$fqdn = generateFqdn($server, $containerName);
|
||||||
} else {
|
} else {
|
||||||
$fqdn = generateFqdn($server, Str::lower($forService).'-'.$resource->uuid);
|
$fqdn = generateFqdn($server, Str::lower($forService) . '-' . $resource->uuid);
|
||||||
}
|
}
|
||||||
if ($port) {
|
if ($port) {
|
||||||
$fqdn = "$fqdn:$port";
|
$fqdn = "$fqdn:$port";
|
||||||
@@ -2843,7 +2842,7 @@ function parseDockerComposeFile(Service|Application $resource, bool $isNew = fal
|
|||||||
});
|
});
|
||||||
if ($pull_request_id !== 0) {
|
if ($pull_request_id !== 0) {
|
||||||
$services->each(function ($service, $serviceName) use ($pull_request_id, $services) {
|
$services->each(function ($service, $serviceName) use ($pull_request_id, $services) {
|
||||||
$services[$serviceName."-pr-$pull_request_id"] = $service;
|
$services[$serviceName . "-pr-$pull_request_id"] = $service;
|
||||||
data_forget($services, $serviceName);
|
data_forget($services, $serviceName);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -2863,7 +2862,7 @@ function parseDockerComposeFile(Service|Application $resource, bool $isNew = fal
|
|||||||
return collect($finalServices);
|
return collect($finalServices);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function newParser(Application|Service $resource, int $pull_request_id = 0)
|
function newParser(Application|Service $resource, int $pull_request_id = 0, ?int $preview_id = null)
|
||||||
{
|
{
|
||||||
$isApplication = $resource instanceof Application;
|
$isApplication = $resource instanceof Application;
|
||||||
$isService = $resource instanceof Service;
|
$isService = $resource instanceof Service;
|
||||||
@@ -2936,6 +2935,7 @@ function newParser(Application|Service $resource, int $pull_request_id = 0)
|
|||||||
$depends_on = collect(data_get($service, 'depends_on', []));
|
$depends_on = collect(data_get($service, 'depends_on', []));
|
||||||
$labels = collect(data_get($service, 'labels', []));
|
$labels = collect(data_get($service, 'labels', []));
|
||||||
$environment = collect(data_get($service, 'environment', []));
|
$environment = collect(data_get($service, 'environment', []));
|
||||||
|
$ports = collect(data_get($service, 'ports', []));
|
||||||
$buildArgs = collect(data_get($service, 'build.args', []));
|
$buildArgs = collect(data_get($service, 'build.args', []));
|
||||||
$environment = $environment->merge($buildArgs);
|
$environment = $environment->merge($buildArgs);
|
||||||
$isDatabase = isDatabaseImage(data_get_str($service, 'image'));
|
$isDatabase = isDatabaseImage(data_get_str($service, 'image'));
|
||||||
@@ -2947,6 +2947,7 @@ function newParser(Application|Service $resource, int $pull_request_id = 0)
|
|||||||
pull_request_id: $pullRequestId
|
pull_request_id: $pullRequestId
|
||||||
);
|
);
|
||||||
$containerName = "$serviceName-$baseName";
|
$containerName = "$serviceName-$baseName";
|
||||||
|
$predefinedPort = data_get($resource, 'ports_exposes');
|
||||||
} elseif ($isService) {
|
} elseif ($isService) {
|
||||||
$containerName = "$serviceName-{$resource->uuid}";
|
$containerName = "$serviceName-{$resource->uuid}";
|
||||||
|
|
||||||
@@ -2985,6 +2986,9 @@ function newParser(Application|Service $resource, int $pull_request_id = 0)
|
|||||||
$savedService->save();
|
$savedService->save();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$originalResource = $isApplication ? $resource : $savedService;
|
||||||
|
|
||||||
if ($volumes->count() > 0) {
|
if ($volumes->count() > 0) {
|
||||||
foreach ($volumes as $index => $volume) {
|
foreach ($volumes as $index => $volume) {
|
||||||
$type = null;
|
$type = null;
|
||||||
@@ -3039,22 +3043,23 @@ function newParser(Application|Service $resource, int $pull_request_id = 0)
|
|||||||
if ($source->value() === '/tmp' || $source->value() === '/tmp/') {
|
if ($source->value() === '/tmp' || $source->value() === '/tmp/') {
|
||||||
return $volume;
|
return $volume;
|
||||||
}
|
}
|
||||||
$mainDirectory = str(base_configuration_dir().'/applications/'.$uuid);
|
$mainDirectory = str(base_configuration_dir() . '/applications/' . $uuid);
|
||||||
$source = replaceLocalSource($source, $mainDirectory);
|
$source = replaceLocalSource($source, $mainDirectory);
|
||||||
|
|
||||||
|
|
||||||
LocalFileVolume::updateOrCreate(
|
LocalFileVolume::updateOrCreate(
|
||||||
[
|
[
|
||||||
'mount_path' => $target,
|
'mount_path' => $target,
|
||||||
'resource_id' => $savedService->id,
|
'resource_id' => $originalResource->id,
|
||||||
'resource_type' => get_class($savedService),
|
'resource_type' => get_class($originalResource),
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'fs_path' => $source,
|
'fs_path' => $source,
|
||||||
'mount_path' => $target,
|
'mount_path' => $target,
|
||||||
'content' => $content,
|
'content' => $content,
|
||||||
'is_directory' => $isDirectory,
|
'is_directory' => $isDirectory,
|
||||||
'resource_id' => $savedService->id,
|
'resource_id' => $originalResource->id,
|
||||||
'resource_type' => get_class($savedService),
|
'resource_type' => get_class($originalResource),
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
$volume = "$source:$target";
|
$volume = "$source:$target";
|
||||||
@@ -3085,18 +3090,18 @@ function newParser(Application|Service $resource, int $pull_request_id = 0)
|
|||||||
LocalPersistentVolume::updateOrCreate(
|
LocalPersistentVolume::updateOrCreate(
|
||||||
[
|
[
|
||||||
'mount_path' => $target,
|
'mount_path' => $target,
|
||||||
'resource_id' => $savedService->id,
|
'resource_id' => $originalResource->id,
|
||||||
'resource_type' => get_class($savedService),
|
'resource_type' => get_class($originalResource),
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'name' => $name,
|
'name' => $name,
|
||||||
'mount_path' => $target,
|
'mount_path' => $target,
|
||||||
'resource_id' => $savedService->id,
|
'resource_id' => $originalResource->id,
|
||||||
'resource_type' => get_class($savedService),
|
'resource_type' => get_class($originalResource),
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
dispatch(new ServerFilesFromServerJob($savedService));
|
dispatch(new ServerFilesFromServerJob($originalResource));
|
||||||
$volumesParsed->put($index, $volume);
|
$volumesParsed->put($index, $volume);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3128,6 +3133,28 @@ function newParser(Application|Service $resource, int $pull_request_id = 0)
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Collect/create/update ports
|
||||||
|
$collectedPorts = collect([]);
|
||||||
|
if ($ports->count() > 0) {
|
||||||
|
foreach ($ports as $sport) {
|
||||||
|
if (is_string($sport) || is_numeric($sport)) {
|
||||||
|
$collectedPorts->push($sport);
|
||||||
|
}
|
||||||
|
if (is_array($sport)) {
|
||||||
|
$target = data_get($sport, 'target');
|
||||||
|
$published = data_get($sport, 'published');
|
||||||
|
$protocol = data_get($sport, 'protocol');
|
||||||
|
$collectedPorts->push("$target:$published/$protocol");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($isService) {
|
||||||
|
$originalResource->ports = $collectedPorts->implode(',');
|
||||||
|
$originalResource->save();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
$networks_temp = collect();
|
$networks_temp = collect();
|
||||||
|
|
||||||
foreach ($networks as $key => $network) {
|
foreach ($networks as $key => $network) {
|
||||||
@@ -3156,7 +3183,7 @@ function newParser(Application|Service $resource, int $pull_request_id = 0)
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// convert environment variables a different format
|
// convert environment variables to one format
|
||||||
$convertedServiceVariables = collect([]);
|
$convertedServiceVariables = collect([]);
|
||||||
foreach ($environment as $variableName => $variable) {
|
foreach ($environment as $variableName => $variable) {
|
||||||
if (is_numeric($variableName)) {
|
if (is_numeric($variableName)) {
|
||||||
@@ -3184,17 +3211,16 @@ function newParser(Application|Service $resource, int $pull_request_id = 0)
|
|||||||
|
|
||||||
return str($key)->startsWith('SERVICE_') || str($value)->startsWith('SERVICE_');
|
return str($key)->startsWith('SERVICE_') || str($value)->startsWith('SERVICE_');
|
||||||
});
|
});
|
||||||
ray($magicEnvironments);
|
$normalEnvironments = $environment->diffKeys($magicEnvironments);
|
||||||
// TODO: go through all the magic environments and handle all kinds of cases, FQDN, URL, PASSWORD, USER, etc.
|
|
||||||
if ($magicEnvironments->count() > 0) {
|
if ($magicEnvironments->count() > 0) {
|
||||||
foreach ($magicEnvironments as $key => $value) {
|
foreach ($magicEnvironments as $key => $value) {
|
||||||
$key = str($key);
|
$key = str($key);
|
||||||
$value = str($value);
|
$value = str($value);
|
||||||
$command = $key->after('SERVICE_')->before('_');
|
$keyCommand = $key->after('SERVICE_')->before('_');
|
||||||
if ($command->value() === 'FQDN') {
|
$valueCommand = $value->after('SERVICE_')->before('_');
|
||||||
|
if ($keyCommand->value() === 'FQDN') {
|
||||||
if ($isApplication) {
|
if ($isApplication) {
|
||||||
$fqdn = generateFqdn($server, "{$resource->name}-{$uuid}");
|
$fqdn = generateFqdn($server, "{$resource->name}-{$uuid}");
|
||||||
|
|
||||||
} elseif ($isService) {
|
} elseif ($isService) {
|
||||||
$fqdn = generateFqdn($server, "{$savedService->name}-{$uuid}");
|
$fqdn = generateFqdn($server, "{$savedService->name}-{$uuid}");
|
||||||
}
|
}
|
||||||
@@ -3204,7 +3230,32 @@ function newParser(Application|Service $resource, int $pull_request_id = 0)
|
|||||||
} else {
|
} else {
|
||||||
$value = $fqdn;
|
$value = $fqdn;
|
||||||
}
|
}
|
||||||
|
$environment->forget($key);
|
||||||
|
if (!$isDatabase) {
|
||||||
|
if ($isApplication) {
|
||||||
|
$resource->fqdn = $value;
|
||||||
|
$resource->save();
|
||||||
|
} elseif ($isService) {
|
||||||
|
$savedService->fqdn = $value;
|
||||||
|
$savedService->save();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} elseif ($keyCommand->value() === 'URL') {
|
||||||
|
if ($isApplication) {
|
||||||
|
$fqdn = generateFqdn($server, "{$resource->name}-{$uuid}");
|
||||||
|
} elseif ($isService) {
|
||||||
|
$fqdn = generateFqdn($server, "{$savedService->name}-{$uuid}");
|
||||||
|
}
|
||||||
|
$value = str($fqdn)->replace('http://', '')->replace('https://', '')->replace('www.', '');
|
||||||
|
// remove it from environment
|
||||||
|
$environment->forget($key);
|
||||||
|
} else {
|
||||||
|
$generatedValue = generateEnvValue($valueCommand, $resource);
|
||||||
|
if ($generatedValue) {
|
||||||
|
$value = $generatedValue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$resource->environment_variables()->where('key', $key)->where($nameOfId, $resource->id)->firstOrCreate([
|
$resource->environment_variables()->where('key', $key)->where($nameOfId, $resource->id)->firstOrCreate([
|
||||||
'key' => $key,
|
'key' => $key,
|
||||||
$nameOfId => $resource->id,
|
$nameOfId => $resource->id,
|
||||||
@@ -3214,86 +3265,26 @@ function newParser(Application|Service $resource, int $pull_request_id = 0)
|
|||||||
'is_preview' => false,
|
'is_preview' => false,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
foreach ($normalEnvironments as $key => $value) {
|
||||||
foreach ($environment as $key => $value) {
|
|
||||||
if (is_numeric($key)) {
|
|
||||||
if (is_array($value)) {
|
|
||||||
// - SESSION_SECRET: 123
|
|
||||||
// - SESSION_SECRET:
|
|
||||||
$key = str(collect($value)->keys()->first());
|
|
||||||
$value = str(collect($value)->values()->first());
|
|
||||||
} else {
|
|
||||||
$variable = str($value);
|
|
||||||
if ($variable->contains('=')) {
|
|
||||||
// - SESSION_SECRET=123
|
|
||||||
// - SESSION_SECRET=
|
|
||||||
$key = $variable->before('=');
|
|
||||||
$value = $variable->after('=');
|
|
||||||
} else {
|
|
||||||
// - SESSION_SECRET
|
|
||||||
$key = $variable;
|
|
||||||
$value = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// SESSION_SECRET: 123
|
|
||||||
// SESSION_SECRET:
|
|
||||||
$key = str($key);
|
$key = str($key);
|
||||||
$value = str($value);
|
$value = str($value);
|
||||||
}
|
if ($value->startsWith('$')) {
|
||||||
// Auto generate FQDN and URL
|
$value = str(replaceVariables(str($value)));
|
||||||
// environment:
|
if ($value->contains(':-')) {
|
||||||
// - SERVICE_FQDN_UMAMI=/umami
|
$key = $value->before(':');
|
||||||
// - FQDN=$SERVICE_FQDN_UMAMI
|
$value = $value->after(':-');
|
||||||
// - URL=$SERVICE_URL_UMAMI
|
} elseif ($value->contains('-')) {
|
||||||
// - TEST=${TEST:-initial}
|
$key = $value->before('-');
|
||||||
// - HARDCODED=stuff
|
$value = $value->after('-');
|
||||||
if ($value->startsWith('$')) {
|
} elseif ($value->contains(':?')) {
|
||||||
$value = str(replaceVariables($value));
|
$key = $value->before(':');
|
||||||
if ($value->startsWith('SERVICE_')) {
|
$value = $value->after(':?');
|
||||||
$command = $value->after('SERVICE_')->before('_');
|
} elseif ($value->contains('?')) {
|
||||||
if ($command->value() === 'FQDN') {
|
$key = $value->before('?');
|
||||||
if ($magicEnvironments->has($value->value())) {
|
$value = $value->after('?');
|
||||||
$found = $magicEnvironments->get($value->value());
|
|
||||||
if ($found) {
|
|
||||||
$found = $resource->environment_variables()->where('key', $value->value())->where($nameOfId, $resource->id)->first();
|
|
||||||
if ($found) {
|
|
||||||
$value = $found->value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if ($isApplication) {
|
|
||||||
$fqdn = generateFqdn($server, "{$resource->name}-{$uuid}");
|
|
||||||
|
|
||||||
} elseif ($isService) {
|
|
||||||
$fqdn = generateFqdn($server, "{$savedService->name}-{$uuid}");
|
|
||||||
}
|
|
||||||
if ($value && get_class($value) === 'Illuminate\Support\Stringable' && $value->startsWith('/')) {
|
|
||||||
$path = $value->value();
|
|
||||||
$value = "$fqdn$path";
|
|
||||||
} else {
|
|
||||||
$value = $fqdn;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} elseif ($command->value() === 'URL') {
|
|
||||||
if ($magicEnvironments->has($value->value())) {
|
|
||||||
$found = $magicEnvironments->get($value->value());
|
|
||||||
if ($found) {
|
|
||||||
$found = $resource->environment_variables()->where('key', $value->value())->where($nameOfId, $resource->id)->first();
|
|
||||||
if ($found) {
|
|
||||||
$value = $found->value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if ($isApplication) {
|
|
||||||
$fqdn = generateFqdn($server, "{$resource->name}-{$uuid}");
|
|
||||||
} elseif ($isService) {
|
|
||||||
$fqdn = generateFqdn($server, "{$savedService->name}-{$uuid}");
|
|
||||||
}
|
|
||||||
$value = str($fqdn)->replace('http://', '')->replace('https://', '')->replace('www.', '');
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
$value = generateEnvValue($command, $resource);
|
$key = $value;
|
||||||
|
$value = null;
|
||||||
}
|
}
|
||||||
$resource->environment_variables()->where('key', $key)->where($nameOfId, $resource->id)->firstOrCreate([
|
$resource->environment_variables()->where('key', $key)->where($nameOfId, $resource->id)->firstOrCreate([
|
||||||
'key' => $key,
|
'key' => $key,
|
||||||
@@ -3305,13 +3296,132 @@ function newParser(Application|Service $resource, int $pull_request_id = 0)
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Add COOLIFY_CONTAINER_NAME to environment
|
||||||
|
if ($resource->environment_variables->where('key', 'COOLIFY_CONTAINER_NAME')->isEmpty()) {
|
||||||
|
$environment->put('COOLIFY_CONTAINER_NAME', $containerName);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($isApplication) {
|
||||||
|
$domains = collect(json_decode($resource->docker_compose_domains)) ?? collect([]);
|
||||||
|
$fqdns = data_get($domains, "$serviceName.domain");
|
||||||
|
if ($fqdns) {
|
||||||
|
$fqdns = str($fqdns)->explode(',');
|
||||||
|
if ($isPullRequest) {
|
||||||
|
$preview = $resource->previews()->find($preview_id);
|
||||||
|
$docker_compose_domains = collect(json_decode(data_get($preview, 'docker_compose_domains')));
|
||||||
|
if ($docker_compose_domains->count() > 0) {
|
||||||
|
$found_fqdn = data_get($docker_compose_domains, "$serviceName.domain");
|
||||||
|
if ($found_fqdn) {
|
||||||
|
$fqdns = collect($found_fqdn);
|
||||||
|
} else {
|
||||||
|
$fqdns = collect([]);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$fqdns = $fqdns->map(function ($fqdn) use ($pullRequestId) {
|
||||||
|
$preview = ApplicationPreview::findPreviewByApplicationAndPullId($this->id, $pullRequestId);
|
||||||
|
$url = Url::fromString($fqdn);
|
||||||
|
$template = $this->preview_url_template;
|
||||||
|
$host = $url->getHost();
|
||||||
|
$schema = $url->getScheme();
|
||||||
|
$random = new Cuid2;
|
||||||
|
$preview_fqdn = str_replace('{{random}}', $random, $template);
|
||||||
|
$preview_fqdn = str_replace('{{domain}}', $host, $preview_fqdn);
|
||||||
|
$preview_fqdn = str_replace('{{pr_id}}', $pullRequestId, $preview_fqdn);
|
||||||
|
$preview_fqdn = "$schema://$preview_fqdn";
|
||||||
|
$preview->fqdn = $preview_fqdn;
|
||||||
|
$preview->save();
|
||||||
|
|
||||||
|
return $preview_fqdn;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$defaultLabels = defaultLabels(
|
||||||
|
id: $resource->id,
|
||||||
|
name: $containerName,
|
||||||
|
pull_request_id: $pullRequestId,
|
||||||
|
type: 'application'
|
||||||
|
);
|
||||||
|
} elseif ($isService) {
|
||||||
|
if ($savedService->serviceType()) {
|
||||||
|
$fqdns = generateServiceSpecificFqdns($savedService);
|
||||||
|
} else {
|
||||||
|
$fqdns = collect(data_get($savedService, 'fqdns'))->filter();
|
||||||
|
}
|
||||||
|
$defaultLabels = defaultLabels($resource->id, $containerName, type: 'service', subType: $isDatabase ? 'database' : 'application', subId: $savedService->id);
|
||||||
|
}
|
||||||
|
|
||||||
|
$serviceLabels = $labels->merge($defaultLabels);
|
||||||
|
|
||||||
|
if (!$isDatabase && $fqdns->count() > 0) {
|
||||||
|
if ($isApplication) {
|
||||||
|
$shouldGenerateLabelsExactly = $resource->destination->server->settings->generate_exact_labels;
|
||||||
|
} else {
|
||||||
|
$shouldGenerateLabelsExactly = $resource->server->settings->generate_exact_labels;
|
||||||
|
}
|
||||||
|
if ($shouldGenerateLabelsExactly) {
|
||||||
|
switch ($server->proxyType()) {
|
||||||
|
case ProxyTypes::TRAEFIK->value:
|
||||||
|
$serviceLabels = $serviceLabels->merge(fqdnLabelsForTraefik(
|
||||||
|
uuid: $resource->uuid,
|
||||||
|
domains: $fqdns,
|
||||||
|
is_force_https_enabled: true,
|
||||||
|
serviceLabels: $serviceLabels,
|
||||||
|
is_gzip_enabled: $originalResource->isGzipEnabled(),
|
||||||
|
is_stripprefix_enabled: $originalResource->isStripprefixEnabled(),
|
||||||
|
service_name: $serviceName,
|
||||||
|
image: $image
|
||||||
|
));
|
||||||
|
break;
|
||||||
|
case ProxyTypes::CADDY->value:
|
||||||
|
$serviceLabels = $serviceLabels->merge(fqdnLabelsForCaddy(
|
||||||
|
network: $resource->destination->network,
|
||||||
|
uuid: $resource->uuid,
|
||||||
|
domains: $fqdns,
|
||||||
|
is_force_https_enabled: true,
|
||||||
|
serviceLabels: $serviceLabels,
|
||||||
|
is_gzip_enabled: $originalResource->isGzipEnabled(),
|
||||||
|
is_stripprefix_enabled: $originalResource->isStripprefixEnabled(),
|
||||||
|
service_name: $serviceName,
|
||||||
|
image: $image,
|
||||||
|
predefinedPort: $predefinedPort
|
||||||
|
));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$serviceLabels = $serviceLabels->merge(fqdnLabelsForTraefik(
|
||||||
|
uuid: $resource->uuid,
|
||||||
|
domains: $fqdns,
|
||||||
|
is_force_https_enabled: true,
|
||||||
|
serviceLabels: $serviceLabels,
|
||||||
|
is_gzip_enabled: $originalResource->isGzipEnabled(),
|
||||||
|
is_stripprefix_enabled: $originalResource->isStripprefixEnabled(),
|
||||||
|
service_name: $serviceName,
|
||||||
|
image: $image
|
||||||
|
));
|
||||||
|
$serviceLabels = $serviceLabels->merge(fqdnLabelsForCaddy(
|
||||||
|
network: $resource->destination->network,
|
||||||
|
uuid: $resource->uuid,
|
||||||
|
domains: $fqdns,
|
||||||
|
is_force_https_enabled: true,
|
||||||
|
serviceLabels: $serviceLabels,
|
||||||
|
is_gzip_enabled: $originalResource->isGzipEnabled(),
|
||||||
|
is_stripprefix_enabled: $originalResource->isStripprefixEnabled(),
|
||||||
|
service_name: $serviceName,
|
||||||
|
image: $image,
|
||||||
|
predefinedPort: $predefinedPort
|
||||||
|
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$payload = collect($service)->merge([
|
$payload = collect($service)->merge([
|
||||||
'restart' => $restart->value(),
|
'restart' => $restart->value(),
|
||||||
'container_name' => $containerName,
|
'container_name' => $containerName,
|
||||||
'volumes' => $volumesParsed,
|
'volumes' => $volumesParsed,
|
||||||
'networks' => $networks_temp,
|
'networks' => $networks_temp,
|
||||||
'labels' => $labels,
|
'labels' => $serviceLabels,
|
||||||
'environment' => $environment,
|
'environment' => $environment,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
@@ -70,6 +70,11 @@ beforeEach(function () {
|
|||||||
|
|
||||||
$this->application = Application::create([
|
$this->application = Application::create([
|
||||||
'name' => 'Application for tests',
|
'name' => 'Application for tests',
|
||||||
|
'docker_compose_domains' => json_encode([
|
||||||
|
'app' => [
|
||||||
|
'domain' => 'http://bcoowoookw0co4cok4sgc4k8.127.0.0.1.sslip.io',
|
||||||
|
]
|
||||||
|
]),
|
||||||
'uuid' => 'bcoowoookw0co4cok4sgc4k8',
|
'uuid' => 'bcoowoookw0co4cok4sgc4k8',
|
||||||
'repository_project_id' => 603035348,
|
'repository_project_id' => 603035348,
|
||||||
'git_repository' => 'coollabsio/coolify-examples',
|
'git_repository' => 'coollabsio/coolify-examples',
|
||||||
@@ -86,6 +91,7 @@ beforeEach(function () {
|
|||||||
'source_type' => GithubApp::class,
|
'source_type' => GithubApp::class,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
|
||||||
$this->serviceComposeFile = [
|
$this->serviceComposeFile = [
|
||||||
'services' => [
|
'services' => [
|
||||||
'activepieces' => [
|
'activepieces' => [
|
||||||
@@ -356,16 +362,9 @@ afterEach(function () {
|
|||||||
|
|
||||||
test('ServiceComposeParseNew', function () {
|
test('ServiceComposeParseNew', function () {
|
||||||
ray()->clearAll();
|
ray()->clearAll();
|
||||||
$output = $this->service->newParser();
|
$output = newParser($this->application);
|
||||||
// ray('New parser');
|
ray('New parser');
|
||||||
// ray(data_get($output, 'services.activepieces.environment')->toArray());
|
ray($output->toArray());
|
||||||
ray($this->service->environment_variables->pluck('value', 'key')->toArray());
|
|
||||||
// foreach ($this->service->applications as $application) {
|
|
||||||
// ray($application->persistentStorages->pluck('mount_path', 'name')->toArray());
|
|
||||||
// }
|
|
||||||
// foreach ($this->service->databases as $database) {
|
|
||||||
// ray($database->persistentStorages->pluck('mount_path', 'name')->toArray());
|
|
||||||
// }
|
|
||||||
expect($output)->toBeInstanceOf(Collection::class);
|
expect($output)->toBeInstanceOf(Collection::class);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user