Skip to content

An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.

feat: Autoupdater

Andras Bacsaic1a48dcf1ea7
diff --git a/src/lib/locales/en.json b/src/lib/locales/en.json
index 573ca00e85..d77d2a1c1e 100644
--- a/src/lib/locales/en.json
+++ b/src/lib/locales/en.json
@@ -304,7 +304,7 @@
"coolify_proxy_settings": "Coolify Proxy Settings",
"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_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": {
"pending_invitations": "Pending invitations",
diff --git a/src/lib/queues/autoUpdater.ts b/src/lib/queues/autoUpdater.ts
index 8350101773..4bfb995c7b 100644
--- a/src/lib/queues/autoUpdater.ts
+++ b/src/lib/queues/autoUpdater.ts
@@ -6,34 +6,37 @@ import compare from 'compare-versions';
import { dev } from '$app/env';
export default async function (): Promise<void> {
- const currentVersion = version;
- const { isAutoUpdateEnabled } = await prisma.setting.findFirst();
- if (isAutoUpdateEnabled) {
- const versions = await got
- .get(
- `https://get.coollabs.io/versions.json?appId=${process.env['COOLIFY_APP_ID']}&version=${currentVersion}`
- )
- .json();
- const latestVersion = versions['coolify'].main.version;
- const isUpdateAvailable = compare(latestVersion, currentVersion);
- if (isUpdateAvailable === 1) {
- const activeCount = await buildQueue.getActiveCount();
- if (activeCount === 0) {
- if (!dev) {
- console.log('Updating...');
- await asyncExecShell(`docker pull coollabsio/coolify:${latestVersion}`);
- await asyncExecShell(`env | grep COOLIFY > .env`);
- 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"`
- );
- } else {
- console.log('Updating (not really in dev mode).');
+ try {
+ const currentVersion = version;
+ const { isAutoUpdateEnabled } = await prisma.setting.findFirst();
+ if (isAutoUpdateEnabled) {
+ const versions = await got
+ .get(
+ `https://get.coollabs.io/versions.json?appId=${process.env['COOLIFY_APP_ID']}&version=${currentVersion}`
+ )
+ .json();
+ const latestVersion = versions['coolify'].main.version;
+ const isUpdateAvailable = compare(latestVersion, currentVersion);
+ if (isUpdateAvailable === 1) {
+ const activeCount = await buildQueue.getActiveCount();
+ if (activeCount === 0) {
+ if (!dev) {
+ await buildQueue.pause();
+ console.log(`Updating Coolify to ${latestVersion}.`);
+ await asyncExecShell(`docker pull coollabsio/coolify:${latestVersion}`);
+ await asyncExecShell(`env | grep COOLIFY > .env`);
+ 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"`
+ );
+ } else {
+ await buildQueue.pause();
+ 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);
}
}
diff --git a/src/lib/queues/index.ts b/src/lib/queues/index.ts
index 5f8ebfb11a..60097680da 100644
--- a/src/lib/queues/index.ts
+++ b/src/lib/queues/index.ts
@@ -130,6 +130,9 @@ const buildWorker = new Worker(buildQueueName, async (job) => await builder(job)
concurrency: 1,
...connectionOptions
});
+buildQueue.resume().catch((err) => {
+ console.log('Build queue failed to resume!', err);
+});
buildWorker.on('completed', async (job: Bullmq.Job) => {
try {
@@ -138,7 +141,6 @@ buildWorker.on('completed', async (job: Bullmq.Job) => {
setTimeout(async () => {
await prisma.build.update({ where: { id: job.data.build_id }, data: { status: 'success' } });
}, 1234);
- console.log(error);
} finally {
const workdir = `/tmp/build-sources/${job.data.repository}/${job.data.build_id}`;
if (!dev) await asyncExecShell(`rm -fr ${workdir}`);
@@ -154,7 +156,6 @@ buildWorker.on('failed', async (job: Bullmq.Job, failedReason) => {
setTimeout(async () => {
await prisma.build.update({ where: { id: job.data.build_id }, data: { status: 'failed' } });
}, 1234);
- console.log(error);
} finally {
const workdir = `/tmp/build-sources/${job.data.repository}`;
if (!dev) await asyncExecShell(`rm -fr ${workdir}`);
diff --git a/src/routes/settings/index.svelte b/src/routes/settings/index.svelte
index 5040089ba1..500fc1943e 100644
--- a/src/routes/settings/index.svelte
+++ b/src/routes/settings/index.svelte
@@ -194,14 +194,16 @@
on:click={() => changeSettings('isRegistrationEnabled')}
/>
</div>
- <div class="grid grid-cols-2 items-center">
- <Setting
- bind:setting={isAutoUpdateEnabled}
- title={$t('setting.auto_update_enabled')}
- description={$t('setting.auto_update_enabled_explainer')}
- on:click={() => changeSettings('isAutoUpdateEnabled')}
- />
- </div>
+ {#if browser && window.location.hostname === 'staging.coolify.io'}
+ <div class="grid grid-cols-2 items-center">
+ <Setting
+ bind:setting={isAutoUpdateEnabled}
+ title={$t('setting.auto_update_enabled')}
+ description={$t('setting.auto_update_enabled_explainer')}
+ on:click={() => changeSettings('isAutoUpdateEnabled')}
+ />
+ </div>
+ {/if}
</div>
</form>
<div class="flex space-x-1 pt-6 font-bold">