Merge branch 'next' of github.com:coollabsio/coolify into next

This commit is contained in:
Andras Bacsai
2024-10-17 10:04:54 +02:00
5 changed files with 38 additions and 33 deletions

View File

@@ -63,6 +63,7 @@ class PushServerUpdateJob implements ShouldQueue
public Collection $foundApplicationPreviewsIds; public Collection $foundApplicationPreviewsIds;
public bool $foundProxy = false; public bool $foundProxy = false;
public bool $foundLogDrainContainer = false; public bool $foundLogDrainContainer = false;
public function backoff(): int public function backoff(): int
@@ -204,7 +205,8 @@ class PushServerUpdateJob implements ShouldQueue
} }
private function serverStatus(){ private function serverStatus()
{
if ($this->server->isFunctional() === false) { if ($this->server->isFunctional() === false) {
throw new \Exception('Server is not ready.'); throw new \Exception('Server is not ready.');
} }
@@ -212,6 +214,7 @@ class PushServerUpdateJob implements ShouldQueue
throw new \Exception('Server is not reachable.'); throw new \Exception('Server is not reachable.');
} }
} }
private function updateApplicationStatus(string $applicationId, string $containerStatus) private function updateApplicationStatus(string $applicationId, string $containerStatus)
{ {
$application = $this->applications->where('id', $applicationId)->first(); $application = $this->applications->where('id', $applicationId)->first();
@@ -278,7 +281,6 @@ class PushServerUpdateJob implements ShouldQueue
StartProxy::run($this->server, false); StartProxy::run($this->server, false);
} }
} catch (\Throwable $e) { } catch (\Throwable $e) {
logger()->error($e);
} }
} else { } else {
$connectProxyToDockerNetworks = connectProxyToNetworks($this->server); $connectProxyToDockerNetworks = connectProxyToNetworks($this->server);
@@ -396,7 +398,8 @@ class PushServerUpdateJob implements ShouldQueue
return str($containerStatus)->contains('running'); return str($containerStatus)->contains('running');
} }
private function checkLogDrainContainer(){ private function checkLogDrainContainer()
{
if ($this->server->isLogDrainEnabled() && $this->foundLogDrainContainer === false) { if ($this->server->isLogDrainEnabled() && $this->foundLogDrainContainer === false) {
InstallLogDrain::dispatch($this->server); InstallLogDrain::dispatch($this->server);
} }

View File

@@ -213,7 +213,7 @@ class Application extends BaseModel
$server = data_get($this, 'destination.server'); $server = data_get($this, 'destination.server');
$workdir = $this->workdir(); $workdir = $this->workdir();
if (str($workdir)->endsWith($this->uuid)) { if (str($workdir)->endsWith($this->uuid)) {
instant_remote_process(['rm -rf ' . $this->workdir()], $server, false); instant_remote_process(['rm -rf '.$this->workdir()], $server, false);
} }
} }
@@ -348,7 +348,7 @@ class Application extends BaseModel
public function publishDirectory(): Attribute public function publishDirectory(): Attribute
{ {
return Attribute::make( return Attribute::make(
set: fn($value) => $value ? '/' . ltrim($value, '/') : null, set: fn ($value) => $value ? '/'.ltrim($value, '/') : null,
); );
} }
@@ -430,7 +430,7 @@ class Application extends BaseModel
$git_repository = str_replace('.git', '', $this->git_repository); $git_repository = str_replace('.git', '', $this->git_repository);
$url = Url::fromString($git_repository); $url = Url::fromString($git_repository);
$url = $url->withUserInfo(''); $url = $url->withUserInfo('');
$url = $url->withPath($url->getPath() . '/commits/' . $link); $url = $url->withPath($url->getPath().'/commits/'.$link);
return $url->__toString(); return $url->__toString();
} }
@@ -483,21 +483,21 @@ class Application extends BaseModel
public function baseDirectory(): Attribute public function baseDirectory(): Attribute
{ {
return Attribute::make( return Attribute::make(
set: fn($value) => '/' . ltrim($value, '/'), set: fn ($value) => '/'.ltrim($value, '/'),
); );
} }
public function portsMappings(): Attribute public function portsMappings(): Attribute
{ {
return Attribute::make( return Attribute::make(
set: fn($value) => $value === '' ? null : $value, set: fn ($value) => $value === '' ? null : $value,
); );
} }
public function portsMappingsArray(): Attribute public function portsMappingsArray(): Attribute
{ {
return Attribute::make( return Attribute::make(
get: fn() => is_null($this->ports_mappings) get: fn () => is_null($this->ports_mappings)
? [] ? []
: explode(',', $this->ports_mappings), : explode(',', $this->ports_mappings),
@@ -614,7 +614,7 @@ class Application extends BaseModel
public function portsExposesArray(): Attribute public function portsExposesArray(): Attribute
{ {
return Attribute::make( return Attribute::make(
get: fn() => is_null($this->ports_exposes) get: fn () => is_null($this->ports_exposes)
? [] ? []
: explode(',', $this->ports_exposes) : explode(',', $this->ports_exposes)
); );
@@ -831,7 +831,7 @@ class Application extends BaseModel
public function workdir() public function workdir()
{ {
return application_configuration_dir() . "/{$this->uuid}"; return application_configuration_dir()."/{$this->uuid}";
} }
public function isLogDrainEnabled() public function isLogDrainEnabled()
@@ -841,7 +841,7 @@ class Application extends BaseModel
public function isConfigurationChanged(bool $save = false) public function isConfigurationChanged(bool $save = false)
{ {
$newConfigHash = $this->fqdn . $this->git_repository . $this->git_branch . $this->git_commit_sha . $this->build_pack . $this->static_image . $this->install_command . $this->build_command . $this->start_command . $this->ports_exposes . $this->ports_mappings . $this->base_directory . $this->publish_directory . $this->dockerfile . $this->dockerfile_location . $this->custom_labels . $this->custom_docker_run_options . $this->dockerfile_target_build . $this->redirect; $newConfigHash = $this->fqdn.$this->git_repository.$this->git_branch.$this->git_commit_sha.$this->build_pack.$this->static_image.$this->install_command.$this->build_command.$this->start_command.$this->ports_exposes.$this->ports_mappings.$this->base_directory.$this->publish_directory.$this->dockerfile.$this->dockerfile_location.$this->custom_labels.$this->custom_docker_run_options.$this->dockerfile_target_build.$this->redirect;
if ($this->pull_request_id === 0 || $this->pull_request_id === null) { if ($this->pull_request_id === 0 || $this->pull_request_id === null) {
$newConfigHash .= json_encode($this->environment_variables()->get('value')->sort()); $newConfigHash .= json_encode($this->environment_variables()->get('value')->sort());
} else { } else {
@@ -895,7 +895,7 @@ class Application extends BaseModel
public function dirOnServer() public function dirOnServer()
{ {
return application_configuration_dir() . "/{$this->uuid}"; return application_configuration_dir()."/{$this->uuid}";
} }
public function setGitImportSettings(string $deployment_uuid, string $git_clone_command, bool $public = false) public function setGitImportSettings(string $deployment_uuid, string $git_clone_command, bool $public = false)
@@ -1019,7 +1019,7 @@ class Application extends BaseModel
} else { } else {
$commands->push("echo 'Checking out $branch'"); $commands->push("echo 'Checking out $branch'");
} }
$git_clone_command = "{$git_clone_command} && cd {$baseDir} && GIT_SSH_COMMAND=\"ssh -o ConnectTimeout=30 -p {$customPort} -o Port={$customPort} -o LogLevel=ERROR -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i /root/.ssh/id_rsa\" git fetch origin $branch && " . $this->buildGitCheckoutCommand($pr_branch_name); $git_clone_command = "{$git_clone_command} && cd {$baseDir} && GIT_SSH_COMMAND=\"ssh -o ConnectTimeout=30 -p {$customPort} -o Port={$customPort} -o LogLevel=ERROR -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i /root/.ssh/id_rsa\" git fetch origin $branch && ".$this->buildGitCheckoutCommand($pr_branch_name);
} elseif ($git_type === 'github' || $git_type === 'gitea') { } elseif ($git_type === 'github' || $git_type === 'gitea') {
$branch = "pull/{$pull_request_id}/head:$pr_branch_name"; $branch = "pull/{$pull_request_id}/head:$pr_branch_name";
if ($exec_in_docker) { if ($exec_in_docker) {
@@ -1027,14 +1027,14 @@ class Application extends BaseModel
} else { } else {
$commands->push("echo 'Checking out $branch'"); $commands->push("echo 'Checking out $branch'");
} }
$git_clone_command = "{$git_clone_command} && cd {$baseDir} && GIT_SSH_COMMAND=\"ssh -o ConnectTimeout=30 -p {$customPort} -o Port={$customPort} -o LogLevel=ERROR -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i /root/.ssh/id_rsa\" git fetch origin $branch && " . $this->buildGitCheckoutCommand($pr_branch_name); $git_clone_command = "{$git_clone_command} && cd {$baseDir} && GIT_SSH_COMMAND=\"ssh -o ConnectTimeout=30 -p {$customPort} -o Port={$customPort} -o LogLevel=ERROR -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i /root/.ssh/id_rsa\" git fetch origin $branch && ".$this->buildGitCheckoutCommand($pr_branch_name);
} elseif ($git_type === 'bitbucket') { } elseif ($git_type === 'bitbucket') {
if ($exec_in_docker) { if ($exec_in_docker) {
$commands->push(executeInDocker($deployment_uuid, "echo 'Checking out $branch'")); $commands->push(executeInDocker($deployment_uuid, "echo 'Checking out $branch'"));
} else { } else {
$commands->push("echo 'Checking out $branch'"); $commands->push("echo 'Checking out $branch'");
} }
$git_clone_command = "{$git_clone_command} && cd {$baseDir} && GIT_SSH_COMMAND=\"ssh -o ConnectTimeout=30 -p {$customPort} -o Port={$customPort} -o LogLevel=ERROR -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i /root/.ssh/id_rsa\" " . $this->buildGitCheckoutCommand($commit); $git_clone_command = "{$git_clone_command} && cd {$baseDir} && GIT_SSH_COMMAND=\"ssh -o ConnectTimeout=30 -p {$customPort} -o Port={$customPort} -o LogLevel=ERROR -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i /root/.ssh/id_rsa\" ".$this->buildGitCheckoutCommand($commit);
} }
} }
@@ -1063,7 +1063,7 @@ class Application extends BaseModel
} else { } else {
$commands->push("echo 'Checking out $branch'"); $commands->push("echo 'Checking out $branch'");
} }
$git_clone_command = "{$git_clone_command} && cd {$baseDir} && GIT_SSH_COMMAND=\"ssh -o ConnectTimeout=30 -p {$customPort} -o Port={$customPort} -o LogLevel=ERROR -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i /root/.ssh/id_rsa\" git fetch origin $branch && " . $this->buildGitCheckoutCommand($pr_branch_name); $git_clone_command = "{$git_clone_command} && cd {$baseDir} && GIT_SSH_COMMAND=\"ssh -o ConnectTimeout=30 -p {$customPort} -o Port={$customPort} -o LogLevel=ERROR -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i /root/.ssh/id_rsa\" git fetch origin $branch && ".$this->buildGitCheckoutCommand($pr_branch_name);
} elseif ($git_type === 'github' || $git_type === 'gitea') { } elseif ($git_type === 'github' || $git_type === 'gitea') {
$branch = "pull/{$pull_request_id}/head:$pr_branch_name"; $branch = "pull/{$pull_request_id}/head:$pr_branch_name";
if ($exec_in_docker) { if ($exec_in_docker) {
@@ -1071,14 +1071,14 @@ class Application extends BaseModel
} else { } else {
$commands->push("echo 'Checking out $branch'"); $commands->push("echo 'Checking out $branch'");
} }
$git_clone_command = "{$git_clone_command} && cd {$baseDir} && GIT_SSH_COMMAND=\"ssh -o ConnectTimeout=30 -p {$customPort} -o Port={$customPort} -o LogLevel=ERROR -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i /root/.ssh/id_rsa\" git fetch origin $branch && " . $this->buildGitCheckoutCommand($pr_branch_name); $git_clone_command = "{$git_clone_command} && cd {$baseDir} && GIT_SSH_COMMAND=\"ssh -o ConnectTimeout=30 -p {$customPort} -o Port={$customPort} -o LogLevel=ERROR -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i /root/.ssh/id_rsa\" git fetch origin $branch && ".$this->buildGitCheckoutCommand($pr_branch_name);
} elseif ($git_type === 'bitbucket') { } elseif ($git_type === 'bitbucket') {
if ($exec_in_docker) { if ($exec_in_docker) {
$commands->push(executeInDocker($deployment_uuid, "echo 'Checking out $branch'")); $commands->push(executeInDocker($deployment_uuid, "echo 'Checking out $branch'"));
} else { } else {
$commands->push("echo 'Checking out $branch'"); $commands->push("echo 'Checking out $branch'");
} }
$git_clone_command = "{$git_clone_command} && cd {$baseDir} && GIT_SSH_COMMAND=\"ssh -o ConnectTimeout=30 -p {$customPort} -o Port={$customPort} -o LogLevel=ERROR -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i /root/.ssh/id_rsa\" " . $this->buildGitCheckoutCommand($commit); $git_clone_command = "{$git_clone_command} && cd {$baseDir} && GIT_SSH_COMMAND=\"ssh -o ConnectTimeout=30 -p {$customPort} -o Port={$customPort} -o LogLevel=ERROR -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i /root/.ssh/id_rsa\" ".$this->buildGitCheckoutCommand($commit);
} }
} }
@@ -1131,7 +1131,7 @@ class Application extends BaseModel
} }
if ($source->startsWith('.')) { if ($source->startsWith('.')) {
$source = $source->after('.'); $source = $source->after('.');
$source = $workdir . $source; $source = $workdir.$source;
} }
$commands->push("mkdir -p $source > /dev/null 2>&1 || true"); $commands->push("mkdir -p $source > /dev/null 2>&1 || true");
} }
@@ -1142,7 +1142,7 @@ class Application extends BaseModel
$labels->push('coolify.managed=true'); $labels->push('coolify.managed=true');
} }
if (! $labels->contains('coolify.applicationId')) { if (! $labels->contains('coolify.applicationId')) {
$labels->push('coolify.applicationId=' . $this->id); $labels->push('coolify.applicationId='.$this->id);
} }
if (! $labels->contains('coolify.type')) { if (! $labels->contains('coolify.type')) {
$labels->push('coolify.type=application'); $labels->push('coolify.type=application');
@@ -1264,7 +1264,7 @@ class Application extends BaseModel
public function fqdns(): Attribute public function fqdns(): Attribute
{ {
return Attribute::make( return Attribute::make(
get: fn() => is_null($this->fqdn) get: fn () => is_null($this->fqdn)
? [] ? []
: explode(',', $this->fqdn), : explode(',', $this->fqdn),
); );
@@ -1325,10 +1325,10 @@ class Application extends BaseModel
continue; continue;
} }
if (isset($healthcheckCommand) && str_contains($trimmedLine, '\\')) { if (isset($healthcheckCommand) && str_contains($trimmedLine, '\\')) {
$healthcheckCommand .= ' ' . trim($trimmedLine, '\\ '); $healthcheckCommand .= ' '.trim($trimmedLine, '\\ ');
} }
if (isset($healthcheckCommand) && ! str_contains($trimmedLine, '\\') && ! empty($healthcheckCommand)) { if (isset($healthcheckCommand) && ! str_contains($trimmedLine, '\\') && ! empty($healthcheckCommand)) {
$healthcheckCommand .= ' ' . $trimmedLine; $healthcheckCommand .= ' '.$trimmedLine;
break; break;
} }
} }
@@ -1425,11 +1425,13 @@ class Application extends BaseModel
} }
$metrics = json_decode($metrics, true); $metrics = json_decode($metrics, true);
$parsedCollection = collect($metrics)->map(function ($metric) { $parsedCollection = collect($metrics)->map(function ($metric) {
return [(int)$metric['time'], (float)$metric['percent']]; return [(int) $metric['time'], (float) $metric['percent']];
}); });
return $parsedCollection->toArray(); return $parsedCollection->toArray();
} }
} }
public function getMemoryMetrics(int $mins = 5) public function getMemoryMetrics(int $mins = 5)
{ {
$server = $this->destination->server; $server = $this->destination->server;
@@ -1455,9 +1457,9 @@ class Application extends BaseModel
} }
$metrics = json_decode($metrics, true); $metrics = json_decode($metrics, true);
$parsedCollection = collect($metrics)->map(function ($metric) { $parsedCollection = collect($metrics)->map(function ($metric) {
logger($metric); return [(int) $metric['time'], (float) $metric['used']];
return [(int)$metric['time'], (float)$metric['used']];
}); });
return $parsedCollection->toArray(); return $parsedCollection->toArray();
} }
} }
@@ -1492,6 +1494,7 @@ class Application extends BaseModel
return $config; return $config;
} }
public function setConfig($config) public function setConfig($config)
{ {

View File

@@ -17,7 +17,6 @@ class SentinelSeeder extends Seeder
} }
if (str($server->settings->sentinel_custom_url)->isEmpty()) { if (str($server->settings->sentinel_custom_url)->isEmpty()) {
$url = $server->generateSentinelUrl(); $url = $server->generateSentinelUrl();
logger()->info("Setting sentinel custom url for server {$server->id} to {$url}");
$server->settings->sentinel_custom_url = $url; $server->settings->sentinel_custom_url = $url;
$server->settings->save(); $server->settings->save();
} }

