From cbaecff3b727ecb604a6e449a82096fc9cd8684e Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Wed, 19 Oct 2022 10:55:16 +0200 Subject: [PATCH] meilisearch --- apps/api/src/lib.ts | 37 ++++++++++++------- apps/api/src/lib/templates.ts | 8 ++-- .../src/routes/api/v1/services/handlers.ts | 2 +- .../src/routes/services/[id]/_Storage.svelte | 4 +- apps/ui/src/routes/services/[id]/index.svelte | 2 +- 5 files changed, 33 insertions(+), 20 deletions(-) diff --git a/apps/api/src/lib.ts b/apps/api/src/lib.ts index 0eefbf2a9..5e76e986b 100644 --- a/apps/api/src/lib.ts +++ b/apps/api/src/lib.ts @@ -1,6 +1,6 @@ import { decrypt, encrypt, getDomain, prisma } from "./lib/common"; import { includeServices } from "./lib/services/common"; - +import templates from "./lib/templates"; export async function migrateServicesToNewTemplate() { // This function migrates old hardcoded services to the new template based services @@ -13,8 +13,8 @@ export async function migrateServicesToNewTemplate() { if (service.type === 'vscodeserver' && service.vscodeserver) await vscodeserver(service) if (service.type === 'wordpress' && service.wordpress) await wordpress(service) if (service.type === 'ghost' && service.ghost) await ghost(service) - if (service.type === 'meilisearch' && service.meilisearch) await meilisearch(service) - + if (service.type === 'meilisearch' && service.meiliSearch) await meilisearch(service) + await createVolumes(service); } } catch (error) { console.log(error) @@ -23,7 +23,7 @@ export async function migrateServicesToNewTemplate() { } async function meilisearch(service: any) { - const { masterKey } = service.meilisearch + const { masterKey } = service.meiliSearch const secrets = [ `MEILI_MASTER_KEY@@@${masterKey}`, @@ -173,13 +173,9 @@ async function plausibleAnalytics(service: any) { `POSTGRES_PASSWORD@@@${postgresqlPassword}`, `DATABASE_URL@@@${encrypt(`postgres://${postgresqlUser}:${decrypt(postgresqlPassword)}@$$generate_fqdn:5432/${postgresqlDatabase}`)}`, ] - const volumes = [ - `${service.id}-postgresql-data@@@/bitnami/postgresql@@@${service.id}-postgresql`, - `${service.id}-clickhouse-data@@@/var/lib/clickhouse/data@@@${service.id}-clickhouse`, - ] await migrateSettings(settings, service); await migrateSecrets(secrets, service); - await createVolumes(volumes, service); + await createVolumes(service); // Remove old service data // await prisma.service.update({ where: { id: service.id }, data: { plausibleAnalytics: { delete: true } } }) @@ -189,7 +185,7 @@ async function migrateSettings(settings: any[], service: any) { for (const setting of settings) { if (!setting) continue; const [name, value] = setting.split('@@@') - console.log('Migrating setting', name, value, 'for service', service.id, ', service name:', service.name) + // console.log('Migrating setting', name, value, 'for service', service.id, ', service name:', service.name) await prisma.serviceSetting.findFirst({ where: { name, serviceId: service.id } }) || await prisma.serviceSetting.create({ data: { name, value, service: { connect: { id: service.id } } } }) } } @@ -197,14 +193,29 @@ async function migrateSecrets(secrets: any[], service: any) { for (const secret of secrets) { if (!secret) continue; const [name, value] = secret.split('@@@') - console.log('Migrating secret', name, value, 'for service', service.id, ', service name:', service.name) + // 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(volumes: any[], service: any) { +async function createVolumes(service: any) { + const volumes = []; + let template = templates.find(t => t.name === service.type) + if (template) { + template = JSON.parse(JSON.stringify(template).replaceAll('$$id', service.id)) + for (const s of Object.keys(template.services)) { + if (template.services[s].volumes && template.services[s].volumes.length > 0) { + for (const volume of template.services[s].volumes) { + const volumeName = volume.split(':')[0] + const volumePath = volume.split(':')[1] + const volumeService = service.id + volumes.push(`${volumeName}@@@${volumePath}@@@${volumeService}`) + } + } + } + } for (const volume of volumes) { const [volumeName, path, containerId] = volume.split('@@@') - console.log('Creating volume', volumeName, path, containerId, 'for service', service.id, ', service name:', service.name) + // console.log('Creating volume', volumeName, path, containerId, 'for service', service.id, ', service name:', service.name) await prisma.servicePersistentStorage.findFirst({ where: { volumeName, serviceId: service.id } }) || await prisma.servicePersistentStorage.create({ data: { volumeName, path, containerId, predefined: true, service: { connect: { id: service.id } } } }) } } \ No newline at end of file diff --git a/apps/api/src/lib/templates.ts b/apps/api/src/lib/templates.ts index 7de4c54af..08350e56c 100644 --- a/apps/api/src/lib/templates.ts +++ b/apps/api/src/lib/templates.ts @@ -1,7 +1,7 @@ export default [ { "templateVersion": "1.0.0", - "serviceDefaultVersion": "latest", + "serviceDefaultVersion": "v0.29.1", "name": "meilisearch", "displayName": "MeiliSearch", "description": "MeiliSearch is a lightning Fast, Ultra Relevant, and Typo-Tolerant Search Engine", @@ -26,7 +26,6 @@ export default [ "7700" ] } - }, "variables": [ { @@ -34,7 +33,10 @@ export default [ "name": "MEILI_MASTER_KEY", "label": "Master Key", "defaultValue": "$$generate_passphrase", - "description": "" + "description": "", + "extras": { + "isVisibleOnUI": true, + } } ] }, diff --git a/apps/api/src/routes/api/v1/services/handlers.ts b/apps/api/src/routes/api/v1/services/handlers.ts index 903f48c52..1a6c8bc79 100644 --- a/apps/api/src/routes/api/v1/services/handlers.ts +++ b/apps/api/src/routes/api/v1/services/handlers.ts @@ -142,7 +142,7 @@ export async function parseAndFindServiceTemplates(service: any, workdir?: strin parsedTemplate = foundTemplate } // replace $$id and $$workdir - parsedTemplate = JSON.parse(JSON.stringify(parsedTemplate).replaceAll('$$id', service.id).replaceAll('$$core_version', foundTemplate.serviceDefaultVersion)) + parsedTemplate = JSON.parse(JSON.stringify(parsedTemplate).replaceAll('$$id', service.id).replaceAll('$$core_version', service.version || foundTemplate.serviceDefaultVersion)) // replace $$fqdn if (workdir) { diff --git a/apps/ui/src/routes/services/[id]/_Storage.svelte b/apps/ui/src/routes/services/[id]/_Storage.svelte index a7c8a155b..8db7d59f7 100644 --- a/apps/ui/src/routes/services/[id]/_Storage.svelte +++ b/apps/ui/src/routes/services/[id]/_Storage.svelte @@ -64,11 +64,11 @@
diff --git a/apps/ui/src/routes/services/[id]/index.svelte b/apps/ui/src/routes/services/[id]/index.svelte index 1ebb4a08d..747deebf2 100644 --- a/apps/ui/src/routes/services/[id]/index.svelte +++ b/apps/ui/src/routes/services/[id]/index.svelte @@ -428,7 +428,7 @@ - {:else if variable.defaultValue === '$$generate_password'} + {:else if variable.defaultValue === '$$generate_password' || variable.defaultValue === '$$generate_passphrase'}