Skip to content

Commit

Permalink
rector: arrrrr
Browse files Browse the repository at this point in the history
  • Loading branch information
andrasbacsai committed Jan 7, 2025
1 parent c702ebf commit 16c0cd1
Show file tree
Hide file tree
Showing 349 changed files with 4,185 additions and 3,693 deletions.
7 changes: 5 additions & 2 deletions app/Actions/Application/StopApplication.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use App\Actions\Server\CleanupDocker;
use App\Models\Application;
use Exception;
use Lorisleiva\Actions\Concerns\AsAction;

class StopApplication
Expand All @@ -23,7 +24,7 @@ public function handle(Application $application, bool $previewDeployments = fals
if ($server->isSwarm()) {
instant_remote_process(["docker stack rm {$application->uuid}"], $server);

return;
return null;
}

$containersToStop = $application->getContainersToStop($previewDeployments);
Expand All @@ -36,8 +37,10 @@ public function handle(Application $application, bool $previewDeployments = fals
if ($dockerCleanup) {
CleanupDocker::dispatch($server, true);
}
} catch (\Exception $e) {
} catch (Exception $e) {
return $e->getMessage();
}

return null;
}
}
7 changes: 5 additions & 2 deletions app/Actions/Application/StopApplicationOneServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use App\Models\Application;
use App\Models\Server;
use Exception;
use Lorisleiva\Actions\Concerns\AsAction;

class StopApplicationOneServer
Expand All @@ -13,7 +14,7 @@ class StopApplicationOneServer
public function handle(Application $application, Server $server)
{
if ($application->destination->server->isSwarm()) {
return;
return null;
}
if (! $server->isFunctional()) {
return 'Server is not functional';
Expand All @@ -31,8 +32,10 @@ public function handle(Application $application, Server $server)
}
}
}
} catch (\Exception $e) {
} catch (Exception $e) {
return $e->getMessage();
}

return null;
}
}
21 changes: 11 additions & 10 deletions app/Actions/CoolifyTask/PrepareCoolifyTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use App\Data\CoolifyTaskArgs;
use App\Jobs\CoolifyTask;
use Illuminate\Database\Eloquent\Model;
use Spatie\Activitylog\Models\Activity;

