diff --git a/apps/api/src/index.ts b/apps/api/src/index.ts index c760116b0..b9d0fb884 100644 --- a/apps/api/src/index.ts +++ b/apps/api/src/index.ts @@ -173,7 +173,13 @@ const host = '0.0.0.0'; // Refresh and check templates setInterval(async () => { await refreshTemplates() + }, 60000) + + setInterval(async () => { await refreshTags() + }, 60000) + + setInterval(async () => { await migrateServicesToNewTemplate() }, 60000) diff --git a/apps/api/src/lib.ts b/apps/api/src/lib.ts index 135ccd255..0d2fdec13 100644 --- a/apps/api/src/lib.ts +++ b/apps/api/src/lib.ts @@ -1,5 +1,5 @@ import cuid from "cuid"; -import { decrypt, encrypt, fixType, generatePassword, getDomain, prisma } from "./lib/common"; +import { decrypt, encrypt, fixType, generatePassword, prisma } from "./lib/common"; import { getTemplates } from "./lib/services"; export async function migrateServicesToNewTemplate() { @@ -253,6 +253,8 @@ async function umami(service: any, template: any) { await migrateSettings(settings, service, template); await migrateSecrets(secrets, service); + await prisma.service.update({ where: { id: service.id }, data: { type: "umami-postgresql" } }) + // Disconnect old service data // await prisma.service.update({ where: { id: service.id }, data: { umami: { disconnect: true } } }) } @@ -440,33 +442,41 @@ async function plausibleAnalytics(service: any, template: any) { async function migrateSettings(settings: any[], service: any, template: any) { for (const setting of settings) { - if (!setting) continue; - let [name, value] = setting.split('@@@') - let minio = name - if (name === 'MINIO_SERVER_URL') { - name = 'coolify_fqdn_minio_console' + try { + if (!setting) continue; + let [name, value] = setting.split('@@@') + let minio = name + if (name === 'MINIO_SERVER_URL') { + name = 'coolify_fqdn_minio_console' + } + if (!value || value === 'null') { + continue; + } + let variableName = template.variables.find((v: any) => v.name === name)?.id + if (!variableName) { + variableName = `$$config_${name.toLowerCase()}` + } + // console.log('Migrating setting', name, value, 'for service', service.id, ', service name:', service.name, 'variableName: ', variableName) + + await prisma.serviceSetting.findFirst({ where: { name: minio, serviceId: service.id } }) || await prisma.serviceSetting.create({ data: { name: minio, value, variableName, service: { connect: { id: service.id } } } }) + } catch(error) { + console.log(error) } - if (!value || value === 'null') { - continue; - } - let variableName = template.variables.find((v: any) => v.name === name)?.id - if (!variableName) { - variableName = `$$config_${name.toLowerCase()}` - } - // console.log('Migrating setting', name, value, 'for service', service.id, ', service name:', service.name, 'variableName: ', variableName) - - await prisma.serviceSetting.findFirst({ where: { name: minio, serviceId: service.id } }) || await prisma.serviceSetting.create({ data: { name: minio, value, variableName, service: { connect: { id: service.id } } } }) } } async function migrateSecrets(secrets: any[], service: any) { for (const secret of secrets) { - if (!secret) continue; - let [name, value] = secret.split('@@@') - if (!value || value === 'null') { - continue + try { + if (!secret) continue; + let [name, value] = secret.split('@@@') + if (!value || value === 'null') { + continue + } + // console.log('Migrating secret', name, value, 'for service', service.id, ', service name:', service.name) + await prisma.serviceSecret.findFirst({ where: { name, serviceId: service.id } }) || await prisma.serviceSecret.create({ data: { name, value, service: { connect: { id: service.id } } } }) + } catch(error) { + console.log(error) } - // console.log('Migrating secret', name, value, 'for service', service.id, ', service name:', service.name) - await prisma.serviceSecret.findFirst({ where: { name, serviceId: service.id } }) || await prisma.serviceSecret.create({ data: { name, value, service: { connect: { id: service.id } } } }) } } async function createVolumes(service: any, template: any) { diff --git a/apps/api/src/lib/common.ts b/apps/api/src/lib/common.ts index bef6a6c43..d0e296ce6 100644 --- a/apps/api/src/lib/common.ts +++ b/apps/api/src/lib/common.ts @@ -17,7 +17,7 @@ import { day } from './dayjs'; import { saveBuildLog } from './buildPacks/common'; import { scheduler } from './scheduler'; -export const version = '3.11.1'; +export const version = '3.11.2'; export const isDev = process.env.NODE_ENV === 'development'; const algorithm = 'aes-256-ctr'; diff --git a/apps/api/src/routes/api/v1/handlers.ts b/apps/api/src/routes/api/v1/handlers.ts index eff8532a3..ffd3ddb05 100644 --- a/apps/api/src/routes/api/v1/handlers.ts +++ b/apps/api/src/routes/api/v1/handlers.ts @@ -49,10 +49,6 @@ export async function refreshTags() { } } catch (error) { console.log(error) - throw { - status: 500, - message: 'Could not fetch templates from get.coollabs.io' - }; } return {}; @@ -73,12 +69,7 @@ export async function refreshTemplates() { } } catch (error) { console.log(error) - throw { - status: 500, - message: 'Could not fetch templates from get.coollabs.io' - }; } - return {}; } catch ({ status, message }) { return errorHandler({ status, message }); diff --git a/apps/api/src/routes/api/v1/index.ts b/apps/api/src/routes/api/v1/index.ts index 7f0c6c61c..6ec94e479 100644 --- a/apps/api/src/routes/api/v1/index.ts +++ b/apps/api/src/routes/api/v1/index.ts @@ -1,5 +1,5 @@ import { FastifyPluginAsync } from 'fastify'; -import { checkUpdate, login, showDashboard, update, resetQueue, getCurrentUser, cleanupManually, restartCoolify, refreshTemplates } from './handlers'; +import { checkUpdate, login, showDashboard, update, resetQueue, getCurrentUser, cleanupManually, restartCoolify } from './handlers'; import { GetCurrentUser } from './types'; export interface Update { @@ -52,10 +52,6 @@ const root: FastifyPluginAsync = async (fastify): Promise => { fastify.post('/internal/cleanup', { onRequest: [fastify.authenticate] }, async (request) => await cleanupManually(request)); - - fastify.post('/internal/refreshTemplates', { - onRequest: [fastify.authenticate] - }, async () => await refreshTemplates()); }; export default root; diff --git a/apps/ui/src/routes/services/[id]/__layout.svelte b/apps/ui/src/routes/services/[id]/__layout.svelte index 536b8ab75..788c4dc94 100644 --- a/apps/ui/src/routes/services/[id]/__layout.svelte +++ b/apps/ui/src/routes/services/[id]/__layout.svelte @@ -79,9 +79,7 @@ $isDeploymentEnabled = checkIfDeploymentEnabledServices($appSession.isAdmin, service); let statusInterval: any; - let loading = { - refreshTemplates: false - }; + async function deleteService() { const sure = confirm($t('application.confirm_to_delete', { name: service.name })); @@ -106,20 +104,6 @@ await startService(); } } - async function refreshTemplate() { - try { - loading.refreshTemplates = true; - await post(`/internal/refreshTemplates`, {}); - addToast({ - message: 'Services refreshed.', - type: 'success' - }); - } catch (error) { - return errorNotification(error); - } finally { - loading.refreshTemplates = false; - } - } async function stopService(skip = false) { if (skip) { $status.service.initialLoading = true; @@ -278,14 +262,6 @@ Delete Service {/if} - {#if $page.url.pathname === `/services/${id}/configuration/type` && dev} - - {/if}