This commit is contained in:
Andras Bacsai 2023-04-28 11:54:01 +02:00
parent 2fb8d928e5
commit 321087cb6d
4 changed files with 31 additions and 9 deletions

View File

@ -15,12 +15,22 @@ class CheckUpdate extends Component
protected function upgrade() protected function upgrade()
{ {
$branch = 'v4';
$location = "https://github.com/coollabsio/coolify/tree/$branch";
$server = Server::where('ip', 'host.docker.internal')->first(); $server = Server::where('ip', 'host.docker.internal')->first();
if (!$server) { if (!$server) {
return; return;
} }
runRemoteCommandSync($server, ['curl -fsSL https://raw.githubusercontent.com/coollabsio/coolify/v4/scripts/upgrade.sh -o /data/coolify/source/upgrade.sh']);
runRemoteCommandSync($server, ["bash /data/coolify/source/upgrade.sh $this->latestVersion"]); runRemoteCommandSync($server, [
"curl -fsSL $location/docker-compose.yml -o /data/coolify/source/docker-compose.yml",
"curl -fsSL $location/docker-compose.prod.yml -o /data/coolify/source/docker-compose.prod.yml",
"curl -fsSL $location/.env.production -o /data/coolify/source/.env.production",
"curl -fsSL $location/scripts/upgrade.sh -o /data/coolify/source/upgrade.sh",
"nohup bash /data/coolify/source/upgrade.sh $this->latestVersion &"
]);
$this->emit('updateInitiated');
} }
public function forceUpgrade() public function forceUpgrade()
{ {

View File

@ -25,6 +25,25 @@
<x-confirm-modal /> <x-confirm-modal />
@livewireScripts @livewireScripts
@auth
<script>
Livewire.on('updateInitiated', () => {
let checkStatus = null;
console.log('Update initiated')
setInterval(async () => {
const res = await fetch('/api/health');
if (res.ok) {
console.log('Server is back online')
clearInterval(checkStatus);
window.location.reload();
} else {
console.log('Waiting for server to come back online...');
}
return;
}, 2000);
})
</script>
@endauth
</body> </body>
</html> </html>

View File

@ -3,14 +3,12 @@
<div wire:loading wire:target="checkUpdate"> <div wire:loading wire:target="checkUpdate">
Checking for updates... Checking for updates...
</div> </div>
@env('production')
@if (auth()->user()->teams->contains(0)) @if (auth()->user()->teams->contains(0))
<button wire:click='forceUpgrade'>Force Upgrade</button> <button wire:click='forceUpgrade'>Force Upgrade</button>
<div wire:loading wire:target="forceUpgrade"> <div wire:loading wire:target="forceUpgrade">
Updating Coolify... Updating Coolify...
</div> </div>
@endif @endif
@endenv
@if ($updateAvailable) @if ($updateAvailable)
Update available Update available
@endif @endif

View File

@ -2,9 +2,4 @@
## Do not modify this file. You will lost the ability to autoupdate! ## Do not modify this file. You will lost the ability to autoupdate!
VERSION="0.1.0" VERSION="0.1.0"
if [ "$EUID" -ne 0 ]; then
echo "Please run as root"
exit
fi
docker run --pull always -v /data/coolify/source:/data/coolify/source -v /var/run/docker.sock:/var/run/docker.sock --rm ghcr.io/coollabsio/coolify-builder bash -c "APP_TAG=${1:-} docker compose --env-file /data/coolify/source/.env -f /data/coolify/source/docker-compose.yml -f /data/coolify/source/docker-compose.prod.yml up -d --pull always --remove-orphans --force-recreate" docker run --pull always -v /data/coolify/source:/data/coolify/source -v /var/run/docker.sock:/var/run/docker.sock --rm ghcr.io/coollabsio/coolify-builder bash -c "APP_TAG=${1:-} docker compose --env-file /data/coolify/source/.env -f /data/coolify/source/docker-compose.yml -f /data/coolify/source/docker-compose.prod.yml up -d --pull always --remove-orphans --force-recreate"