feat: Autoupdater
This commit is contained in:
@@ -304,7 +304,7 @@
|
|||||||
"coolify_proxy_settings": "Coolify Proxy Settings",
|
"coolify_proxy_settings": "Coolify Proxy Settings",
|
||||||
"credential_stat_explainer": "Credentials for <a class=\"text-white font-bold\" href=\"{{link}}\" target=\"_blank\">stats</a> page.",
|
"credential_stat_explainer": "Credentials for <a class=\"text-white font-bold\" href=\"{{link}}\" target=\"_blank\">stats</a> page.",
|
||||||
"auto_update_enabled": "Auto update enabled?",
|
"auto_update_enabled": "Auto update enabled?",
|
||||||
"auto_update_enabled_explainer": "Enable automatic updates for Coolify."
|
"auto_update_enabled_explainer": "Enable automatic updates for Coolify. It will be done automatically behind the scenes, if there is no build process running."
|
||||||
},
|
},
|
||||||
"team": {
|
"team": {
|
||||||
"pending_invitations": "Pending invitations",
|
"pending_invitations": "Pending invitations",
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import compare from 'compare-versions';
|
|||||||
import { dev } from '$app/env';
|
import { dev } from '$app/env';
|
||||||
|
|
||||||
export default async function (): Promise<void> {
|
export default async function (): Promise<void> {
|
||||||
|
try {
|
||||||
const currentVersion = version;
|
const currentVersion = version;
|
||||||
const { isAutoUpdateEnabled } = await prisma.setting.findFirst();
|
const { isAutoUpdateEnabled } = await prisma.setting.findFirst();
|
||||||
if (isAutoUpdateEnabled) {
|
if (isAutoUpdateEnabled) {
|
||||||
@@ -20,20 +21,22 @@ export default async function (): Promise<void> {
|
|||||||
const activeCount = await buildQueue.getActiveCount();
|
const activeCount = await buildQueue.getActiveCount();
|
||||||
if (activeCount === 0) {
|
if (activeCount === 0) {
|
||||||
if (!dev) {
|
if (!dev) {
|
||||||
console.log('Updating...');
|
await buildQueue.pause();
|
||||||
|
console.log(`Updating Coolify to ${latestVersion}.`);
|
||||||
await asyncExecShell(`docker pull coollabsio/coolify:${latestVersion}`);
|
await asyncExecShell(`docker pull coollabsio/coolify:${latestVersion}`);
|
||||||
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"`
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
|
await buildQueue.pause();
|
||||||
console.log('Updating (not really in dev mode).');
|
console.log('Updating (not really in dev mode).');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
console.log('No update available.');
|
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
console.log('Auto update is disabled.');
|
} catch (error) {
|
||||||
|
await buildQueue.resume();
|
||||||
|
console.log(error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -130,6 +130,9 @@ const buildWorker = new Worker(buildQueueName, async (job) => await builder(job)
|
|||||||
concurrency: 1,
|
concurrency: 1,
|
||||||
...connectionOptions
|
...connectionOptions
|
||||||
});
|
});
|
||||||
|
buildQueue.resume().catch((err) => {
|
||||||
|
console.log('Build queue failed to resume!', err);
|
||||||
|
});
|
||||||
|
|
||||||
buildWorker.on('completed', async (job: Bullmq.Job) => {
|
buildWorker.on('completed', async (job: Bullmq.Job) => {
|
||||||
try {
|
try {
|
||||||
@@ -138,7 +141,6 @@ buildWorker.on('completed', async (job: Bullmq.Job) => {
|
|||||||
setTimeout(async () => {
|
setTimeout(async () => {
|
||||||
await prisma.build.update({ where: { id: job.data.build_id }, data: { status: 'success' } });
|
await prisma.build.update({ where: { id: job.data.build_id }, data: { status: 'success' } });
|
||||||
}, 1234);
|
}, 1234);
|
||||||
console.log(error);
|
|
||||||
} finally {
|
} finally {
|
||||||
const workdir = `/tmp/build-sources/${job.data.repository}/${job.data.build_id}`;
|
const workdir = `/tmp/build-sources/${job.data.repository}/${job.data.build_id}`;
|
||||||
if (!dev) await asyncExecShell(`rm -fr ${workdir}`);
|
if (!dev) await asyncExecShell(`rm -fr ${workdir}`);
|
||||||
@@ -154,7 +156,6 @@ buildWorker.on('failed', async (job: Bullmq.Job, failedReason) => {
|
|||||||
setTimeout(async () => {
|
setTimeout(async () => {
|
||||||
await prisma.build.update({ where: { id: job.data.build_id }, data: { status: 'failed' } });
|
await prisma.build.update({ where: { id: job.data.build_id }, data: { status: 'failed' } });
|
||||||
}, 1234);
|
}, 1234);
|
||||||
console.log(error);
|
|
||||||
} finally {
|
} finally {
|
||||||
const workdir = `/tmp/build-sources/${job.data.repository}`;
|
const workdir = `/tmp/build-sources/${job.data.repository}`;
|
||||||
if (!dev) await asyncExecShell(`rm -fr ${workdir}`);
|
if (!dev) await asyncExecShell(`rm -fr ${workdir}`);
|
||||||
|
|||||||
@@ -194,6 +194,7 @@
|
|||||||
on:click={() => changeSettings('isRegistrationEnabled')}
|
on:click={() => changeSettings('isRegistrationEnabled')}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
{#if browser && window.location.hostname === 'staging.coolify.io'}
|
||||||
<div class="grid grid-cols-2 items-center">
|
<div class="grid grid-cols-2 items-center">
|
||||||
<Setting
|
<Setting
|
||||||
bind:setting={isAutoUpdateEnabled}
|
bind:setting={isAutoUpdateEnabled}
|
||||||
@@ -202,6 +203,7 @@
|
|||||||
on:click={() => changeSettings('isAutoUpdateEnabled')}
|
on:click={() => changeSettings('isAutoUpdateEnabled')}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
<div class="flex space-x-1 pt-6 font-bold">
|
<div class="flex space-x-1 pt-6 font-bold">
|
||||||
|
|||||||
Reference in New Issue
Block a user