Skip to content

An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.

fix

Andras Bacsaif93b643e4368
diff --git a/app/Http/Livewire/ForceUpgrade.php b/app/Http/Livewire/ForceUpgrade.php
index 6ef2a06f3e..c5f5991f36 100644
--- a/app/Http/Livewire/ForceUpgrade.php
+++ b/app/Http/Livewire/ForceUpgrade.php
@@ -9,7 +9,7 @@ class ForceUpgrade extends Component
{
public function upgrade()
{
- dispatch_sync(new InstanceAutoUpdateJob());
+ dispatch_sync(new InstanceAutoUpdateJob(force: true));
$this->emit('updateInitiated');
}
}
diff --git a/app/Jobs/InstanceAutoUpdateJob.php b/app/Jobs/InstanceAutoUpdateJob.php
index dee1681f5e..3c382f527c 100644
--- a/app/Jobs/InstanceAutoUpdateJob.php
+++ b/app/Jobs/InstanceAutoUpdateJob.php
@@ -10,77 +10,79 @@ use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
+use Log;
class InstanceAutoUpdateJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
- /**
- * Create a new job instance.
- */
- public function __construct()
+ private string $latest_version;
+ private string $current_version;
+ private Server $server;
+ private string $server_name = 'host.docker.internal';
+
+ public function __construct(private bool $force = false)
{
+ if (config('app.env') === 'local') {
+ $this->server_name = 'coolify-testing-host';
+ }
+
$instance_settings = InstanceSettings::get();
- if (!$instance_settings->is_auto_update_enabled) {
- $this->delete();
+ $this->server = Server::where('ip', $this->server_name)->first();
+
+ if (!$instance_settings->is_auto_update_enabled || !$this->server) {
+ return $this->delete();
}
- }
- /**
- * Execute the job.
- */
+ $this->latest_version = get_latest_version_of_coolify();
+ $this->current_version = config('version');
+ if (!$this->force) {
+ try {
+ $this->check_if_update_available();
+ } catch (\Exception $e) {
+ Log::error($e->getMessage());
+ return $this->delete();
+ }
+ }
+ }
+ private function check_if_update_available()
+ {
+ if ($this->latest_version === $this->current_version) {
+ throw new \Exception("Already on latest version");
+ }
+ if (version_compare($this->latest_version, $this->current_version, '<')) {
+ throw new \Exception("Already on latest version");
+ }
+ }
public function handle(): void
{
- if (config('app.env') === 'local') {
- $latest_version = get_latest_version_of_coolify();
- $current_version = config('version');
- if ($latest_version === $current_version) {
- return;
- }
- if (version_compare($latest_version, $current_version, '<')) {
- return;
- }
+ try {
+ if (config('app.env') === 'local') {
+ instant_remote_process([
+ "sleep 2"
+ ], $this->server);
+ remote_process([
+ "sleep 10"
+ ], $this->server);
+ } else {
+ $cdn = "https://coolify-cdn.b-cdn.net/files";
+ instant_remote_process([
+ "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",
+ ], $this->server);
- $server = Server::where('ip', 'coolify-testing-host')->first();
- if (!$server) {
- return;
- }
- instant_remote_process([
- "sleep 2"
- ], $server);
- remote_process([
- "sleep 10"
- ], $server, ActivityTypes::INLINE->value);
- } else {
- $latest_version = get_latest_version_of_coolify();
- $current_version = config('version');
- if ($latest_version === $current_version) {
- return;
- }
- if (version_compare($latest_version, $current_version, '<')) {
- return;
- }
+ instant_remote_process([
+ "docker compose -f /data/coolify/source/docker-compose.yml -f /data/coolify/source/docker-compose.prod.yml pull",
+ ], $this->server);
- $cdn = "https://coolify-cdn.b-cdn.net/files";
- $server = Server::where('ip', 'host.docker.internal')->first();
- if (!$server) {
- return;
+ remote_process([
+ "bash /data/coolify/source/upgrade.sh $this->latest_version"
+ ], $this->server, ActivityTypes::INLINE->value);
}
-
- instant_remote_process([
- "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);
-
- instant_remote_process([
- "docker compose -f /data/coolify/source/docker-compose.yml -f /data/coolify/source/docker-compose.prod.yml pull",
- ], $server);
-
- remote_process([
- "bash /data/coolify/source/upgrade.sh $latest_version"
- ], $server, ActivityTypes::INLINE->value);
+ } catch (\Exception $e) {
+ Log::error($e->getMessage());
}
}
}
diff --git a/bootstrap/helpers/remoteProcess.php b/bootstrap/helpers/remoteProcess.php
index beb16eebd8..d4197fe2a8 100644
--- a/bootstrap/helpers/remoteProcess.php
+++ b/bootstrap/helpers/remoteProcess.php
@@ -2,6 +2,7 @@
use App\Actions\CoolifyTask\PrepareCoolifyTask;
use App\Data\CoolifyTaskArgs;
+use App\Enums\ActivityTypes;
use App\Models\Server;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Process;
@@ -16,7 +17,7 @@ use Spatie\Activitylog\Models\Activity;
function remote_process(
array $command,
Server $server,
- string $type,
+ string $type = ActivityTypes::INLINE->value,
?string $type_uuid = null,
?Model $model = null,
): Activity {