/**
Expand All @@ -17,36 +18,36 @@ class PrepareCoolifyTask

protected CoolifyTaskArgs $remoteProcessArgs;

public function __construct(CoolifyTaskArgs $remoteProcessArgs)
public function __construct(CoolifyTaskArgs $coolifyTaskArgs)
{
$this->remoteProcessArgs = $remoteProcessArgs;
$this->remoteProcessArgs = $coolifyTaskArgs;

if ($remoteProcessArgs->model) {
$properties = $remoteProcessArgs->toArray();
if ($coolifyTaskArgs->model instanceof Model) {
$properties = $coolifyTaskArgs->toArray();
unset($properties['model']);

$this->activity = activity()
->withProperties($properties)
->performedOn($remoteProcessArgs->model)
->event($remoteProcessArgs->type)
->performedOn($coolifyTaskArgs->model)
->event($coolifyTaskArgs->type)
->log('[]');
} else {
$this->activity = activity()
->withProperties($remoteProcessArgs->toArray())
->event($remoteProcessArgs->type)
->withProperties($coolifyTaskArgs->toArray())
->event($coolifyTaskArgs->type)
->log('[]');
}
}

public function __invoke(): Activity
{
$job = new CoolifyTask(
$coolifyTask = new CoolifyTask(
activity: $this->activity,
ignore_errors: $this->remoteProcessArgs->ignore_errors,
call_event_on_finish: $this->remoteProcessArgs->call_event_on_finish,
call_event_data: $this->remoteProcessArgs->call_event_data,
);
dispatch($job);
dispatch($coolifyTask);
$this->activity->refresh();

return $this->activity;
Expand Down
21 changes: 12 additions & 9 deletions app/Actions/CoolifyTask/RunRemoteProcess.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Process;
use JsonException;
use RuntimeException;
use Spatie\Activitylog\Models\Activity;
use Throwable;

class RunRemoteProcess
{
Expand All @@ -21,9 +24,9 @@ class RunRemoteProcess

public bool $ignore_errors;

public $call_event_on_finish = null;
public $call_event_on_finish;

public $call_event_data = null;
public $call_event_data;

protected $time_start;

Expand All @@ -41,7 +44,7 @@ class RunRemoteProcess
public function __construct(Activity $activity, bool $hide_from_output = false, bool $ignore_errors = false, $call_event_on_finish = null, $call_event_data = null)
{
if ($activity->getExtraProperty('type') !== ActivityTypes::INLINE->value && $activity->getExtraProperty('type') !== ActivityTypes::COMMAND->value) {
throw new \RuntimeException('Incompatible Activity to run a remote command.');
throw new RuntimeException('Incompatible Activity to run a remote command.');
}

$this->activity = $activity;
Expand All @@ -63,7 +66,7 @@ public static function decodeOutput(?Activity $activity = null): string
associative: true,
flags: JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE
);
} catch (\JsonException $exception) {
} catch (JsonException $exception) {
return '';
}

Expand All @@ -79,12 +82,12 @@ public function __invoke(): ProcessResult

$status = ProcessStatus::IN_PROGRESS;
$timeout = config('constants.ssh.command_timeout');
$process = Process::timeout($timeout)->start($this->getCommand(), $this->handleOutput(...));
$invokedProcess = Process::timeout($timeout)->start($this->getCommand(), $this->handleOutput(...));
$this->activity->properties = $this->activity->properties->merge([
'process_id' => $process->id(),
'process_id' => $invokedProcess->id(),
]);

$processResult = $process->wait();
$processResult = $invokedProcess->wait();
// $processResult = Process::timeout($timeout)->run($this->getCommand(), $this->handleOutput(...));
if ($this->activity->properties->get('status') === ProcessStatus::ERROR->value) {
$status = ProcessStatus::ERROR;
Expand All @@ -111,7 +114,7 @@ public function __invoke(): ProcessResult
]);
$this->activity->save();
if ($processResult->exitCode() != 0 && ! $this->ignore_errors) {
throw new \RuntimeException($processResult->errorOutput(), $processResult->exitCode());
throw new RuntimeException($processResult->errorOutput(), $processResult->exitCode());
}
if ($this->call_event_on_finish) {
try {
Expand All @@ -124,7 +127,7 @@ public function __invoke(): ProcessResult
'userId' => $this->activity->causer_id,
]));
}
} catch (\Throwable $e) {
} catch (Throwable $e) {
Log::error('Error calling event: '.$e->getMessage());
}
}
Expand Down
8 changes: 4 additions & 4 deletions app/Actions/Database/StartClickhouse.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ class StartClickhouse

public string $configuration_dir;

public function handle(StandaloneClickhouse $database)
public function handle(StandaloneClickhouse $standaloneClickhouse)
{
$this->database = $database;
$this->database = $standaloneClickhouse;

$container_name = $this->database->uuid;
$this->configuration_dir = database_configuration_dir().'/'.$container_name;
Expand Down Expand Up @@ -103,12 +103,12 @@ public function handle(StandaloneClickhouse $database)
$this->commands[] = "echo '{$docker_compose_base64}' | base64 -d | tee $this->configuration_dir/docker-compose.yml > /dev/null";
$readme = generate_readme_file($this->database->name, now());
$this->commands[] = "echo '{$readme}' > $this->configuration_dir/README.md";
$this->commands[] = "echo 'Pulling {$database->image} image.'";
$this->commands[] = "echo 'Pulling {$standaloneClickhouse->image} image.'";
$this->commands[] = "docker compose -f $this->configuration_dir/docker-compose.yml pull";
$this->commands[] = "docker compose -f $this->configuration_dir/docker-compose.yml up -d";
$this->commands[] = "echo 'Database started.'";

return remote_process($this->commands, $database->destination->server, callEventOnFinish: 'DatabaseStatusChanged');
return remote_process($this->commands, $standaloneClickhouse->destination->server, callEventOnFinish: 'DatabaseStatusChanged');
}

private function generate_local_persistent_volumes()
Expand Down
16 changes: 8 additions & 8 deletions app/Actions/Database/StartDatabase.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,28 +25,28 @@ public function handle(StandaloneRedis|StandalonePostgresql|StandaloneMongodb|St
return 'Server is not functional';
}
switch ($database->getMorphClass()) {
case \App\Models\StandalonePostgresql::class:
case StandalonePostgresql::class:
$activity = StartPostgresql::run($database);
break;
case \App\Models\StandaloneRedis::class:
case StandaloneRedis::class:
$activity = StartRedis::run($database);
break;
case \App\Models\StandaloneMongodb::class:
case StandaloneMongodb::class:
$activity = StartMongodb::run($database);
break;
case \App\Models\StandaloneMysql::class:
case StandaloneMysql::class:
$activity = StartMysql::run($database);
break;
case \App\Models\StandaloneMariadb::class:
case StandaloneMariadb::class:
$activity = StartMariadb::run($database);
break;
case \App\Models\StandaloneKeydb::class:
case StandaloneKeydb::class:
$activity = StartKeydb::run($database);
break;
case \App\Models\StandaloneDragonfly::class:
case StandaloneDragonfly::class:
$activity = StartDragonfly::run($database);
break;
case \App\Models\StandaloneClickhouse::class:
case StandaloneClickhouse::class:
$activity = StartClickhouse::run($database);
break;
}
Expand Down
34 changes: 17 additions & 17 deletions app/Actions/Database/StartDatabaseProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,62 +28,62 @@ public function handle(StandaloneRedis|StandalonePostgresql|StandaloneMongodb|St
$server = data_get($database, 'destination.server');
$containerName = data_get($database, 'uuid');
$proxyContainerName = "{$database->uuid}-proxy";
if ($database->getMorphClass() === \App\Models\ServiceDatabase::class) {
if ($database->getMorphClass() === ServiceDatabase::class) {
$databaseType = $database->databaseType();
// $connectPredefined = data_get($database, 'service.connect_to_docker_network');
$network = $database->service->uuid;
$server = data_get($database, 'service.destination.server');
$proxyContainerName = "{$database->service->uuid}-proxy";
switch ($databaseType) {
case 'standalone-mariadb':
$type = \App\Models\StandaloneMariadb::class;
$type = StandaloneMariadb::class;
$containerName = "mariadb-{$database->service->uuid}";
break;
case 'standalone-mongodb':
$type = \App\Models\StandaloneMongodb::class;
$type = StandaloneMongodb::class;
$containerName = "mongodb-{$database->service->uuid}";
break;
case 'standalone-mysql':
$type = \App\Models\StandaloneMysql::class;
$type = StandaloneMysql::class;
$containerName = "mysql-{$database->service->uuid}";
break;
case 'standalone-postgresql':
$type = \App\Models\StandalonePostgresql::class;
$type = StandalonePostgresql::class;
$containerName = "postgresql-{$database->service->uuid}";
break;
case 'standalone-redis':
$type = \App\Models\StandaloneRedis::class;
$type = StandaloneRedis::class;
$containerName = "redis-{$database->service->uuid}";
break;
case 'standalone-keydb':
$type = \App\Models\StandaloneKeydb::class;
$type = StandaloneKeydb::class;
$containerName = "keydb-{$database->service->uuid}";
break;
case 'standalone-dragonfly':
$type = \App\Models\StandaloneDragonfly::class;
$type = StandaloneDragonfly::class;
$containerName = "dragonfly-{$database->service->uuid}";
break;
case 'standalone-clickhouse':
$type = \App\Models\StandaloneClickhouse::class;
$type = StandaloneClickhouse::class;
$containerName = "clickhouse-{$database->service->uuid}";
break;
}
}
if ($type === \App\Models\StandaloneRedis::class) {
if ($type === StandaloneRedis::class) {
$internalPort = 6379;
} elseif ($type === \App\Models\StandalonePostgresql::class) {
} elseif ($type === StandalonePostgresql::class) {
$internalPort = 5432;
} elseif ($type === \App\Models\StandaloneMongodb::class) {
} elseif ($type === StandaloneMongodb::class) {
$internalPort = 27017;
} elseif ($type === \App\Models\StandaloneMysql::class) {
} elseif ($type === StandaloneMysql::class) {
$internalPort = 3306;
} elseif ($type === \App\Models\StandaloneMariadb::class) {
} elseif ($type === StandaloneMariadb::class) {
$internalPort = 3306;
} elseif ($type === \App\Models\StandaloneKeydb::class) {
} elseif ($type === StandaloneKeydb::class) {
$internalPort = 6379;
} elseif ($type === \App\Models\StandaloneDragonfly::class) {
} elseif ($type === StandaloneDragonfly::class) {
$internalPort = 6379;
} elseif ($type === \App\Models\StandaloneClickhouse::class) {
} elseif ($type === StandaloneClickhouse::class) {
$internalPort = 9000;
}
$configuration_dir = database_proxy_dir($database->uuid);
Expand Down
8 changes: 4 additions & 4 deletions app/Actions/Database/StartDragonfly.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ class StartDragonfly

public string $configuration_dir;

public function handle(StandaloneDragonfly $database)
public function handle(StandaloneDragonfly $standaloneDragonfly)
{
$this->database = $database;
$this->database = $standaloneDragonfly;

$startCommand = "dragonfly --requirepass {$this->database->dragonfly_password}";

Expand Down Expand Up @@ -100,12 +100,12 @@ public function handle(StandaloneDragonfly $database)
$this->commands[] = "echo '{$docker_compose_base64}' | base64 -d | tee $this->configuration_dir/docker-compose.yml > /dev/null";
$readme = generate_readme_file($this->database->name, now());
$this->commands[] = "echo '{$readme}' > $this->configuration_dir/README.md";
$this->commands[] = "echo 'Pulling {$database->image} image.'";
$this->commands[] = "echo 'Pulling {$standaloneDragonfly->image} image.'";
$this->commands[] = "docker compose -f $this->configuration_dir/docker-compose.yml pull";
$this->commands[] = "docker compose -f $this->configuration_dir/docker-compose.yml up -d";
$this->commands[] = "echo 'Database started.'";

return remote_process($this->commands, $database->destination->server, callEventOnFinish: 'DatabaseStatusChanged');
return remote_process($this->commands, $standaloneDragonfly->destination->server, callEventOnFinish: 'DatabaseStatusChanged');
}

private function generate_local_persistent_volumes()
Expand Down
10 changes: 5 additions & 5 deletions app/Actions/Database/StartKeydb.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ class StartKeydb

public string $configuration_dir;

public function handle(StandaloneKeydb $database)
public function handle(StandaloneKeydb $standaloneKeydb)
{
$this->database = $database;
$this->database = $standaloneKeydb;

$startCommand = "keydb-server --requirepass {$this->database->keydb_password} --appendonly yes";

Expand Down Expand Up @@ -92,7 +92,7 @@ public function handle(StandaloneKeydb $database)
if (count($volume_names) > 0) {
$docker_compose['volumes'] = $volume_names;
}
if (! is_null($this->database->keydb_conf) || ! empty($this->database->keydb_conf)) {
if (! is_null($this->database->keydb_conf) || $this->database->keydb_conf !== null) {
$docker_compose['services'][$container_name]['volumes'][] = [
'type' => 'bind',
'source' => $this->configuration_dir.'/keydb.conf',
Expand All @@ -110,12 +110,12 @@ public function handle(StandaloneKeydb $database)
$this->commands[] = "echo '{$docker_compose_base64}' | base64 -d | tee $this->configuration_dir/docker-compose.yml > /dev/null";
$readme = generate_readme_file($this->database->name, now());
$this->commands[] = "echo '{$readme}' > $this->configuration_dir/README.md";
$this->commands[] = "echo 'Pulling {$database->image} image.'";
$this->commands[] = "echo 'Pulling {$standaloneKeydb->image} image.'";
$this->commands[] = "docker compose -f $this->configuration_dir/docker-compose.yml pull";
$this->commands[] = "docker compose -f $this->configuration_dir/docker-compose.yml up -d";
$this->commands[] = "echo 'Database started.'";

return remote_process($this->commands, $database->destination->server, callEventOnFinish: 'DatabaseStatusChanged');
return remote_process($this->commands, $standaloneKeydb->destination->server, callEventOnFinish: 'DatabaseStatusChanged');
}

private function generate_local_persistent_volumes()
Expand Down
Loading

0 comments on commit 16c0cd1

Please sign in to comment.