feat: pull new sentinel image and restart container
This commit is contained in:
parent
76a5290351
commit
1a152a5597
@ -8,8 +8,11 @@
|
|||||||
class StartSentinel
|
class StartSentinel
|
||||||
{
|
{
|
||||||
use AsAction;
|
use AsAction;
|
||||||
public function handle(Server $server)
|
public function handle(Server $server, $version = 'latest', bool $restart = false)
|
||||||
{
|
{
|
||||||
return instant_remote_process(['docker run --rm --pull always -d --name coolify-sentinel -p 127.0.0.1:8888:8888 -v /var/run/docker.sock:/var/run/docker.sock -v /data/coolify/metrics:/var/www/html/storage/app/metrics --pid host --health-cmd "curl --fail http://127.0.0.1:8888/api/health || exit 1" --health-interval 10s --health-retries 3 ghcr.io/coollabsio/sentinel:latest'], $server, false);
|
if ($restart) {
|
||||||
|
instant_remote_process(['docker rm -f coolify-sentinel'], $server, false);
|
||||||
|
}
|
||||||
|
return instant_remote_process(["docker run --rm --pull always -d --name coolify-sentinel -v /var/run/docker.sock:/var/run/docker.sock -v /data/coolify/metrics:/var/www/html/storage/app/metrics --pid host --health-cmd \"curl --fail http://127.0.0.1:8888/api/health || exit 1\" --health-interval 10s --health-retries 3 ghcr.io/coollabsio/sentinel:$version"], $server, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
use App\Jobs\InstanceAutoUpdateJob;
|
use App\Jobs\InstanceAutoUpdateJob;
|
||||||
use App\Jobs\ContainerStatusJob;
|
use App\Jobs\ContainerStatusJob;
|
||||||
use App\Jobs\PullHelperImageJob;
|
use App\Jobs\PullHelperImageJob;
|
||||||
|
use App\Jobs\PullSentinelImageJob;
|
||||||
use App\Jobs\ServerStatusJob;
|
use App\Jobs\ServerStatusJob;
|
||||||
use App\Models\InstanceSettings;
|
use App\Models\InstanceSettings;
|
||||||
use App\Models\ScheduledDatabaseBackup;
|
use App\Models\ScheduledDatabaseBackup;
|
||||||
@ -57,6 +58,7 @@ private function pull_helper_image($schedule)
|
|||||||
{
|
{
|
||||||
$servers = Server::all()->where('settings.is_usable', true)->where('settings.is_reachable', true)->where('ip', '!=', '1.2.3.4');
|
$servers = Server::all()->where('settings.is_usable', true)->where('settings.is_reachable', true)->where('ip', '!=', '1.2.3.4');
|
||||||
foreach ($servers as $server) {
|
foreach ($servers as $server) {
|
||||||
|
$schedule->job(new PullSentinelImageJob($server))->everyMinute()->onOneServer();
|
||||||
$schedule->job(new PullHelperImageJob($server))->everyTenMinutes()->onOneServer();
|
$schedule->job(new PullHelperImageJob($server))->everyTenMinutes()->onOneServer();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
54
app/Jobs/PullSentinelImageJob.php
Normal file
54
app/Jobs/PullSentinelImageJob.php
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Jobs;
|
||||||
|
|
||||||
|
use App\Actions\Server\StartSentinel;
|
||||||
|
use App\Models\Server;
|
||||||
|
use Illuminate\Bus\Queueable;
|
||||||
|
use Illuminate\Contracts\Queue\ShouldBeEncrypted;
|
||||||
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
|
use Illuminate\Foundation\Bus\Dispatchable;
|
||||||
|
use Illuminate\Queue\InteractsWithQueue;
|
||||||
|
use Illuminate\Queue\Middleware\WithoutOverlapping;
|
||||||
|
use Illuminate\Queue\SerializesModels;
|
||||||
|
|
||||||
|
class PullSentinelImageJob implements ShouldQueue, ShouldBeEncrypted
|
||||||
|
{
|
||||||
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||||
|
|
||||||
|
public $timeout = 1000;
|
||||||
|
|
||||||
|
public function middleware(): array
|
||||||
|
{
|
||||||
|
return [(new WithoutOverlapping($this->server->uuid))];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function uniqueId(): string
|
||||||
|
{
|
||||||
|
return $this->server->uuid;
|
||||||
|
}
|
||||||
|
public function __construct(public Server $server)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
public function handle(): void
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$version = get_latest_sentinel_version();
|
||||||
|
if (!$version) {
|
||||||
|
ray('Failed to get latest Sentinel version');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$local_version = instant_remote_process(['docker exec coolify-sentinel sh -c "curl http://127.0.0.1:8888/api/version"'], $this->server, '0.0.0');
|
||||||
|
if ($version === $local_version) {
|
||||||
|
ray('Sentinel image is up to date');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ray('Pulling Sentinel image');
|
||||||
|
StartSentinel::run($this->server, $version, true);
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
send_internal_notification('PullSentinelImageJob failed with: ' . $e->getMessage());
|
||||||
|
ray($e->getMessage());
|
||||||
|
throw $e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -147,6 +147,18 @@ function get_route_parameters(): array
|
|||||||
return Route::current()->parameters();
|
return Route::current()->parameters();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function get_latest_sentinel_version(): string
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$response = Http::get('https://cdn.coollabs.io/coolify/versions.json');
|
||||||
|
$versions = $response->json();
|
||||||
|
return data_get($versions, 'coolify.sentinel.version');
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
//throw $e;
|
||||||
|
ray($e->getMessage());
|
||||||
|
return '0.0.0';
|
||||||
|
}
|
||||||
|
}
|
||||||
function get_latest_version_of_coolify(): string
|
function get_latest_version_of_coolify(): string
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
|
@ -103,18 +103,6 @@ services:
|
|||||||
condition: service_healthy
|
condition: service_healthy
|
||||||
redis:
|
redis:
|
||||||
condition: service_healthy
|
condition: service_healthy
|
||||||
sentinel:
|
|
||||||
image: "ghcr.io/coollabsio/sentinel:${LATEST_IMAGE:-latest}"
|
|
||||||
volumes:
|
|
||||||
- /var/run/docker.sock:/var/run/docker.sock:ro
|
|
||||||
- /data/coolify/metrics:/var/www/html/storage/app/metrics
|
|
||||||
ports:
|
|
||||||
- "127.0.0.1:8888:8888"
|
|
||||||
healthcheck:
|
|
||||||
test: curl --fail http://127.0.0.1:8888/api/health || exit 1
|
|
||||||
interval: 10s
|
|
||||||
retries: 2
|
|
||||||
timeout: 5s
|
|
||||||
postgres:
|
postgres:
|
||||||
volumes:
|
volumes:
|
||||||
- coolify-db:/var/lib/postgresql/data
|
- coolify-db:/var/lib/postgresql/data
|
||||||
|
@ -10,12 +10,6 @@ services:
|
|||||||
depends_on:
|
depends_on:
|
||||||
- postgres
|
- postgres
|
||||||
- redis
|
- redis
|
||||||
sentinel:
|
|
||||||
image: "ghcr.io/coollabsio/sentinel:latest"
|
|
||||||
container_name: coolify-sentinel
|
|
||||||
restart: always
|
|
||||||
networks:
|
|
||||||
- coolify
|
|
||||||
postgres:
|
postgres:
|
||||||
image: postgres:15-alpine
|
image: postgres:15-alpine
|
||||||
container_name: coolify-db
|
container_name: coolify-db
|
||||||
|
@ -2,6 +2,9 @@
|
|||||||
"coolify": {
|
"coolify": {
|
||||||
"v4": {
|
"v4": {
|
||||||
"version": "4.0.0-beta.277"
|
"version": "4.0.0-beta.277"
|
||||||
|
},
|
||||||
|
"sentinel": {
|
||||||
|
"version": "0.0.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user