auto updates
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Console;
|
||||
|
||||
use App\Jobs\AutoUpdateJob;
|
||||
use App\Jobs\ContainerStatusJob;
|
||||
use App\Jobs\DockerCleanupDanglingImagesJob;
|
||||
use App\Jobs\ProxyCheckJob;
|
||||
@@ -15,9 +16,9 @@ class Kernel extends ConsoleKernel
|
||||
*/
|
||||
protected function schedule(Schedule $schedule): void
|
||||
{
|
||||
$schedule->job(new ContainerStatusJob)->everyMinute();
|
||||
$schedule->job(new DockerCleanupDanglingImagesJob)->everyMinute();
|
||||
// $schedule->job(new ProxyCheckJob)->everyMinute();
|
||||
$schedule->job(new DockerCleanupDanglingImagesJob)->everyFiveMinutes();
|
||||
$schedule->job(new AutoUpdateJob)->everyFifteenMinutes();
|
||||
$schedule->job(new ProxyCheckJob)->everyMinute();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Http\Livewire\Project\Application;
|
||||
|
||||
use App\Jobs\ContainerStatusJob;
|
||||
use App\Jobs\DeployApplicationJob;
|
||||
use App\Models\Application;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
@@ -26,6 +27,7 @@ class Deploy extends Component
|
||||
$this->parameters = getParameters();
|
||||
$this->application = Application::where('id', $this->applicationId)->first();
|
||||
$this->destination = $this->application->destination->getMorphClass()::where('id', $this->application->destination->id)->first();
|
||||
dispatch(new ContainerStatusJob($this->application->uuid));
|
||||
}
|
||||
protected function setDeploymentUuid()
|
||||
{
|
||||
|
||||
93
app/Jobs/AutoUpdateJob.php
Normal file
93
app/Jobs/AutoUpdateJob.php
Normal file
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs;
|
||||
|
||||
use App\Enums\ActivityTypes;
|
||||
use App\Models\InstanceSettings;
|
||||
use App\Models\Server;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldBeUnique;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class AutoUpdateJob implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, ShouldBeUnique;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$instance_settings = InstanceSettings::get();
|
||||
if (!$instance_settings->is_auto_update_enabled) {
|
||||
Log::info('Auto update is disabled');
|
||||
dd('Auto update is disabled');
|
||||
$this->delete();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*/
|
||||
public function handle(): void
|
||||
{
|
||||
if (config('app.env') === 'local') {
|
||||
$latest_version = getLatestVersionOfCoolify();
|
||||
$current_version = config('version');
|
||||
if ($latest_version === $current_version) {
|
||||
dd('no update, versions match', $latest_version, $current_version);
|
||||
return;
|
||||
}
|
||||
if (version_compare($latest_version, $current_version, '<')) {
|
||||
dd('no update, latest version is lower than current version');
|
||||
return;
|
||||
}
|
||||
|
||||
$server = Server::where('ip', 'coolify-testing-host')->first();
|
||||
if (!$server) {
|
||||
return;
|
||||
}
|
||||
instantRemoteProcess([
|
||||
"sleep 2"
|
||||
], $server);
|
||||
remoteProcess([
|
||||
"sleep 10"
|
||||
], $server, ActivityTypes::INLINE->value);
|
||||
dd('update done');
|
||||
} else {
|
||||
$latest_version = getLatestVersionOfCoolify();
|
||||
$current_version = config('version');
|
||||
if ($latest_version === $current_version) {
|
||||
return;
|
||||
}
|
||||
if (version_compare($latest_version, $current_version, '<')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$cdn = "https://coolify-cdn.b-cdn.net/files";
|
||||
$server = Server::where('ip', 'host.docker.internal')->first();
|
||||
if (!$server) {
|
||||
return;
|
||||
}
|
||||
|
||||
instantRemoteProcess([
|
||||
"curl -fsSL $cdn/docker-compose.yml -o /data/coolify/source/docker-compose.yml",
|
||||
"curl -fsSL $cdn/docker-compose.prod.yml -o /data/coolify/source/docker-compose.prod.yml",
|
||||
"curl -fsSL $cdn/.env.production -o /data/coolify/source/.env.production",
|
||||
"curl -fsSL $cdn/upgrade.sh -o /data/coolify/source/upgrade.sh",
|
||||
], $server);
|
||||
|
||||
instantRemoteProcess([
|
||||
"docker compose -f /data/coolify/source/docker-compose.yml -f /data/coolify/source/docker-compose.prod.yml pull",
|
||||
], $server);
|
||||
|
||||
remoteProcess([
|
||||
"bash /data/coolify/source/upgrade.sh $latest_version"
|
||||
], $server, ActivityTypes::INLINE->value);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -52,9 +52,15 @@ class User extends Authenticatable
|
||||
$model->uuid = (string) new Cuid2(7);
|
||||
});
|
||||
}
|
||||
public function isRoot()
|
||||
public function isPartOfRootTeam()
|
||||
{
|
||||
return $this->id == 0;
|
||||
$found_root_team = auth()->user()->teams->filter(function ($team) {
|
||||
if ($team->id == 0) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
return $found_root_team->count() > 0;
|
||||
}
|
||||
public function teams()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user