fix: if compose file has more that 6 components, force stop

fix: parser
This commit is contained in:
Andras Bacsai
2024-08-28 15:45:11 +02:00
parent 954d82207d
commit 43f2f1ef2b
11 changed files with 1548 additions and 1480 deletions

View File

@@ -19,14 +19,19 @@ class StopService
ray('Stopping service: '.$service->name); ray('Stopping service: '.$service->name);
$applications = $service->applications()->get(); $applications = $service->applications()->get();
foreach ($applications as $application) { foreach ($applications as $application) {
instant_remote_process(command: ["docker stop --time=30 {$application->name}-{$service->uuid}"], server: $server, throwError: false); if ($applications->count() < 6) {
instant_remote_process(command: ["docker stop --time=10 {$application->name}-{$service->uuid}"], server: $server, throwError: false);
}
instant_remote_process(command: ["docker rm {$application->name}-{$service->uuid}"], server: $server, throwError: false); instant_remote_process(command: ["docker rm {$application->name}-{$service->uuid}"], server: $server, throwError: false);
instant_remote_process(command: ["docker rm -f {$application->name}-{$service->uuid}"], server: $server, throwError: false); instant_remote_process(command: ["docker rm -f {$application->name}-{$service->uuid}"], server: $server, throwError: false);
$application->update(['status' => 'exited']); $application->update(['status' => 'exited']);
} }
$dbs = $service->databases()->get(); $dbs = $service->databases()->get();
foreach ($dbs as $db) { foreach ($dbs as $db) {
instant_remote_process(command: ["docker stop --time=30 {$db->name}-{$service->uuid}"], server: $server, throwError: false); if ($dbs->count() < 6) {
instant_remote_process(command: ["docker stop --time=10 {$db->name}-{$service->uuid}"], server: $server, throwError: false);
}
instant_remote_process(command: ["docker rm {$db->name}-{$service->uuid}"], server: $server, throwError: false); instant_remote_process(command: ["docker rm {$db->name}-{$service->uuid}"], server: $server, throwError: false);
instant_remote_process(command: ["docker rm -f {$db->name}-{$service->uuid}"], server: $server, throwError: false); instant_remote_process(command: ["docker rm -f {$db->name}-{$service->uuid}"], server: $server, throwError: false);
$db->update(['status' => 'exited']); $db->update(['status' => 'exited']);

View File

@@ -91,18 +91,16 @@ class Create extends Component
$oneClickDotEnvs->each(function ($value) use ($service) { $oneClickDotEnvs->each(function ($value) use ($service) {
$key = str()->before($value, '='); $key = str()->before($value, '=');
$value = str(str()->after($value, '=')); $value = str(str()->after($value, '='));
$generatedValue = $value; if ($value) {
if ($value->contains('SERVICE_')) {
$command = $value->after('SERVICE_')->beforeLast('_');
$generatedValue = generateEnvValue($command->value(), $service);
}
EnvironmentVariable::create([ EnvironmentVariable::create([
'key' => $key, 'key' => $key,
'value' => $generatedValue, 'value' => $value,
'service_id' => $service->id, 'service_id' => $service->id,
'is_build_time' => false, 'is_build_time' => false,
'is_preview' => false, 'is_preview' => false,
]); ]);
}
}); });
} }
$service->parse(isNew: true); $service->parse(isNew: true);

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -146,7 +146,6 @@ function generate_default_proxy_configuration(Server $server)
'coolify.managed=true', 'coolify.managed=true',
]; ];
$config = [ $config = [
'version' => '3.8',
'networks' => $array_of_networks->toArray(), 'networks' => $array_of_networks->toArray(),
'services' => [ 'services' => [
'traefik' => [ 'traefik' => [

View File

@@ -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;
} }
@@ -981,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) {
@@ -991,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;
@@ -1039,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('/');
@@ -1066,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('/');
@@ -1116,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('/');
@@ -1135,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('/');
@@ -1178,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;
@@ -1209,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();
@@ -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";
@@ -1990,7 +1990,6 @@ function parseDockerComposeFile(Service|Application $resource, bool $isNew = fal
} else { } else {
$fqdns = collect(data_get($savedService, 'fqdns'))->filter(); $fqdns = collect(data_get($savedService, 'fqdns'))->filter();
} }
ray($savedService);
$defaultLabels = defaultLabels($resource->id, $containerName, type: 'service', subType: $isDatabase ? 'database' : 'application', subId: $savedService->id); $defaultLabels = defaultLabels($resource->id, $containerName, type: 'service', subType: $isDatabase ? 'database' : 'application', subId: $savedService->id);
$serviceLabels = $serviceLabels->merge($defaultLabels); $serviceLabels = $serviceLabels->merge($defaultLabels);
if (! $isDatabase && $fqdns->count() > 0) { if (! $isDatabase && $fqdns->count() > 0) {
@@ -2214,7 +2213,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);
} }
@@ -2222,12 +2221,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);
@@ -2266,7 +2265,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");
} }
@@ -2277,7 +2276,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);
} }
@@ -2285,21 +2284,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)) {
@@ -2338,7 +2337,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);
} }
@@ -2346,13 +2345,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);
@@ -2371,7 +2370,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());
@@ -2394,7 +2393,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");
} }
@@ -2406,7 +2405,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);
} }
@@ -2414,20 +2413,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)) {
@@ -2462,7 +2461,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());
} }
@@ -2505,7 +2504,7 @@ function parseDockerComposeFile(Service|Application $resource, bool $isNew = fal
} }
} }
if ($collectedPorts->count() > 0) { if ($collectedPorts->count() > 0) {
// ray($collectedPorts->implode(',')); ray($collectedPorts->implode(','));
} }
$definedNetworkExists = $topLevelNetworks->contains(function ($value, $_) use ($definedNetwork) { $definedNetworkExists = $topLevelNetworks->contains(function ($value, $_) use ($definedNetwork) {
return $value == $definedNetwork; return $value == $definedNetwork;
@@ -2633,7 +2632,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";
@@ -2842,7 +2841,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);
}); });
} }
@@ -2862,13 +2861,16 @@ function parseDockerComposeFile(Service|Application $resource, bool $isNew = fal
return collect($finalServices); return collect($finalServices);
} }
} }
function newParser(Application|Service $resource, int $pull_request_id = 0, ?int $preview_id = null) function newParser(Application|Service $resource, int $pull_request_id = 0, ?int $preview_id = null): Collection
{ {
$isApplication = $resource instanceof Application; $isApplication = $resource instanceof Application;
$isService = $resource instanceof Service; $isService = $resource instanceof Service;
$uuid = data_get($resource, 'uuid'); $uuid = data_get($resource, 'uuid');
$compose = data_get($resource, 'docker_compose_raw'); $compose = data_get($resource, 'docker_compose_raw');
if (! $compose) {
return collect([]);
}
if ($isApplication) { if ($isApplication) {
$nameOfId = 'application_id'; $nameOfId = 'application_id';
@@ -2881,13 +2883,13 @@ function newParser(Application|Service $resource, int $pull_request_id = 0, ?int
$server = data_get($resource, 'server'); $server = data_get($resource, 'server');
$allServices = get_service_templates(); $allServices = get_service_templates();
} else { } else {
return; return collect([]);
} }
try { try {
$yaml = Yaml::parse($compose); $yaml = Yaml::parse($compose);
} catch (\Exception $e) { } catch (\Exception $e) {
return; return collect([]);
} }
$services = data_get($yaml, 'services', collect([])); $services = data_get($yaml, 'services', collect([]));
@@ -2947,7 +2949,7 @@ function newParser(Application|Service $resource, int $pull_request_id = 0, ?int
pull_request_id: $pullRequestId pull_request_id: $pullRequestId
); );
$containerName = "$serviceName-$baseName"; $containerName = "$serviceName-$baseName";
$predefinedPort = data_get($resource, 'ports_exposes'); $predefinedPort = null;
} elseif ($isService) { } elseif ($isService) {
$containerName = "$serviceName-{$resource->uuid}"; $containerName = "$serviceName-{$resource->uuid}";
@@ -3038,15 +3040,13 @@ function newParser(Application|Service $resource, int $pull_request_id = 0, ?int
} }
if ($type->value() === 'bind') { if ($type->value() === 'bind') {
if ($source->value() === '/var/run/docker.sock') { if ($source->value() === '/var/run/docker.sock') {
return $volume; $volume = $source->value().':'.$target->value();
} } elseif ($source->value() === '/tmp' || $source->value() === '/tmp/') {
if ($source->value() === '/tmp' || $source->value() === '/tmp/') { $volume = $source->value().':'.$target->value();
return $volume; } else {
} $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,
@@ -3063,6 +3063,7 @@ function newParser(Application|Service $resource, int $pull_request_id = 0, ?int
] ]
); );
$volume = "$source:$target"; $volume = "$source:$target";
}
} elseif ($type->value() === 'volume') { } elseif ($type->value() === 'volume') {
if ($topLevel->get('volumes')->has($source->value())) { if ($topLevel->get('volumes')->has($source->value())) {
$temp = $topLevel->get('volumes')->get($source->value()); $temp = $topLevel->get('volumes')->get($source->value());
@@ -3154,7 +3155,6 @@ function newParser(Application|Service $resource, int $pull_request_id = 0, ?int
$originalResource->save(); $originalResource->save();
} }
$networks_temp = collect(); $networks_temp = collect();
foreach ($networks as $key => $network) { foreach ($networks as $key => $network) {
@@ -3184,27 +3184,7 @@ function newParser(Application|Service $resource, int $pull_request_id = 0, ?int
} }
} }
// convert environment variables to one format // convert environment variables to one format
$convertedServiceVariables = collect([]); $environment = convertComposeEnvironmentToArray($environment);
foreach ($environment as $variableName => $variable) {
if (is_numeric($variableName)) {
if (is_array($variable)) {
$key = str(collect($variable)->keys()->first());
$value = str(collect($variable)->values()->first());
$variable = "$key=$value";
$convertedServiceVariables->put($variableName, $variable);
} elseif (is_string($variable)) {
if (is_numeric($variableName)) {
$convertedServiceVariables->put($variable, null);
} else {
$convertedServiceVariables->put($variableName, $variable);
}
}
} elseif (is_string($variableName)) {
$convertedServiceVariables->put($variableName, $variable);
}
}
$environment = $convertedServiceVariables;
// filter magic environments // filter magic environments
$magicEnvironments = $environment->filter(function ($value, $key) { $magicEnvironments = $environment->filter(function ($value, $key) {
$value = str(replaceVariables(str($value))); $value = str(replaceVariables(str($value)));
@@ -3215,10 +3195,58 @@ function newParser(Application|Service $resource, int $pull_request_id = 0, ?int
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(replaceVariables(str($value)));
$originalValue = $value;
$keyCommand = $key->after('SERVICE_')->before('_'); $keyCommand = $key->after('SERVICE_')->before('_');
$valueCommand = $value->after('SERVICE_')->before('_'); $valueCommand = $value->after('SERVICE_')->before('_');
if ($keyCommand->value() === 'FQDN') { if ($key->startsWith('SERVICE_FQDN_')) {
$fqdnFor = $key->after('SERVICE_FQDN_')->lower()->value();
if (str($fqdnFor)->contains('_')) {
$fqdnFor = str($fqdnFor)->before('_');
}
} elseif ($value->startsWith('SERVICE_FQDN_')) {
$fqdnFor = $value->after('SERVICE_FQDN_')->lower()->value();
if (str($fqdnFor)->contains('_')) {
$fqdnFor = str($fqdnFor)->before('_');
}
} else {
$fqdnFor = null;
}
if ($keyCommand->value() === 'FQDN' || $valueCommand->value() === 'FQDN') {
if ($isApplication) {
$fqdn = generateFqdn($server, "{$resource->name}-$uuid");
} elseif ($isService) {
if ($fqdnFor) {
$fqdn = generateFqdn($server, "$fqdnFor-$uuid");
} else {
$fqdn = generateFqdn($server, "{$savedService->name}-$uuid");
}
}
if ($value && get_class($value) === 'Illuminate\Support\Stringable' && $value->startsWith('/')) {
$path = $value->value();
if ($value === '/') {
$value = "$fqdn";
} else {
$value = "$fqdn$path";
}
} else {
$value = $fqdn;
}
if (! $isDatabase) {
if ($isApplication && is_null($resource->fqdn)) {
data_forget($resource, 'environment_variables');
data_forget($resource, 'environment_variables_preview');
$resource->fqdn = $value;
$resource->save();
} elseif ($isService && is_null($savedService->fqdn)) {
if ($key->startsWith('SERVICE_FQDN_')) {
$savedService->fqdn = $value;
$savedService->save();
}
}
}
} elseif ($keyCommand->value() === 'URL' || $valueCommand->value() === 'URL') {
if ($isApplication) { if ($isApplication) {
$fqdn = generateFqdn($server, "{$resource->name}-{$uuid}"); $fqdn = generateFqdn($server, "{$resource->name}-{$uuid}");
} elseif ($isService) { } elseif ($isService) {
@@ -3230,34 +3258,23 @@ function newParser(Application|Service $resource, int $pull_request_id = 0, ?int
} 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.', ''); $value = str($fqdn)->replace('http://', '')->replace('https://', '')->replace('www.', '');
// remove it from environment
$environment->forget($key);
} else { } else {
$generatedValue = generateEnvValue($valueCommand, $resource); $generatedValue = generateEnvValue($valueCommand, $resource);
if ($generatedValue) { if ($generatedValue) {
$value = $generatedValue; $value = $generatedValue;
} }
} }
if (str($fqdnFor)->startsWith('/')) {
$resource->environment_variables()->where('key', $key)->where($nameOfId, $resource->id)->firstOrCreate([ $fqdnFor = null;
'key' => $key, }
// Lets save the magic value to the environment variables
if (! $originalValue->startsWith('/')) {
if ($key->startsWith('SERVICE_')) {
$originalValue = $key;
}
$resource->environment_variables()->where('key', $originalValue->value())->where($nameOfId, $resource->id)->firstOrCreate([
'key' => $originalValue->value(),
$nameOfId => $resource->id, $nameOfId => $resource->id,
], [ ], [
'value' => $value, 'value' => $value,
@@ -3265,6 +3282,20 @@ function newParser(Application|Service $resource, int $pull_request_id = 0, ?int
'is_preview' => false, 'is_preview' => false,
]); ]);
} }
// Save the original value to the environment variables
if ($originalValue->startsWith('SERVICE_')) {
$value = "$$originalValue";
}
$resource->environment_variables()->where('key', $key->value())->where($nameOfId, $resource->id)->firstOrCreate([
'key' => $key->value(),
$nameOfId => $resource->id,
], [
'value' => "$value",
'is_build_time' => false,
'is_preview' => false,
]);
}
}
foreach ($normalEnvironments as $key => $value) { foreach ($normalEnvironments as $key => $value) {
$key = str($key); $key = str($key);
$value = str($value); $value = str($value);
@@ -3353,7 +3384,7 @@ function newParser(Application|Service $resource, int $pull_request_id = 0, ?int
$serviceLabels = $labels->merge($defaultLabels); $serviceLabels = $labels->merge($defaultLabels);
if (!$isDatabase && $fqdns->count() > 0) { if (! $isDatabase && $fqdns?->count() > 0) {
if ($isApplication) { if ($isApplication) {
$shouldGenerateLabelsExactly = $resource->destination->server->settings->generate_exact_labels; $shouldGenerateLabelsExactly = $resource->destination->server->settings->generate_exact_labels;
} else { } else {
@@ -3414,17 +3445,28 @@ function newParser(Application|Service $resource, int $pull_request_id = 0, ?int
)); ));
} }
} }
if ($isService) {
if (data_get($service, 'restart') === 'no' || data_get($service, 'exclude_from_hc')) {
$savedService->update(['exclude_from_status' => true]);
} }
}
data_forget($service, 'volumes.*.content');
data_forget($service, 'volumes.*.isDirectory');
data_forget($service, 'volumes.*.is_directory');
data_forget($service, 'exclude_from_hc');
$payload = collect($service)->merge([ $payload = collect($service)->merge([
'restart' => $restart->value(),
'container_name' => $containerName, 'container_name' => $containerName,
'volumes' => $volumesParsed, 'restart' => $restart->value(),
'networks' => $networks_temp, 'networks' => $networks_temp,
'labels' => $serviceLabels, 'labels' => $serviceLabels,
'environment' => $environment,
]); ]);
if ($volumesParsed->count() > 0) {
$payload['volumes'] = $volumesParsed;
}
if ($environment->count() > 0) {
$payload['environment'] = $environment;
}
if ($logging) { if ($logging) {
$payload['logging'] = $logging; $payload['logging'] = $logging;
} }
@@ -3434,6 +3476,7 @@ function newParser(Application|Service $resource, int $pull_request_id = 0, ?int
if ($isApplication && $isPullRequest) { if ($isApplication && $isPullRequest) {
$serviceName = "{$serviceName}-pr-{$pullRequestId}"; $serviceName = "{$serviceName}-pr-{$pullRequestId}";
} }
$parsedServices->put($serviceName, $payload); $parsedServices->put($serviceName, $payload);
} }
$topLevel->put('services', $parsedServices); $topLevel->put('services', $parsedServices);
@@ -3442,6 +3485,7 @@ function newParser(Application|Service $resource, int $pull_request_id = 0, ?int
$topLevel = $topLevel->sortBy(function ($value, $key) use ($customOrder) { $topLevel = $topLevel->sortBy(function ($value, $key) use ($customOrder) {
return array_search($key, $customOrder); return array_search($key, $customOrder);
}); });
$resource->docker_compose = Yaml::dump(convertToArray($topLevel), 10, 2); $resource->docker_compose = Yaml::dump(convertToArray($topLevel), 10, 2);
data_forget($resource, 'environment_variables'); data_forget($resource, 'environment_variables');
data_forget($resource, 'environment_variables_preview'); data_forget($resource, 'environment_variables_preview');
@@ -3449,3 +3493,34 @@ function newParser(Application|Service $resource, int $pull_request_id = 0, ?int
return $topLevel; return $topLevel;
} }
function convertComposeEnvironmentToArray($environment)
{
$convertedServiceVariables = collect([]);
foreach ($environment as $variableName => $variableValue) {
if (is_array($variableValue)) {
$key = str(collect($variableValue)->keys()->first());
$value = str(collect($variableValue)->values()->first());
} elseif (is_string($variableValue)) {
if (str($variableValue)->contains('=')) {
$key = str($variableValue)->before('=');
$value = str($variableValue)->after('=');
} else {
if (is_numeric($variableName)) {
$key = str($variableValue);
$value = null;
} else {
$key = str($variableName);
if ($variableValue) {
$value = str($variableValue);
} else {
$value = null;
}
}
}
}
$convertedServiceVariables->put($key->value(), $value?->value() ?? null);
}
return $convertedServiceVariables;
}

View File

@@ -8,6 +8,7 @@ services:
activepieces: activepieces:
image: "ghcr.io/activepieces/activepieces:latest" image: "ghcr.io/activepieces/activepieces:latest"
environment: environment:
- SERVICE_FQDN_ACTIVEPIECES
- AP_API_KEY=$SERVICE_PASSWORD_64_APIKEY - AP_API_KEY=$SERVICE_PASSWORD_64_APIKEY
- AP_ENCRYPTION_KEY=$SERVICE_PASSWORD_ENCRYPTIONKEY - AP_ENCRYPTION_KEY=$SERVICE_PASSWORD_ENCRYPTIONKEY
- AP_ENGINE_EXECUTABLE_PATH=dist/packages/engine/main.js - AP_ENGINE_EXECUTABLE_PATH=dist/packages/engine/main.js

View File

@@ -3,9 +3,6 @@ _APP_LOCALE=en
_APP_OPTIONS_ABUSE=enabled _APP_OPTIONS_ABUSE=enabled
_APP_OPTIONS_FORCE_HTTPS=disabled _APP_OPTIONS_FORCE_HTTPS=disabled
_APP_OPENSSL_KEY_V1= _APP_OPENSSL_KEY_V1=
_APP_DOMAIN=
_APP_DOMAIN_TARGET=
_APP_DOMAIN_FUNCTIONS=
_APP_CONSOLE_WHITELIST_ROOT=enabled _APP_CONSOLE_WHITELIST_ROOT=enabled
_APP_CONSOLE_WHITELIST_EMAILS= _APP_CONSOLE_WHITELIST_EMAILS=
_APP_CONSOLE_WHITELIST_IPS= _APP_CONSOLE_WHITELIST_IPS=
@@ -28,9 +25,6 @@ _APP_REDIS_PASS=
_APP_DB_HOST=appwrite-mariadb _APP_DB_HOST=appwrite-mariadb
_APP_DB_PORT=3306 _APP_DB_PORT=3306
_APP_DB_SCHEMA=appwrite _APP_DB_SCHEMA=appwrite
_APP_DB_USER=$SERVICE_USER_MYSQL
_APP_DB_PASS=$SERVICE_PASSWORD_MYSQL
_APP_DB_ROOT_PASS=$SERVICE_PASSWORD_ROOTMYSQL
_APP_SMTP_HOST= _APP_SMTP_HOST=
_APP_SMTP_PORT= _APP_SMTP_PORT=
_APP_SMTP_SECURE= _APP_SMTP_SECURE=
@@ -72,7 +66,6 @@ _APP_FUNCTIONS_CPUS=0
_APP_FUNCTIONS_MEMORY=0 _APP_FUNCTIONS_MEMORY=0
_APP_FUNCTIONS_MEMORY_SWAP=0 _APP_FUNCTIONS_MEMORY_SWAP=0
_APP_FUNCTIONS_RUNTIMES=node-20.0,php-8.2,python-3.11,ruby-3.2 _APP_FUNCTIONS_RUNTIMES=node-20.0,php-8.2,python-3.11,ruby-3.2
_APP_EXECUTOR_SECRET=$SERVICE_PASSWORD_64_APPWRITE
_APP_EXECUTOR_HOST=http://appwrite-executor/v1 _APP_EXECUTOR_HOST=http://appwrite-executor/v1
_APP_EXECUTOR_RUNTIME_NETWORK=appwrite_runtimes _APP_EXECUTOR_RUNTIME_NETWORK=appwrite_runtimes
_APP_FUNCTIONS_INACTIVE_THRESHOLD=60 _APP_FUNCTIONS_INACTIVE_THRESHOLD=60

View File

@@ -52,8 +52,9 @@ services:
- _APP_DB_HOST - _APP_DB_HOST
- _APP_DB_PORT - _APP_DB_PORT
- _APP_DB_SCHEMA - _APP_DB_SCHEMA
- _APP_DB_USER - _APP_DB_USER=$SERVICE_USER_MARIADB
- _APP_DB_PASS - _APP_DB_PASS=$SERVICE_PASSWORD_MARIADB
- _APP_DB_ROOT_PASS=$SERVICE_PASSWORD_MARIADBROOT
- _APP_SMTP_HOST - _APP_SMTP_HOST
- _APP_SMTP_PORT - _APP_SMTP_PORT
- _APP_SMTP_SECURE - _APP_SMTP_SECURE
@@ -92,7 +93,7 @@ services:
- _APP_FUNCTIONS_CPUS - _APP_FUNCTIONS_CPUS
- _APP_FUNCTIONS_MEMORY - _APP_FUNCTIONS_MEMORY
- _APP_FUNCTIONS_RUNTIMES - _APP_FUNCTIONS_RUNTIMES
- _APP_EXECUTOR_SECRET - _APP_EXECUTOR_SECRET=$SERVICE_PASSWORD_64_APPWRITE
- _APP_EXECUTOR_HOST - _APP_EXECUTOR_HOST
- _APP_LOGGING_PROVIDER - _APP_LOGGING_PROVIDER
- _APP_LOGGING_CONFIG - _APP_LOGGING_CONFIG
@@ -500,7 +501,7 @@ services:
- _APP_MAINTENANCE_RETENTION_SCHEDULES - _APP_MAINTENANCE_RETENTION_SCHEDULES
appwrite-worker-usage: appwrite-worker-usage:
image: appwrite/appwrite:1.5.1 image: appwrite/appwrite:1.5
entrypoint: worker-usage entrypoint: worker-usage
container_name: appwrite-worker-usage container_name: appwrite-worker-usage
<<: *x-logging <<: *x-logging
@@ -527,7 +528,7 @@ services:
- _APP_USAGE_AGGREGATION_INTERVAL - _APP_USAGE_AGGREGATION_INTERVAL
appwrite-worker-usage-dump: appwrite-worker-usage-dump:
image: appwrite/appwrite:1.5.1 image: appwrite/appwrite:1.5
entrypoint: worker-usage-dump entrypoint: worker-usage-dump
<<: *x-logging <<: *x-logging
container_name: appwrite-worker-usage-dump container_name: appwrite-worker-usage-dump

File diff suppressed because one or more lines are too long

View File

@@ -11,69 +11,56 @@ use Visus\Cuid2\Cuid2;
ray()->clearAll(); ray()->clearAll();
beforeEach(function () { beforeEach(function () {
$this->applicationComposeFile = [ $this->applicationYaml = '
'version' => '3.8', version: "3.8"
'services' => [ services:
'app' => [ app:
'image' => 'nginx', image: nginx
'environment' => [ environment:
'SERVICE_FQDN_APP' => '/app', SERVICE_FQDN_APP: /app
'APP_KEY' => 'base64', APP_KEY: base64
'APP_DEBUG' => '${APP_DEBUG:-false}', APP_DEBUG: "${APP_DEBUG:-false}"
'APP_URL' => '$SERVICE_FQDN_APP', APP_URL: $SERVICE_FQDN_APP
], volumes:
'volumes' => [ - "./nginx:/etc/nginx"
'./nginx:/etc/nginx', - "data:/var/www/html"
'data:/var/www/html', depends_on:
], - db
'depends_on' => [ db:
'db', image: postgres
], environment:
], POSTGRES_USER: "${POSTGRES_USER:-postgres}"
'db' => [ POSTGRES_PASSWORD: "${POSTGRES_PASSWORD:-postgres}"
'image' => 'postgres', volumes:
'environment' => [ - "dbdata:/var/lib/postgresql/data"
'POSTGRES_USER' => '${POSTGRES_USER:-postgres}', healthcheck:
'POSTGRES_PASSWORD' => '${POSTGRES_PASSWORD:-postgres}', test:
], - CMD
'volumes' => [ - pg_isready
'dbdata:/var/lib/postgresql/data', - "-U"
], - "postgres"
'healthcheck' => [ interval: 2s
'test' => ['CMD', 'pg_isready', '-U', 'postgres'], timeout: 10s
'interval' => '2s', retries: 10
'timeout' => '10s', depends_on:
'retries' => 10, app:
], condition: service_healthy
'depends_on' => [ networks:
'app' => [ default:
'condition' => 'service_healthy', name: something
], external: true
], noinet:
driver: bridge
internal: true';
], $this->applicationComposeFileString = Yaml::parse($this->applicationYaml);
],
'networks' => [
'default' => [
'name' => 'something',
'external' => true,
],
'noinet' => [
'driver' => 'bridge',
'internal' => true,
],
],
];
$this->applicationComposeFileString = Yaml::dump($this->applicationComposeFile, 10, 2);
$this->jsonapplicationComposeFile = json_encode($this->applicationComposeFile, JSON_PRETTY_PRINT | JSON_THROW_ON_ERROR);
$this->application = Application::create([ $this->application = Application::create([
'name' => 'Application for tests', 'name' => 'Application for tests',
'docker_compose_domains' => json_encode([ 'docker_compose_domains' => json_encode([
'app' => [ 'app' => [
'domain' => 'http://bcoowoookw0co4cok4sgc4k8.127.0.0.1.sslip.io', 'domain' => 'http://bcoowoookw0co4cok4sgc4k8.127.0.0.1.sslip.io',
] ],
]), ]),
'uuid' => 'bcoowoookw0co4cok4sgc4k8', 'uuid' => 'bcoowoookw0co4cok4sgc4k8',
'repository_project_id' => 603035348, 'repository_project_id' => 603035348,
@@ -81,7 +68,7 @@ beforeEach(function () {
'git_branch' => 'main', 'git_branch' => 'main',
'base_directory' => '/docker-compose-test', 'base_directory' => '/docker-compose-test',
'docker_compose_location' => 'docker-compose.yml', 'docker_compose_location' => 'docker-compose.yml',
'docker_compose_raw' => $this->applicationComposeFileString, 'docker_compose_raw' => $this->applicationYaml,
'build_pack' => 'dockercompose', 'build_pack' => 'dockercompose',
'ports_exposes' => '3000', 'ports_exposes' => '3000',
'environment_id' => 1, 'environment_id' => 1,
@@ -90,101 +77,77 @@ beforeEach(function () {
'source_id' => 1, 'source_id' => 1,
'source_type' => GithubApp::class, 'source_type' => GithubApp::class,
]); ]);
$this->serviceYaml = '
version: "3.8"
services:
activepieces:
image: ghcr.io/activepieces/activepieces:latest
environment:
- SERVICE_FQDN_ACTIVEPIECES
- AP_ENCRYPTION_KEY=$SERVICE_PASSWORD_ENCRYPTIONKEY
- AP_EXECUTION_MODE=UNSANDBOXED
- AP_FRONTEND_URL=$SERVICE_FQDN_ACTIVEPIECES
- AP_TEST=${AP_TEST:-test}
volumes:
- "dbdata:/var/lib/postgresql/data"
depends_on:
- postgres
- redis
activepieces2:
image: ghcr.io/activepieces/activepieces:latest
environment:
TEST: $SERVICE_FQDN_ACTIVEPIECES
volumes:
- "dbdata:/var/lib/postgresql/data"
depends_on:
- postgres
- redis
postgres:
image: postgres:latest
environment:
POSTGRES_DB: activepieces
POSTGRES_USER: $SERVICE_USER_POSTGRES
POSTGRES_PASSWORD: $SERVICE_PASSWORD_POSTGRES
volumes:
- "dbdata:/var/lib/postgresql/data"
healthcheck:
test:
- CMD
- pg_isready
- "-U"
- "postgres"
interval: 2s
timeout: 10s
retries: 10
redis:
image: redis:latest
volumes:
- "redis_data:/data"
healthcheck:
test:
- CMD
- redis-cli
- ping
interval: 2s
timeout: 10s
retries: 10
volumes:
dbdata:
redis_data:
networks:
default:
name: something
external: true
noinet:
driver: bridge
internal: true';
$this->serviceComposeFileString = Yaml::parse($this->serviceYaml);
$this->serviceComposeFile = [
'services' => [
'activepieces' => [
'image' => 'ghcr.io/activepieces/activepieces:latest',
'environment' => [
'SERVICE_FQDN_ACTIVEPIECES_80' => '/app',
'AP_API_KEY' => '$SERVICE_PASSWORD_64_APIKEY',
'AP_ENCRYPTION_KEY' => '$SERVICE_PASSWORD_ENCRYPTIONKEY',
'AP_ENGINE_EXECUTABLE_PATH' => 'dist/packages/engine/main.js',
'AP_ENVIRONMENT' => 'prod',
'AP_EXECUTION_MODE' => 'UNSANDBOXED',
'AP_FRONTEND_URL' => '$SERVICE_FQDN_ACTIVEPIECES',
'AP_JWT_SECRET' => '$SERVICE_PASSWORD_64_JWT',
'AP_POSTGRES_DATABASE' => 'activepieces',
'AP_POSTGRES_HOST' => 'postgres',
'AP_POSTGRES_PASSWORD' => '$SERVICE_PASSWORD_POSTGRES',
'AP_POSTGRES_PORT' => '5432',
'AP_POSTGRES_USERNAME' => '$SERVICE_USER_POSTGRES',
'AP_REDIS_HOST' => 'redis',
'AP_REDIS_PORT' => '6379',
'AP_SANDBOX_RUN_TIME_SECONDS' => '600',
'AP_TELEMETRY_ENABLED' => 'true',
'AP_TEMPLATES_SOURCE_URL' => 'https://cloud.activepieces.com/api/v1/flow-templates',
'AP_TRIGGER_DEFAULT_POLL_INTERVAL' => '5',
'AP_WEBHOOK_TIMEOUT_SECONDS' => '30',
'AP_TEST' => '${AP_TEST:-test}',
],
'depends_on' => [
'postgres' => [
'condition' => 'service_healthy',
],
'redis' => [
'condition' => 'service_started',
],
],
'healthcheck' => [
'test' => [
'CMD',
'curl',
'-f',
'http://127.0.0.1:80',
],
'interval' => '5s',
'timeout' => '20s',
'retries' => 10,
],
],
'postgres' => [
'image' => 'postgres:latest',
'environment' => [
'POSTGRES_DB' => 'activepieces',
'POSTGRES_PASSWORD' => '$SERVICE_PASSWORD_POSTGRES',
'POSTGRES_USER' => '$SERVICE_USER_POSTGRES',
],
'volumes' => [
'dbdata:/var/lib/postgresql/data',
],
'healthcheck' => [
'test' => [
'CMD-SHELL',
'pg_isready -U $${POSTGRES_USER} -d $${POSTGRES_DB}',
],
'interval' => '5s',
'timeout' => '20s',
'retries' => 10,
],
],
'redis' => [
'image' => 'redis:latest',
'volumes' => [
'redis_data:/data',
],
'healthcheck' => [
'test' => [
'CMD',
'redis-cli',
'ping',
],
'interval' => '5s',
'timeout' => '20s',
'retries' => 10,
],
],
],
];
$this->serviceComposeFileString = Yaml::dump($this->serviceComposeFile, 10, 2);
$this->jsonServiceComposeFile = json_encode($this->serviceComposeFile, JSON_PRETTY_PRINT | JSON_THROW_ON_ERROR);
$this->service = Service::create([ $this->service = Service::create([
'name' => 'Service for tests', 'name' => 'Service for tests',
'uuid' => (string) new Cuid2(), 'uuid' => (string) new Cuid2(),
'docker_compose_raw' => $this->serviceComposeFileString, 'docker_compose_raw' => $this->serviceYaml,
'environment_id' => 1, 'environment_id' => 1,
'server_id' => 0, 'server_id' => 0,
'destination_id' => 0, 'destination_id' => 0,
@@ -362,23 +325,24 @@ afterEach(function () {
test('ServiceComposeParseNew', function () { test('ServiceComposeParseNew', function () {
ray()->clearAll(); ray()->clearAll();
$output = newParser($this->application); $output = newParser($this->service);
ray('New parser'); // ray('New parser');
ray($output->toArray()); // ray($output->toArray());
ray($this->service->environment_variables->pluck('value', 'key')->toArray());
expect($output)->toBeInstanceOf(Collection::class); expect($output)->toBeInstanceOf(Collection::class);
}); });
// test('ServiceComposeParseOld', function () { // test('ServiceComposeParseOld', function () {
// $output = parseDockerComposeFile($this->service); // $output = parseDockerComposeFile($this->service);
// ray('Old parser'); // ray('Old parser');
// ray($output->toArray()); // // ray($output->toArray());
// ray($this->service->environment_variables->pluck('value', 'key')->toArray()); // // ray($this->service->environment_variables->pluck('value', 'key')->toArray());
// foreach ($this->service->applications as $application) { // // foreach ($this->service->applications as $application) {
// ray($application->persistentStorages->pluck('mount_path', 'name')->toArray()); // // ray($application->persistentStorages->pluck('mount_path', 'name')->toArray());
// } // // }
// foreach ($this->service->databases as $database) { // // foreach ($this->service->databases as $database) {
// ray($database->persistentStorages->pluck('mount_path', 'name')->toArray()); // // ray($database->persistentStorages->pluck('mount_path', 'name')->toArray());
// } // // }
// expect($output)->toBeInstanceOf(Collection::class); // expect($output)->toBeInstanceOf(Collection::class);
// }); // });
@@ -387,3 +351,30 @@ test('ServiceComposeParseNew', function () {
// $output = instant_remote_process(['docker --version'], $server); // $output = instant_remote_process(['docker --version'], $server);
// expect($output)->toContain('Docker version'); // expect($output)->toContain('Docker version');
// }); // });
// test('ConvertComposeEnvironmentToArray', function () {
// ray()->clearAll();
// $yaml = '
// services:
// activepieces:
// environment:
// - SERVICE_FQDN_ACTIVEPIECES=/app
// - AP_API_KEY=$SERVICE_PASSWORD_64_APIKEY
// activepieces2:
// environment:
// - SERVICE_FQDN_ACTIVEPIECES=/v1/realtime
// postgres:
// environment:
// - POSTGRES_DB: activepieces
// ';
// $parsedYaml = Yaml::parse($yaml);
// $output = convertComposeEnvironmentToArray($parsedYaml['services']['activepieces']['environment']);
// $output2 = convertComposeEnvironmentToArray($parsedYaml['services']['activepieces2']['environment']);
// $dboutput = convertComposeEnvironmentToArray($parsedYaml['services']['postgres']['environment']);
// ray($output);
// ray($output2);
// ray($dboutput);
// expect($output)->toBeInstanceOf(Collection::class);
// expect($output2)->toBeInstanceOf(Collection::class);
// expect($dboutput)->toBeInstanceOf(Collection::class);
// });