View File

@@ -148,12 +148,12 @@ Route::group([
return response()->json(['message' => 'Server not found'], 404); return response()->json(['message' => 'Server not found'], 404);
} }
if ($server->settings->sentinel_token !== $naked_token) { if ($server->settings->sentinel_token !== $naked_token) {
logger('Unauthorized');
return response()->json(['message' => 'Unauthorized'], 401); return response()->json(['message' => 'Unauthorized'], 401);
} }
$data = request()->all(); $data = request()->all();
PushServerUpdateJob::dispatch($server, $data); PushServerUpdateJob::dispatch($server, $data);
return response()->json(['message' => 'ok'], 200); return response()->json(['message' => 'ok'], 200);
}); });
}); });

View File

@@ -12,9 +12,9 @@ services:
- SERVICE_FQDN_PLAUSIBLE - SERVICE_FQDN_PLAUSIBLE
- DATABASE_URL=postgres://${SERVICE_USER_POSTGRES}:${SERVICE_PASSWORD_POSTGRES}@plausible-db:5432/${POSTGRES_DB:-plausible-db} - DATABASE_URL=postgres://${SERVICE_USER_POSTGRES}:${SERVICE_PASSWORD_POSTGRES}@plausible-db:5432/${POSTGRES_DB:-plausible-db}
- CLICKHOUSE_DATABASE_URL=http://plausible-events-db:8123/plausible_events_db - CLICKHOUSE_DATABASE_URL=http://plausible-events-db:8123/plausible_events_db
- BASE_URL=$SERVICE_FQDN_PLAUSIBLE - BASE_URL=${SERVICE_FQDN_PLAUSIBLE}
- SECRET_KEY_BASE=$SERVICE_BASE64_64_PLAUSIBLE - SECRET_KEY_BASE=${SERVICE_BASE64_64_PLAUSIBLE}
- TOTP_VAULT_KEY=$SERVICE_REALBASE64_32_TOTP - TOTP_VAULT_KEY=${SERVICE_REALBASE64_32_TOTP}
depends_on: depends_on:
plausible-db: plausible-db:
condition: service_healthy condition: service_healthy
@@ -30,7 +30,7 @@ services:
"--no-verbose", "--no-verbose",
"--tries=1", "--tries=1",
"--spider", "--spider",
"http://127.0.0.1:8000/ping", "http://127.0.0.1:8000/api/health",
] ]
interval: 10s interval: 10s
timeout: 5s timeout: 5s