fix: update process
This commit is contained in:
parent
a0795136ac
commit
d19b05b970
@ -243,7 +243,6 @@ export async function configureHAProxy() {
|
|||||||
const { proxyHash, id } = await db.listSettings();
|
const { proxyHash, id } = await db.listSettings();
|
||||||
if (proxyHash !== newHash) {
|
if (proxyHash !== newHash) {
|
||||||
await db.prisma.setting.update({ where: { id }, data: { proxyHash: newHash } });
|
await db.prisma.setting.update({ where: { id }, data: { proxyHash: newHash } });
|
||||||
console.log('HAProxy configuration changed, updating...');
|
|
||||||
await haproxy.post(`v2/services/haproxy/configuration/raw`, {
|
await haproxy.post(`v2/services/haproxy/configuration/raw`, {
|
||||||
searchParams: {
|
searchParams: {
|
||||||
skip_version: true
|
skip_version: true
|
||||||
@ -253,8 +252,6 @@ export async function configureHAProxy() {
|
|||||||
'Content-Type': 'text/plain'
|
'Content-Type': 'text/plain'
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
|
||||||
console.log('HAProxy configuration is up to date');
|
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw error;
|
throw error;
|
||||||
|
@ -38,13 +38,13 @@
|
|||||||
import { errorNotification } from '$lib/form';
|
import { errorNotification } from '$lib/form';
|
||||||
import { asyncSleep } from '$lib/components/common';
|
import { asyncSleep } from '$lib/components/common';
|
||||||
import { del, get, post } from '$lib/api';
|
import { del, get, post } from '$lib/api';
|
||||||
import { browser } from '$app/env';
|
import { browser, dev } from '$app/env';
|
||||||
import { fade } from 'svelte/transition';
|
|
||||||
|
|
||||||
let isUpdateAvailable = false;
|
let isUpdateAvailable = false;
|
||||||
|
|
||||||
let updateStatus = {
|
let updateStatus = {
|
||||||
|
found: false,
|
||||||
loading: false,
|
loading: false,
|
||||||
checking: false,
|
|
||||||
success: null
|
success: null
|
||||||
};
|
};
|
||||||
let latestVersion = 'latest';
|
let latestVersion = 'latest';
|
||||||
@ -60,16 +60,19 @@
|
|||||||
}
|
}
|
||||||
if ($session.teamId === '0') {
|
if ($session.teamId === '0') {
|
||||||
try {
|
try {
|
||||||
updateStatus.checking = true;
|
|
||||||
const data = await get(`/update.json`);
|
const data = await get(`/update.json`);
|
||||||
if (overrideVersion || data?.isUpdateAvailable) {
|
if (overrideVersion || data?.isUpdateAvailable) {
|
||||||
latestVersion = overrideVersion || data.latestVersion;
|
latestVersion = overrideVersion || data.latestVersion;
|
||||||
isUpdateAvailable = overrideVersion ? true : data?.isUpdateAvailable;
|
console.log('checking update');
|
||||||
await post(`/update.json`, { type: 'pull', latestVersion });
|
const { exists } = await post(`/update.json`, {
|
||||||
|
type: 'check',
|
||||||
|
latestVersion,
|
||||||
|
overrideVersion
|
||||||
|
});
|
||||||
|
isUpdateAvailable = exists;
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
} finally {
|
} finally {
|
||||||
updateStatus.checking = false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -97,26 +100,32 @@
|
|||||||
async function update() {
|
async function update() {
|
||||||
updateStatus.loading = true;
|
updateStatus.loading = true;
|
||||||
try {
|
try {
|
||||||
await post(`/update.json`, { type: 'update', latestVersion });
|
if (dev) {
|
||||||
toast.push('Update completed.<br><br>Waiting for the new version to start...');
|
console.log(`updating to ${latestVersion}`);
|
||||||
let reachable = false;
|
|
||||||
let tries = 0;
|
|
||||||
do {
|
|
||||||
await asyncSleep(4000);
|
await asyncSleep(4000);
|
||||||
try {
|
return window.location.reload();
|
||||||
await get(`/undead.json`);
|
} else {
|
||||||
reachable = true;
|
await post(`/update.json`, { type: 'update', latestVersion });
|
||||||
} catch (error) {
|
toast.push('Update completed.<br><br>Waiting for the new version to start...');
|
||||||
reachable = false;
|
let reachable = false;
|
||||||
}
|
let tries = 0;
|
||||||
if (reachable) break;
|
do {
|
||||||
tries++;
|
await asyncSleep(4000);
|
||||||
} while (!reachable || tries < 120);
|
try {
|
||||||
toast.push('New version reachable. Reloading...');
|
await get(`/undead.json`);
|
||||||
updateStatus.loading = false;
|
reachable = true;
|
||||||
updateStatus.success = true;
|
} catch (error) {
|
||||||
await asyncSleep(3000);
|
reachable = false;
|
||||||
return window.location.reload();
|
}
|
||||||
|
if (reachable) break;
|
||||||
|
tries++;
|
||||||
|
} while (!reachable || tries < 120);
|
||||||
|
toast.push('New version reachable. Reloading...');
|
||||||
|
updateStatus.loading = false;
|
||||||
|
updateStatus.success = true;
|
||||||
|
await asyncSleep(3000);
|
||||||
|
return window.location.reload();
|
||||||
|
}
|
||||||
} catch ({ error }) {
|
} catch ({ error }) {
|
||||||
updateStatus.success = false;
|
updateStatus.success = false;
|
||||||
updateStatus.loading = false;
|
updateStatus.loading = false;
|
||||||
@ -311,35 +320,10 @@
|
|||||||
|
|
||||||
<div class="flex flex-col space-y-4 py-2">
|
<div class="flex flex-col space-y-4 py-2">
|
||||||
{#if $session.teamId === '0'}
|
{#if $session.teamId === '0'}
|
||||||
{#if updateStatus.checking}
|
{#if isUpdateAvailable}
|
||||||
<button
|
|
||||||
disabled
|
|
||||||
in:fade={{ duration: 150 }}
|
|
||||||
class="icons tooltip-right bg-gradient-to-r from-purple-500 via-pink-500 to-red-500 text-white duration-75 hover:scale-105"
|
|
||||||
data-tooltip="Checking for updates..."
|
|
||||||
><svg
|
|
||||||
xmlns="http://www.w3.org/2000/svg"
|
|
||||||
class="h-9 w-8 animate-spin"
|
|
||||||
viewBox="0 0 24 24"
|
|
||||||
stroke-width="1.5"
|
|
||||||
stroke="currentColor"
|
|
||||||
fill="none"
|
|
||||||
stroke-linecap="round"
|
|
||||||
stroke-linejoin="round"
|
|
||||||
>
|
|
||||||
<path stroke="none" d="M0 0h24v24H0z" fill="none" />
|
|
||||||
<path d="M9 4.55a8 8 0 0 1 6 14.9m0 -4.45v5h5" />
|
|
||||||
<line x1="5.63" y1="7.16" x2="5.63" y2="7.17" />
|
|
||||||
<line x1="4.06" y1="11" x2="4.06" y2="11.01" />
|
|
||||||
<line x1="4.63" y1="15.1" x2="4.63" y2="15.11" />
|
|
||||||
<line x1="7.16" y1="18.37" x2="7.16" y2="18.38" />
|
|
||||||
<line x1="11" y1="19.94" x2="11" y2="19.95" />
|
|
||||||
</svg></button
|
|
||||||
>
|
|
||||||
{:else if isUpdateAvailable}
|
|
||||||
<button
|
<button
|
||||||
disabled={updateStatus.success === false}
|
disabled={updateStatus.success === false}
|
||||||
data-tooltip="Update available"
|
title="Update available"
|
||||||
on:click={update}
|
on:click={update}
|
||||||
class="icons tooltip-right bg-gradient-to-r from-purple-500 via-pink-500 to-red-500 text-white duration-75 hover:scale-105"
|
class="icons tooltip-right bg-gradient-to-r from-purple-500 via-pink-500 to-red-500 text-white duration-75 hover:scale-105"
|
||||||
>
|
>
|
||||||
|
@ -43,39 +43,41 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="mx-auto max-w-6xl rounded-xl px-6 pt-4">
|
{#if applicationSecrets.length !== 0}
|
||||||
<table class="mx-auto border-separate text-left">
|
<div class="mx-auto max-w-6xl rounded-xl px-6 pt-4">
|
||||||
<thead>
|
<table class="mx-auto border-separate text-left">
|
||||||
<tr class="h-12">
|
<thead>
|
||||||
<th scope="col">Name</th>
|
<tr class="h-12">
|
||||||
<th scope="col">Value</th>
|
<th scope="col">Name</th>
|
||||||
<th scope="col" class="w-64 text-center">Need during buildtime?</th>
|
<th scope="col">Value</th>
|
||||||
<th scope="col" class="w-96 text-center">Action</th>
|
<th scope="col" class="w-64 text-center">Need during buildtime?</th>
|
||||||
</tr>
|
<th scope="col" class="w-96 text-center">Action</th>
|
||||||
</thead>
|
</tr>
|
||||||
<tbody>
|
</thead>
|
||||||
{#each applicationSecrets as secret}
|
<tbody>
|
||||||
{#key secret.id}
|
{#each applicationSecrets as secret}
|
||||||
<tr>
|
{#key secret.id}
|
||||||
<Secret
|
<tr>
|
||||||
PRMRSecret={PRMRSecrets.find((s) => s.name === secret.name)}
|
<Secret
|
||||||
isPRMRSecret
|
PRMRSecret={PRMRSecrets.find((s) => s.name === secret.name)}
|
||||||
name={secret.name}
|
isPRMRSecret
|
||||||
value={secret.value}
|
name={secret.name}
|
||||||
isBuildSecret={secret.isBuildSecret}
|
value={secret.value}
|
||||||
on:refresh={refreshSecrets}
|
isBuildSecret={secret.isBuildSecret}
|
||||||
/>
|
on:refresh={refreshSecrets}
|
||||||
</tr>
|
/>
|
||||||
{/key}
|
</tr>
|
||||||
{/each}
|
{/key}
|
||||||
</tbody>
|
{/each}
|
||||||
</table>
|
</tbody>
|
||||||
</div>
|
</table>
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
<div class="flex justify-center py-4 text-center">
|
<div class="flex justify-center py-4 text-center">
|
||||||
<Explainer
|
<Explainer
|
||||||
customClass="w-full"
|
customClass="w-full"
|
||||||
text={applicationSecrets.length === 0
|
text={applicationSecrets.length === 0
|
||||||
? "<span class='font-bold text-white text-xl'>Please add secrets to the application first.</span> <br><br>These values overwrite application secrets in PR/MR deployments. Useful for creating <span class='text-green-500 font-bold'>staging</span> environments."
|
? "You can add secrets to PR/MR deployments. Please add secrets to the application first. <br>Useful for creating <span class='text-green-500 font-bold'>staging</span> environments."
|
||||||
: "These values overwrite application secrets in PR/MR deployments. Useful for creating <span class='text-green-500 font-bold'>staging</span> environments."}
|
: "These values overwrite application secrets in PR/MR deployments. Useful for creating <span class='text-green-500 font-bold'>staging</span> environments."}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
@ -12,7 +12,7 @@ export const get: RequestHandler = async () => {
|
|||||||
const versions = await got
|
const versions = await got
|
||||||
.get(`https://get.coollabs.io/versions.json?appId=${process.env['COOLIFY_APP_ID']}`)
|
.get(`https://get.coollabs.io/versions.json?appId=${process.env['COOLIFY_APP_ID']}`)
|
||||||
.json();
|
.json();
|
||||||
const latestVersion = dev ? '10.0.0' : versions['coolify'].main.version;
|
const latestVersion = versions['coolify'].main.version;
|
||||||
const isUpdateAvailable = compare(latestVersion, currentVersion);
|
const isUpdateAvailable = compare(latestVersion, currentVersion);
|
||||||
return {
|
return {
|
||||||
body: {
|
body: {
|
||||||
@ -26,27 +26,11 @@ export const get: RequestHandler = async () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const post: RequestHandler = async (event) => {
|
export const post: RequestHandler = async (event) => {
|
||||||
const { type, latestVersion } = await event.request.json();
|
const { type, latestVersion, overrideVersion } = await event.request.json();
|
||||||
if (type === 'pull') {
|
if (type === 'update') {
|
||||||
try {
|
try {
|
||||||
if (!dev) {
|
if (!dev) {
|
||||||
await asyncExecShell(`docker pull coollabsio/coolify:${latestVersion}`);
|
await asyncExecShell(`docker pull coollabsio/coolify:${latestVersion}`);
|
||||||
return {
|
|
||||||
status: 200,
|
|
||||||
body: {}
|
|
||||||
};
|
|
||||||
} else {
|
|
||||||
return {
|
|
||||||
status: 200,
|
|
||||||
body: {}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
return ErrorHandler(error);
|
|
||||||
}
|
|
||||||
} else if (type === 'update') {
|
|
||||||
try {
|
|
||||||
if (!dev) {
|
|
||||||
await asyncExecShell(`env | grep COOLIFY > .env`);
|
await asyncExecShell(`env | grep COOLIFY > .env`);
|
||||||
await asyncExecShell(
|
await asyncExecShell(
|
||||||
`docker run --rm -tid --env-file .env -v /var/run/docker.sock:/var/run/docker.sock -v coolify-db coollabsio/coolify:${latestVersion} /bin/sh -c "env | grep COOLIFY > .env && echo 'TAG=${latestVersion}' >> .env && docker stop -t 0 coolify coolify-redis && docker rm coolify coolify-redis && docker compose up -d --force-recreate"`
|
`docker run --rm -tid --env-file .env -v /var/run/docker.sock:/var/run/docker.sock -v coolify-db coollabsio/coolify:${latestVersion} /bin/sh -c "env | grep COOLIFY > .env && echo 'TAG=${latestVersion}' >> .env && docker stop -t 0 coolify coolify-redis && docker rm coolify coolify-redis && docker compose up -d --force-recreate"`
|
||||||
@ -66,6 +50,31 @@ export const post: RequestHandler = async (event) => {
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
return ErrorHandler(error);
|
return ErrorHandler(error);
|
||||||
}
|
}
|
||||||
|
} else if (type === 'check') {
|
||||||
|
try {
|
||||||
|
if (overrideVersion) {
|
||||||
|
return {
|
||||||
|
status: 200,
|
||||||
|
body: {
|
||||||
|
exists: true
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
await asyncExecShell(`docker image inspect coollabsio/coolify:${latestVersion}`);
|
||||||
|
return {
|
||||||
|
status: 200,
|
||||||
|
body: {
|
||||||
|
exists: true
|
||||||
|
}
|
||||||
|
};
|
||||||
|
} catch (error) {
|
||||||
|
return {
|
||||||
|
status: 200,
|
||||||
|
body: {
|
||||||
|
exists: false
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
status: 500
|
status: 500
|
||||||
|
Loading…
x
Reference in New Issue
Block a user