Merge pull request #1467 from coollabsio/next

v4.0.0-beta.142
This commit is contained in:
Andras Bacsai
2023-11-17 14:32:32 +01:00
committed by GitHub
10 changed files with 37 additions and 44 deletions

View File

@@ -4,6 +4,7 @@ namespace App\Http\Livewire\Project\Application;
use App\Actions\Application\StopApplication; use App\Actions\Application\StopApplication;
use App\Jobs\ContainerStatusJob; use App\Jobs\ContainerStatusJob;
use App\Jobs\ServerStatusJob;
use App\Models\Application; use App\Models\Application;
use Livewire\Component; use Livewire\Component;
use Visus\Cuid2\Cuid2; use Visus\Cuid2\Cuid2;
@@ -28,6 +29,8 @@ class Heading extends Component
$this->application->previews->each(function ($preview) { $this->application->previews->each(function ($preview) {
$preview->refresh(); $preview->refresh();
}); });
} else {
dispatch(new ServerStatusJob($this->application->destination->server));
} }
} }

View File

@@ -42,28 +42,31 @@ class Rollback extends Component
{ {
try { try {
$image = $this->application->uuid; $image = $this->application->uuid;
$output = instant_remote_process([ if ($this->application->destination->server->isFunctional()) {
"docker inspect --format='{{.Config.Image}}' {$this->application->uuid}", $output = instant_remote_process([
], $this->application->destination->server, throwError: false); "docker inspect --format='{{.Config.Image}}' {$this->application->uuid}",
$current_tag = Str::of($output)->trim()->explode(":"); ], $this->application->destination->server, throwError: false);
$this->current = data_get($current_tag, 1); $current_tag = Str::of($output)->trim()->explode(":");
$this->current = data_get($current_tag, 1);
$output = instant_remote_process([ $output = instant_remote_process([
"docker images --format '{{.Repository}}#{{.Tag}}#{{.CreatedAt}}'", "docker images --format '{{.Repository}}#{{.Tag}}#{{.CreatedAt}}'",
], $this->application->destination->server); ], $this->application->destination->server);
$this->images = Str::of($output)->trim()->explode("\n")->filter(function ($item) use ($image) { $this->images = Str::of($output)->trim()->explode("\n")->filter(function ($item) use ($image) {
return Str::of($item)->contains($image); return Str::of($item)->contains($image);
})->map(function ($item) { })->map(function ($item) {
$item = Str::of($item)->explode('#'); $item = Str::of($item)->explode('#');
if ($item[1] === $this->current) { if ($item[1] === $this->current) {
// $is_current = true; // $is_current = true;
} }
return [ return [
'tag' => $item[1], 'tag' => $item[1],
'created_at' => $item[2], 'created_at' => $item[2],
'is_current' => $is_current ?? null, 'is_current' => $is_current ?? null,
]; ];
})->toArray(); })->toArray();
}
return [];
} catch (\Throwable $e) { } catch (\Throwable $e) {
return handleError($e, $this); return handleError($e, $this);
} }

View File

@@ -1022,10 +1022,6 @@ COPY ./nginx.conf /etc/nginx/conf.d/default.conf");
listen [::]:80; listen [::]:80;
server_name localhost; server_name localhost;
// real_ip_header X-Forwarded-For;
// proxy_set_header X-Real-IP \$remote_addr;
// proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
location / { location / {
root /usr/share/nginx/html; root /usr/share/nginx/html;
index index.html; index index.html;

View File

@@ -23,7 +23,7 @@ class ContainerStatusJob implements ShouldQueue, ShouldBeEncrypted
public function __construct(public Server $server) public function __construct(public Server $server)
{ {
// $this->handle(); $this->handle();
} }
public function middleware(): array public function middleware(): array
{ {
@@ -37,11 +37,9 @@ class ContainerStatusJob implements ShouldQueue, ShouldBeEncrypted
public function handle(): void public function handle(): void
{ {
// ray("checking server status for {$this->server->id}"); ray("checking container statuses for {$this->server->id}");
try { try {
if (!$this->server->checkServerRediness()) { $this->server->checkServerRediness();
return;
}
$containers = instant_remote_process(["docker container ls -q"], $this->server); $containers = instant_remote_process(["docker container ls -q"], $this->server);
if (!$containers) { if (!$containers) {
return; return;

View File

@@ -34,10 +34,7 @@ class ServerStatusJob implements ShouldQueue, ShouldBeEncrypted
{ {
ray("checking server status for {$this->server->id}"); ray("checking server status for {$this->server->id}");
try { try {
if (!$this->server->checkServerRediness()) { $this->server->checkServerRediness();
ray('server not ready');
return;
}
$this->cleanup(notify: false); $this->cleanup(notify: false);
} catch (\Throwable $e) { } catch (\Throwable $e) {
send_internal_notification('ServerStatusJob failed with: ' . $e->getMessage()); send_internal_notification('ServerStatusJob failed with: ' . $e->getMessage());

View File

@@ -130,15 +130,12 @@ class Server extends BaseModel
} }
public function checkServerRediness() public function checkServerRediness()
{ {
if ($this->skipServer()) {
return false;
}
$serverUptimeCheckNumber = $this->unreachable_count; $serverUptimeCheckNumber = $this->unreachable_count;
$serverUptimeCheckNumberMax = 5; $serverUptimeCheckNumberMax = 3;
$currentTime = now()->timestamp; $currentTime = now()->timestamp;
$runtime5Minutes = 1 * 60; $runtime5Minutes = 1 * 60;
// Run for 1 minutes max and check every 5 seconds // Run for 1 minutes max and check every 5 seconds for 3 times
while ($currentTime + $runtime5Minutes > now()->timestamp) { while ($currentTime + $runtime5Minutes > now()->timestamp) {
if ($serverUptimeCheckNumber >= $serverUptimeCheckNumberMax) { if ($serverUptimeCheckNumber >= $serverUptimeCheckNumberMax) {
if ($this->unreachable_notification_sent === false) { if ($this->unreachable_notification_sent === false) {
@@ -168,7 +165,7 @@ class Server extends BaseModel
$db->update(['status' => 'exited']); $db->update(['status' => 'exited']);
} }
} }
return false; throw new \Exception('Server is not reachable.');
} }
$result = $this->validateConnection(); $result = $this->validateConnection();
ray('validateConnection: ' . $result); ray('validateConnection: ' . $result);

View File

@@ -52,7 +52,6 @@ class User extends Authenticatable implements SendsEmail
} }
public function createToken(string $name, array $abilities = ['*'], DateTimeInterface $expiresAt = null) public function createToken(string $name, array $abilities = ['*'], DateTimeInterface $expiresAt = null)
{ {
ray('asd');
$plainTextToken = sprintf( $plainTextToken = sprintf(
'%s%s%s', '%s%s%s',
config('sanctum.token_prefix', ''), config('sanctum.token_prefix', ''),

View File

@@ -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.141', 'release' => '4.0.0-beta.142',
// 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'),

View File

@@ -1,3 +1,3 @@
<?php <?php
return '4.0.0-beta.141'; return '4.0.0-beta.142';

View File

@@ -4,7 +4,7 @@
"version": "3.12.36" "version": "3.12.36"
}, },
"v4": { "v4": {
"version": "4.0.0-beta.141" "version": "4.0.0-beta.142"
} }
} }
} }