Skip to content

Commit

Permalink
Merge pull request #4338 from coollabsio/next
Browse files Browse the repository at this point in the history
v4.0.0-beta.371
  • Loading branch information
andrasbacsai authored Nov 22, 2024
2 parents 092bd91 + 75b7a32 commit 57a1945
Show file tree
Hide file tree
Showing 72 changed files with 266 additions and 196 deletions.
2 changes: 2 additions & 0 deletions app/Actions/Application/StopApplication.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ class StopApplication
{
use AsAction;

public string $jobQueue = 'high';

public function handle(Application $application, bool $previewDeployments = false, bool $dockerCleanup = true)
{
try {
Expand Down
7 changes: 1 addition & 6 deletions app/Actions/CoolifyTask/PrepareCoolifyTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace App\Actions\CoolifyTask;

use App\Data\CoolifyTaskArgs;
use App\Enums\ActivityTypes;
use App\Jobs\CoolifyTask;
use Spatie\Activitylog\Models\Activity;

Expand Down Expand Up @@ -47,11 +46,7 @@ public function __invoke(): Activity
call_event_on_finish: $this->remoteProcessArgs->call_event_on_finish,
call_event_data: $this->remoteProcessArgs->call_event_data,
);
if ($this->remoteProcessArgs->type === ActivityTypes::COMMAND->value) {
dispatch($job)->onQueue('high');
} else {
dispatch($job);
}
dispatch($job);
$this->activity->refresh();

return $this->activity;
Expand Down
4 changes: 3 additions & 1 deletion app/Actions/Database/StartDatabase.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ class StartDatabase
{
use AsAction;

public string $jobQueue = 'high';

public function handle(StandaloneRedis|StandalonePostgresql|StandaloneMongodb|StandaloneMysql|StandaloneMariadb|StandaloneKeydb|StandaloneDragonfly|StandaloneClickhouse $database)
{
$server = $database->destination->server;
Expand Down Expand Up @@ -49,7 +51,7 @@ public function handle(StandaloneRedis|StandalonePostgresql|StandaloneMongodb|St
break;
}
if ($database->is_public && $database->public_port) {
StartDatabaseProxy::dispatch($database)->onQueue('high');
StartDatabaseProxy::dispatch($database);
}

return $activity;
Expand Down
2 changes: 2 additions & 0 deletions app/Actions/Database/StartDatabaseProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class StartDatabaseProxy
{
use AsAction;

public string $jobQueue = 'high';

public function handle(StandaloneRedis|StandalonePostgresql|StandaloneMongodb|StandaloneMysql|StandaloneMariadb|StandaloneKeydb|StandaloneDragonfly|StandaloneClickhouse|ServiceDatabase $database)
{
$internalPort = null;
Expand Down
2 changes: 2 additions & 0 deletions app/Actions/Database/StopDatabaseProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class StopDatabaseProxy
{
use AsAction;

public string $jobQueue = 'high';

public function handle(StandaloneRedis|StandalonePostgresql|StandaloneMongodb|StandaloneMysql|StandaloneMariadb|StandaloneKeydb|ServiceDatabase|StandaloneDragonfly|StandaloneClickhouse $database)
{
$server = data_get($database, 'destination.server');
Expand Down
3 changes: 2 additions & 1 deletion app/Actions/Docker/GetContainersStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use App\Models\ApplicationPreview;
use App\Models\Server;
use App\Models\ServiceDatabase;
use App\Notifications\Container\ContainerRestarted;
use Illuminate\Support\Arr;
use Illuminate\Support\Collection;
use Lorisleiva\Actions\Concerns\AsAction;
Expand All @@ -16,6 +15,8 @@ class GetContainersStatus
{
use AsAction;

public string $jobQueue = 'high';

public $applications;

public ?Collection $containers;
Expand Down
2 changes: 2 additions & 0 deletions app/Actions/Server/CleanupDocker.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ class CleanupDocker
{
use AsAction;

public string $jobQueue = 'high';

public function handle(Server $server)
{
$settings = instanceSettings();
Expand Down
4 changes: 2 additions & 2 deletions app/Actions/Server/ServerCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,10 @@ private function checkLogDrainContainer()
if ($foundLogDrainContainer) {
$status = data_get($foundLogDrainContainer, 'State.Status');
if ($status !== 'running') {
StartLogDrain::dispatch($this->server)->onQueue('high');
StartLogDrain::dispatch($this->server);
}
} else {
StartLogDrain::dispatch($this->server)->onQueue('high');
StartLogDrain::dispatch($this->server);
}
}

Expand Down
2 changes: 2 additions & 0 deletions app/Actions/Server/StartLogDrain.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ class StartLogDrain
{
use AsAction;

public string $jobQueue = 'high';

public function handle(Server $server)
{
if ($server->settings->is_logdrain_newrelic_enabled) {
Expand Down
2 changes: 1 addition & 1 deletion app/Actions/Server/UpdateCoolify.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function handle($manual_update = false)
if (! $this->server) {
return;
}
CleanupDocker::dispatch($this->server)->onQueue('high');
CleanupDocker::dispatch($this->server);
$this->latestVersion = get_latest_version_of_coolify();
$this->currentVersion = config('version');
if (! $manual_update) {
Expand Down
2 changes: 2 additions & 0 deletions app/Actions/Server/ValidateServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ class ValidateServer
{
use AsAction;

public string $jobQueue = 'high';

public ?string $uptime = null;

public ?string $error = null;
Expand Down
2 changes: 2 additions & 0 deletions app/Actions/Service/RestartService.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ class RestartService
{
use AsAction;

public string $jobQueue = 'high';

public function handle(Service $service)
{
StopService::run($service);
Expand Down
2 changes: 2 additions & 0 deletions app/Actions/Service/StartService.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ class StartService
{
use AsAction;

public string $jobQueue = 'high';

public function handle(Service $service)
{
$service->saveComposeConfigs();
Expand Down
2 changes: 2 additions & 0 deletions app/Actions/Service/StopService.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ class StopService
{
use AsAction;

public string $jobQueue = 'high';

public function handle(Service $service, bool $isDeleteOperation = false, bool $dockerCleanup = true)
{
try {
Expand Down
6 changes: 3 additions & 3 deletions app/Console/Commands/ServicesDelete.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ private function deleteApplication()
if (! $confirmed) {
break;
}
DeleteResourceJob::dispatch($toDelete)->onQueue('high');
DeleteResourceJob::dispatch($toDelete);
}
}
}
Expand All @@ -122,7 +122,7 @@ private function deleteDatabase()
if (! $confirmed) {
return;
}
DeleteResourceJob::dispatch($toDelete)->onQueue('high');
DeleteResourceJob::dispatch($toDelete);
}
}
}
Expand All @@ -148,7 +148,7 @@ private function deleteService()
if (! $confirmed) {
return;
}
DeleteResourceJob::dispatch($toDelete)->onQueue('high');
DeleteResourceJob::dispatch($toDelete);
}
}
}
Expand Down
37 changes: 18 additions & 19 deletions app/Helpers/SshMultiplexingHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,14 @@ public static function serverSshConfiguration(Server $server)
];
}

public static function ensureMultiplexedConnection(Server $server)
public static function ensureMultiplexedConnection(Server $server): bool
{
if (! self::isMultiplexingEnabled()) {
return;
return false;
}

$sshConfig = self::serverSshConfiguration($server);
$muxSocket = $sshConfig['muxFilename'];
$sshKeyLocation = $sshConfig['sshKeyLocation'];

self::validateSshKey($sshKeyLocation);

$checkCommand = "ssh -O check -o ControlPath=$muxSocket ";
if (data_get($server, 'settings.is_cloudflare_tunnel')) {
Expand All @@ -41,16 +38,17 @@ public static function ensureMultiplexedConnection(Server $server)
$process = Process::run($checkCommand);

if ($process->exitCode() !== 0) {
self::establishNewMultiplexedConnection($server);
return self::establishNewMultiplexedConnection($server);
}

return true;
}

public static function establishNewMultiplexedConnection(Server $server)
public static function establishNewMultiplexedConnection(Server $server): bool
{
$sshConfig = self::serverSshConfiguration($server);
$sshKeyLocation = $sshConfig['sshKeyLocation'];
$muxSocket = $sshConfig['muxFilename'];

$connectionTimeout = config('constants.ssh.connection_timeout');
$serverInterval = config('constants.ssh.server_interval');
$muxPersistTime = config('constants.ssh.mux_persist_time');
Expand All @@ -60,15 +58,14 @@ public static function establishNewMultiplexedConnection(Server $server)
if (data_get($server, 'settings.is_cloudflare_tunnel')) {
$establishCommand .= ' -o ProxyCommand="cloudflared access ssh --hostname %h" ';
}

$establishCommand .= self::getCommonSshOptions($server, $sshKeyLocation, $connectionTimeout, $serverInterval);
$establishCommand .= "{$server->user}@{$server->ip}";

$establishProcess = Process::run($establishCommand);

if ($establishProcess->exitCode() !== 0) {
throw new \RuntimeException('Failed to establish multiplexed connection: '.$establishProcess->errorOutput());
return false;
}

return true;
}

public static function removeMuxFile(Server $server)
Expand Down Expand Up @@ -97,9 +94,8 @@ public static function generateScpCommand(Server $server, string $source, string
if ($server->isIpv6()) {
$scp_command .= '-6 ';
}
if (self::isMultiplexingEnabled()) {
if (self::isMultiplexingEnabled() && self::ensureMultiplexedConnection($server)) {
$scp_command .= "-o ControlMaster=auto -o ControlPath=$muxSocket -o ControlPersist={$muxPersistTime} ";
self::ensureMultiplexedConnection($server);
}

if (data_get($server, 'settings.is_cloudflare_tunnel')) {
Expand All @@ -120,16 +116,18 @@ public static function generateSshCommand(Server $server, string $command)

$sshConfig = self::serverSshConfiguration($server);
$sshKeyLocation = $sshConfig['sshKeyLocation'];

self::validateSshKey($server->privateKey);

$muxSocket = $sshConfig['muxFilename'];

$timeout = config('constants.ssh.command_timeout');
$muxPersistTime = config('constants.ssh.mux_persist_time');

$ssh_command = "timeout $timeout ssh ";

if (self::isMultiplexingEnabled()) {
if (self::isMultiplexingEnabled() && self::ensureMultiplexedConnection($server)) {
$ssh_command .= "-o ControlMaster=auto -o ControlPath=$muxSocket -o ControlPersist={$muxPersistTime} ";
self::ensureMultiplexedConnection($server);
}

if (data_get($server, 'settings.is_cloudflare_tunnel')) {
Expand All @@ -154,13 +152,14 @@ private static function isMultiplexingEnabled(): bool
return config('constants.ssh.mux_enabled') && ! config('constants.coolify.is_windows_docker_desktop');
}

private static function validateSshKey(string $sshKeyLocation): void
private static function validateSshKey(PrivateKey $privateKey): void
{
$checkKeyCommand = "ls $sshKeyLocation 2>/dev/null";
$keyLocation = $privateKey->getKeyLocation();
$checkKeyCommand = "ls $keyLocation 2>/dev/null";
$keyCheckProcess = Process::run($checkKeyCommand);

if ($keyCheckProcess->exitCode() !== 0) {
throw new \RuntimeException("SSH key file not accessible: $sshKeyLocation");
$privateKey->storeInFileSystem();
}
}

Expand Down
6 changes: 3 additions & 3 deletions app/Http/Controllers/Api/ApplicationsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -1224,7 +1224,7 @@ private function create_application(Request $request, $type)
$service->name = "service-$service->uuid";
$service->parse(isNew: true);
if ($instantDeploy) {
StartService::dispatch($service)->onQueue('high');
StartService::dispatch($service);
}

return response()->json(serializeApiResponse([
Expand Down Expand Up @@ -1379,7 +1379,7 @@ public function delete_by_uuid(Request $request)
deleteVolumes: $request->query->get('delete_volumes', true),
dockerCleanup: $request->query->get('docker_cleanup', true),
deleteConnectedNetworks: $request->query->get('delete_connected_networks', true)
)->onQueue('high');
);

return response()->json([
'message' => 'Application deletion request queued.',
Expand Down Expand Up @@ -2523,7 +2523,7 @@ public function action_stop(Request $request)
if (! $application) {
return response()->json(['message' => 'Application not found.'], 404);
}
StopApplication::dispatch($application)->onQueue('high');
StopApplication::dispatch($application);

return response()->json(
[
Expand Down
Loading

0 comments on commit 57a1945

Please sign in to comment.