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 $currentVersion;
|
||||||
protected $image = 'ghcr.io/coollabsio/coolify';
|
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()
|
public function checkUpdate()
|
||||||
{
|
{
|
||||||
$response = Http::get('https://get.coollabs.io/versions.json');
|
$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 @@ class RouteServiceProvider extends ServiceProvider
|
|||||||
protected function configureRateLimiting(): void
|
protected function configureRateLimiting(): void
|
||||||
{
|
{
|
||||||
RateLimiter::for('api', function (Request $request) {
|
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());
|
return Limit::perMinute(60)->by($request->user()?->id ?: $request->ip());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -27,20 +27,41 @@
|
|||||||
@livewireScripts
|
@livewireScripts
|
||||||
@auth
|
@auth
|
||||||
<script>
|
<script>
|
||||||
Livewire.on('updateInitiated', () => {
|
function checkIfIamDead() {
|
||||||
let checkStatus = null;
|
checkIfIamDeadInterval = setInterval(async () => {
|
||||||
console.log('Update initiated')
|
console.log('Checking server\'s pulse...')
|
||||||
setInterval(async () => {
|
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');
|
const res = await fetch('/api/health');
|
||||||
if (res.ok) {
|
if (res.ok) {
|
||||||
console.log('Server is back online')
|
console.log('Server is back online. Reloading...')
|
||||||
clearInterval(checkStatus);
|
if (checkHealthInterval) clearInterval(checkHealthInterval);
|
||||||
window.location.reload();
|
window.location.reload();
|
||||||
} else {
|
} else {
|
||||||
console.log('Waiting for server to come back online...');
|
console.log('Waiting for server to come back from dead...');
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}, 2000);
|
}, 2000);
|
||||||
|
}
|
||||||
|
Livewire.on('updateInitiated', () => {
|
||||||
|
let checkHealthInterval = null;
|
||||||
|
let checkIfIamDeadInterval = null;
|
||||||
|
console.log('Update initiated. Waiting for server to be dead...')
|
||||||
|
checkIfIamDead();
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
@endauth
|
@endauth
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
@csrf
|
@csrf
|
||||||
<button type="submit">Logout</button>
|
<button type="submit">Logout</button>
|
||||||
</form>
|
</form>
|
||||||
<livewire:check-update>
|
<livewire:check-update />
|
||||||
@endauth
|
<livewire:force-upgrade />
|
||||||
|
@endauth
|
||||||
</nav>
|
</nav>
|
||||||
|
@ -1,14 +1,6 @@
|
|||||||
<div>
|
<div>
|
||||||
<button wire:click='checkUpdate'>Updates</button>
|
<button wire:loading.class="text-black bg-green-500" wire:loading.attr="disabled" wire:click='checkUpdate'>Check for
|
||||||
<div wire:loading wire:target="checkUpdate">
|
updates</button>
|
||||||
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
|
|
||||||
@if ($updateAvailable)
|
@if ($updateAvailable)
|
||||||
Update available
|
Update available
|
||||||
@endif
|
@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…
x
Reference in New Issue
Block a user