better upgrade process for the user
This commit is contained in:
parent
c579dcfb53
commit
7ea73c3db2
@ -13,28 +13,6 @@ class CheckUpdate extends Component
|
||||
protected $currentVersion;
|
||||
protected $image = 'ghcr.io/coollabsio/coolify';
|
||||
|
||||
protected function upgrade()
|
||||
{
|
||||
$cdn = "https://coolify-cdn.b-cdn.net/files";
|
||||
$server = Server::where('ip', 'host.docker.internal')->first();
|
||||
if (!$server) {
|
||||
return;
|
||||
}
|
||||
|
||||
runRemoteCommandSync($server, [
|
||||
"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",
|
||||
"bash /data/coolify/source/upgrade.sh $this->latestVersion &"
|
||||
]);
|
||||
$this->emit('updateInitiated');
|
||||
}
|
||||
public function forceUpgrade()
|
||||
{
|
||||
$this->checkUpdate();
|
||||
$this->upgrade();
|
||||
}
|
||||
public function checkUpdate()
|
||||
{
|
||||
$response = Http::get('https://get.coollabs.io/versions.json');
|
||||
|
48
app/Http/Livewire/ForceUpgrade.php
Normal file
48
app/Http/Livewire/ForceUpgrade.php
Normal file
@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Livewire;
|
||||
|
||||
use App\Models\Server;
|
||||
use Livewire\Component;
|
||||
|
||||
class ForceUpgrade extends Component
|
||||
{
|
||||
public function upgrade()
|
||||
{
|
||||
if (env('APP_ENV') === 'local') {
|
||||
$server = Server::where('ip', 'coolify-testing-host')->first();
|
||||
if (!$server) {
|
||||
return;
|
||||
}
|
||||
runRemoteCommandSync($server, [
|
||||
"sleep 2"
|
||||
]);
|
||||
remoteProcess([
|
||||
"sleep 10"
|
||||
], $server);
|
||||
$this->emit('updateInitiated');
|
||||
} else {
|
||||
$cdn = "https://coolify-cdn.b-cdn.net/files";
|
||||
$server = Server::where('ip', 'host.docker.internal')->first();
|
||||
if (!$server) {
|
||||
return;
|
||||
}
|
||||
|
||||
runRemoteCommandSync($server, [
|
||||
"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",
|
||||
]);
|
||||
runRemoteCommandSync($server, [
|
||||
"docker compose -f /data/coolify/source/docker-compose.yml -f /data/coolify/source/docker-compose.prod.yml pull",
|
||||
]);
|
||||
|
||||
remoteProcess([
|
||||
"bash /data/coolify/source/upgrade.sh $this->latestVersion"
|
||||
], $server);
|
||||
|
||||
$this->emit('updateInitiated');
|
||||
}
|
||||
}
|
||||
}
|
@ -42,6 +42,9 @@ public function boot(): void
|
||||
protected function configureRateLimiting(): void
|
||||
{
|
||||
RateLimiter::for('api', function (Request $request) {
|
||||
if ($request->path() === 'api/health') {
|
||||
return Limit::perMinute(5000)->by($request->user()?->id ?: $request->ip());
|
||||
}
|
||||
return Limit::perMinute(60)->by($request->user()?->id ?: $request->ip());
|
||||
});
|
||||
}
|
||||
|
@ -27,20 +27,41 @@
|
||||
@livewireScripts
|
||||
@auth
|
||||
<script>
|
||||
Livewire.on('updateInitiated', () => {
|
||||
let checkStatus = null;
|
||||
console.log('Update initiated')
|
||||
setInterval(async () => {
|
||||
function checkIfIamDead() {
|
||||
checkIfIamDeadInterval = setInterval(async () => {
|
||||
console.log('Checking server\'s pulse...')
|
||||
const res = await fetch('/api/health');
|
||||
if (!res.ok) {
|
||||
console.log('I\'m dead. Charging... Standby... Bzz... Bzz...')
|
||||
} else {
|
||||
console.log('I\'m alive!');
|
||||
checkHealth();
|
||||
if (checkIfIamDeadInterval) clearInterval(checkIfIamDeadInterval);
|
||||
}
|
||||
|
||||
return;
|
||||
}, 2000);
|
||||
}
|
||||
|
||||
function checkHealth() {
|
||||
checkHealthInterval = setInterval(async () => {
|
||||
console.log('Checking server\'s health...')
|
||||
const res = await fetch('/api/health');
|
||||
if (res.ok) {
|
||||
console.log('Server is back online')
|
||||
clearInterval(checkStatus);
|
||||
console.log('Server is back online. Reloading...')
|
||||
if (checkHealthInterval) clearInterval(checkHealthInterval);
|
||||
window.location.reload();
|
||||
} else {
|
||||
console.log('Waiting for server to come back online...');
|
||||
console.log('Waiting for server to come back from dead...');
|
||||
}
|
||||
return;
|
||||
}, 2000);
|
||||
}
|
||||
Livewire.on('updateInitiated', () => {
|
||||
let checkHealthInterval = null;
|
||||
let checkIfIamDeadInterval = null;
|
||||
console.log('Update initiated. Waiting for server to be dead...')
|
||||
checkIfIamDead();
|
||||
})
|
||||
</script>
|
||||
@endauth
|
||||
|
@ -13,6 +13,7 @@
|
||||
@csrf
|
||||
<button type="submit">Logout</button>
|
||||
</form>
|
||||
<livewire:check-update>
|
||||
<livewire:check-update />
|
||||
<livewire:force-upgrade />
|
||||
@endauth
|
||||
</nav>
|
||||
|
@ -1,14 +1,6 @@
|
||||
<div>
|
||||
<button wire:click='checkUpdate'>Updates</button>
|
||||
<div wire:loading wire:target="checkUpdate">
|
||||
Checking for updates...
|
||||
</div>
|
||||
@if (auth()->user()->teams->contains(0))
|
||||
<button wire:click='forceUpgrade'>Force Upgrade</button>
|
||||
<div wire:loading wire:target="forceUpgrade">
|
||||
Updating Coolify...
|
||||
</div>
|
||||
@endif
|
||||
<button wire:loading.class="text-black bg-green-500" wire:loading.attr="disabled" wire:click='checkUpdate'>Check for
|
||||
updates</button>
|
||||
@if ($updateAvailable)
|
||||
Update available
|
||||
@endif
|
||||
|
6
resources/views/livewire/force-upgrade.blade.php
Normal file
6
resources/views/livewire/force-upgrade.blade.php
Normal file
@ -0,0 +1,6 @@
|
||||
<div>
|
||||
@if (auth()->user()->teams->contains(0))
|
||||
<button wire:loading.class="text-black bg-green-500" wire:loading.attr="disabled" wire:click='upgrade'>Force
|
||||
Upgrade</button>
|
||||
@endif
|
||||
</div>
|
Loading…
Reference in New Issue
Block a user