Fix server functionality check and cleanup SSH keys
This commit is contained in:
parent
a6cbabfba5
commit
a9cc5cc351
@ -179,6 +179,11 @@ class ApplicationDeploymentJob implements ShouldQueue, ShouldBeEncrypted
|
|||||||
|
|
||||||
public function handle(): void
|
public function handle(): void
|
||||||
{
|
{
|
||||||
|
if (!$this->server->isFunctional()) {
|
||||||
|
$this->application_deployment_queue->addLogEntry("Server is not functional.");
|
||||||
|
$this->fail("Server is not functional.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
// Generate custom host<->ip mapping
|
// Generate custom host<->ip mapping
|
||||||
$allContainers = instant_remote_process(["docker network inspect {$this->destination->network} -f '{{json .Containers}}' "], $this->server);
|
$allContainers = instant_remote_process(["docker network inspect {$this->destination->network} -f '{{json .Containers}}' "], $this->server);
|
||||||
@ -1809,7 +1814,6 @@ COPY ./nginx.conf /etc/nginx/conf.d/default.conf");
|
|||||||
|
|
||||||
public function failed(Throwable $exception): void
|
public function failed(Throwable $exception): void
|
||||||
{
|
{
|
||||||
|
|
||||||
$this->next(ApplicationDeploymentStatus::FAILED->value);
|
$this->next(ApplicationDeploymentStatus::FAILED->value);
|
||||||
$this->application_deployment_queue->addLogEntry("Oops something is not okay, are you okay? 😢", 'stderr');
|
$this->application_deployment_queue->addLogEntry("Oops something is not okay, are you okay? 😢", 'stderr');
|
||||||
if (str($exception->getMessage())->isNotEmpty()) {
|
if (str($exception->getMessage())->isNotEmpty()) {
|
||||||
|
@ -690,7 +690,13 @@ $schema://$host {
|
|||||||
}
|
}
|
||||||
public function isFunctional()
|
public function isFunctional()
|
||||||
{
|
{
|
||||||
return $this->settings->is_reachable && $this->settings->is_usable && !$this->settings->force_disabled;
|
$isFunctional = $this->settings->is_reachable && $this->settings->is_usable && !$this->settings->force_disabled;
|
||||||
|
['private_key_filename' => $private_key_filename, 'mux_filename' => $mux_filename] = server_ssh_configuration($this);
|
||||||
|
if (!$isFunctional) {
|
||||||
|
Storage::disk('ssh-keys')->delete($private_key_filename);
|
||||||
|
Storage::disk('ssh-mux')->delete($mux_filename);
|
||||||
|
}
|
||||||
|
return $isFunctional;
|
||||||
}
|
}
|
||||||
public function isLogDrainEnabled()
|
public function isLogDrainEnabled()
|
||||||
{
|
{
|
||||||
|
@ -55,17 +55,30 @@ function remote_process(
|
|||||||
),
|
),
|
||||||
])();
|
])();
|
||||||
}
|
}
|
||||||
|
function server_ssh_configuration(Server $server)
|
||||||
|
{
|
||||||
|
$uuid = data_get($server, 'uuid');
|
||||||
|
if (is_null($uuid)) {
|
||||||
|
throw new \Exception("Server does not have a uuid");
|
||||||
|
}
|
||||||
|
$private_key_filename = "id.root@{$server->uuid}";
|
||||||
|
$location = '/var/www/html/storage/app/ssh/keys/' . $private_key_filename;
|
||||||
|
$mux_filename = '/var/www/html/storage/app/ssh/mux/' . $server->muxFilename();
|
||||||
|
return [
|
||||||
|
'location' => $location,
|
||||||
|
'mux_filename' => $mux_filename,
|
||||||
|
'private_key_filename' => $private_key_filename
|
||||||
|
];
|
||||||
|
}
|
||||||
function savePrivateKeyToFs(Server $server)
|
function savePrivateKeyToFs(Server $server)
|
||||||
{
|
{
|
||||||
if (data_get($server, 'privateKey.private_key') === null) {
|
if (data_get($server, 'privateKey.private_key') === null) {
|
||||||
throw new \Exception("Server {$server->name} does not have a private key");
|
throw new \Exception("Server {$server->name} does not have a private key");
|
||||||
}
|
}
|
||||||
$sshKeyFileLocation = "id.root@{$server->uuid}";
|
['location' => $location, 'private_key_filename' => $private_key_filename] = server_ssh_configuration($server);
|
||||||
Storage::disk('ssh-keys')->makeDirectory('.');
|
Storage::disk('ssh-keys')->makeDirectory('.');
|
||||||
Storage::disk('ssh-mux')->makeDirectory('.');
|
Storage::disk('ssh-mux')->makeDirectory('.');
|
||||||
Storage::disk('ssh-keys')->put($sshKeyFileLocation, $server->privateKey->private_key);
|
Storage::disk('ssh-keys')->put($private_key_filename, $server->privateKey->private_key);
|
||||||
$location = '/var/www/html/storage/app/ssh/keys/' . $sshKeyFileLocation;
|
|
||||||
return $location;
|
return $location;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -223,6 +236,13 @@ function remove_iip($text)
|
|||||||
$text = preg_replace('/x-access-token:.*?(?=@)/', "x-access-token:" . REDACTED, $text);
|
$text = preg_replace('/x-access-token:.*?(?=@)/', "x-access-token:" . REDACTED, $text);
|
||||||
return preg_replace('/\x1b\[[0-9;]*m/', '', $text);
|
return preg_replace('/\x1b\[[0-9;]*m/', '', $text);
|
||||||
}
|
}
|
||||||
|
function remove_mux_and_private_key(Server $server)
|
||||||
|
{
|
||||||
|
$muxFilename = $server->muxFilename();
|
||||||
|
$privateKeyLocation = savePrivateKeyToFs($server);
|
||||||
|
Storage::disk('ssh-mux')->delete($muxFilename);
|
||||||
|
Storage::disk('ssh-keys')->delete($privateKeyLocation);
|
||||||
|
}
|
||||||
function refresh_server_connection(?PrivateKey $private_key = null)
|
function refresh_server_connection(?PrivateKey $private_key = null)
|
||||||
{
|
{
|
||||||
if (is_null($private_key)) {
|
if (is_null($private_key)) {
|
||||||
|
@ -7,7 +7,7 @@ return [
|
|||||||
|
|
||||||
// The release version of your application
|
// The release version of your application
|
||||||
// Example with dynamic git hash: trim(exec('git --git-dir ' . base_path('.git') . ' log --pretty="%h" -n1 HEAD'))
|
// Example with dynamic git hash: trim(exec('git --git-dir ' . base_path('.git') . ' log --pretty="%h" -n1 HEAD'))
|
||||||
'release' => '4.0.0-beta.252',
|
'release' => '4.0.0-beta.253',
|
||||||
// When left empty or `null` the Laravel environment will be used
|
// When left empty or `null` the Laravel environment will be used
|
||||||
'environment' => config('app.env'),
|
'environment' => config('app.env'),
|
||||||
|
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
return '4.0.0-beta.252';
|
return '4.0.0-beta.253';
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"coolify": {
|
"coolify": {
|
||||||
"v4": {
|
"v4": {
|
||||||
"version": "4.0.0-beta.252"
|
"version": "4.0.0-beta.253"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user