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.

plausible migration done

Andras Bacsai877577efdbd4
diff --git a/apps/api/src/index.ts b/apps/api/src/index.ts
index 21185a6d47..477406e65a 100644
--- a/apps/api/src/index.ts
+++ b/apps/api/src/index.ts
@@ -6,7 +6,7 @@ import cookie from '@fastify/cookie';
import multipart from '@fastify/multipart';
import path, { join } from 'path';
import autoLoad from '@fastify/autoload';
-import { asyncExecShell, cleanupDockerStorage, createRemoteEngineConfiguration, decrypt, executeDockerCmd, executeSSHCmd, generateDatabaseConfiguration, getDomain, isDev, listSettings, prisma, startTraefikProxy, startTraefikTCPProxy, version } from './lib/common';
+import { asyncExecShell, cleanupDockerStorage, createRemoteEngineConfiguration, decrypt, encrypt, executeDockerCmd, executeSSHCmd, generateDatabaseConfiguration, getDomain, isDev, listSettings, prisma, startTraefikProxy, startTraefikTCPProxy, version } from './lib/common';
import { scheduler } from './lib/scheduler';
import { compareVersions } from 'compare-versions';
import Graceful from '@ladjs/graceful'
@@ -14,6 +14,7 @@ import axios from 'axios';
import fs from 'fs/promises';
import { verifyRemoteDockerEngineFn } from './routes/api/v1/destinations/handlers';
import { checkContainer } from './lib/docker';
+import { includeServices } from './lib/services/common';
declare module 'fastify' {
interface FastifyInstance {
config: {
@@ -122,6 +123,7 @@ const host = '0.0.0.0';
}
})
try {
+ await migrateServicesToNewTemplate()
await fastify.listen({ port, host })
console.log(`Coolify's API is listening on ${host}:${port}`);
await initServer();
@@ -159,6 +161,7 @@ const host = '0.0.0.0';
getArch(),
getIPAddress(),
configureRemoteDockers(),
+
])
} catch (error) {
console.error(error);
@@ -166,7 +169,44 @@ const host = '0.0.0.0';
}
})();
+async function migrateServicesToNewTemplate() {
+ // This function migrates old hardcoded services to the new template based services
+ try {
+ const services = await prisma.service.findMany({ include: includeServices })
+ for (const service of services) {
+ if (service.type === 'plausibleanalytics') {
+ const { email = '[email protected]', username = 'admin', password, postgresqlUser, postgresqlPassword, postgresqlDatabase, secretKeyBase, scriptName } = service.plausibleAnalytics;
+
+ // Migrate Secrets
+ await prisma.serviceSecret.create({ data: { name: 'ADMIN_USER_PWD', value: password, service: { connect: { id: service.id } } } })
+ await prisma.serviceSecret.create({ data: { name: 'SECRET_KEY_BASE', value: secretKeyBase, service: { connect: { id: service.id } } } })
+ await prisma.serviceSecret.create({ data: { name: 'POSTGRESQL_PASSWORD', value: postgresqlPassword, service: { connect: { id: service.id } } } })
+ await prisma.serviceSecret.create({ data: { name: 'DATABASE_URL', value: encrypt(`postgresql://${postgresqlUser}:${decrypt(postgresqlPassword)}@${service.id}-postgresql:5432/${postgresqlDatabase}`), service: { connect: { id: service.id } } } })
+ await prisma.serviceSecret.create({ data: { name: 'CLICKHOUSE_DATABASE_URL', value: encrypt(`http://${service.id}-clickhouse:8123/plausible`), service: { connect: { id: service.id } } } })
+
+ // Migrate Configs
+ await prisma.serviceSetting.create({ data: { name: 'BASE_URL', value: '$$generate_fqdn', service: { connect: { id: service.id } } } })
+ await prisma.serviceSetting.create({ data: { name: 'ADMIN_USER_EMAIL', value: email, service: { connect: { id: service.id } } } })
+ await prisma.serviceSetting.create({ data: { name: 'ADMIN_USER_NAME', value: username, service: { connect: { id: service.id } } } })
+ await prisma.serviceSetting.create({ data: { name: 'DISABLE_AUTH', value: 'false', service: { connect: { id: service.id } } } })
+ await prisma.serviceSetting.create({ data: { name: 'DISABLE_REGISTRATION', value: 'true', service: { connect: { id: service.id } } } })
+ await prisma.serviceSetting.create({ data: { name: 'POSTGRESQL_USERNAME', value: postgresqlUser, service: { connect: { id: service.id } } } })
+ await prisma.serviceSetting.create({ data: { name: 'POSTGRESQL_DATABASE', value: postgresqlDatabase, service: { connect: { id: service.id } } } })
+ await prisma.serviceSetting.create({ data: { name: 'SCRIPT_NAME', value: scriptName, service: { connect: { id: service.id } } } })
+
+ // Create predefined persistent volumes
+ await prisma.servicePersistentStorage.create({ data: { path: '/bitnami/postgresql', containerId: `${service.id}-postgresql`, volumeName: `${service.id}-postgresql-data`, predefined: true, service: { connect: { id: service.id } } } })
+ await prisma.servicePersistentStorage.create({ data: { path: '/var/lib/clickhouse', containerId: `${service.id}-clickhouse`, volumeName: `${service.id}-clickhouse-data`, predefined: true, service: { connect: { id: service.id } } } })
+
+ // Remove old service data
+ await prisma.service.update({ where: { id: service.id }, data: { plausibleAnalytics: { delete: true } } })
+ }
+ }
+ } catch (error) {
+ console.log(error)
+ }
+}
async function getIPAddress() {
const { publicIpv4, publicIpv6 } = await import('public-ip')
try {
diff --git a/apps/api/src/lib/templates.ts b/apps/api/src/lib/templates.ts
index 92b0b2d16b..2454f0ab7b 100644
--- a/apps/api/src/lib/templates.ts
+++ b/apps/api/src/lib/templates.ts
@@ -69,7 +69,7 @@ export default [
"documentation": "Taken from https://plausible.io/",
"image": "bitnami/postgresql:13.2.0",
"volumes": [
- '$$id-postgresql-data:/bitnami/postgresql/',
+ '$$id-postgresql-data:/bitnami/postgresql',
],
"environment": [
"POSTGRESQL_PASSWORD=$$secret_postgresql_password",
diff --git a/apps/api/src/routes/api/v1/services/handlers.ts b/apps/api/src/routes/api/v1/services/handlers.ts
index ec723a30b4..732b9f01f5 100644
--- a/apps/api/src/routes/api/v1/services/handlers.ts
+++ b/apps/api/src/routes/api/v1/services/handlers.ts
@@ -68,10 +68,6 @@ export async function getServiceStatus(request: FastifyRequest<OnlyId>) {
try {
const teamId = request.user.teamId;
const { id } = request.params;
-
- let isRunning = false;
- let isExited = false
- let isRestarting = false;
const service = await getServiceFromDB({ id, teamId });
const { destinationDockerId, settings } = service;
let payload = {}
diff --git a/apps/ui/src/routes/applications/[id]/__layout.svelte b/apps/ui/src/routes/applications/[id]/__layout.svelte
index e10ee15d62..697f499870 100644
--- a/apps/ui/src/routes/applications/[id]/__layout.svelte
+++ b/apps/ui/src/routes/applications/[id]/__layout.svelte
@@ -323,11 +323,11 @@
on:click={stopApplication}
type="submit"
disabled={!$isDeploymentEnabled}
- class="btn btn-sm btn-error gap-2"
+ class="btn btn-sm gap-2"
>
<svg
xmlns="http://www.w3.org/2000/svg"
- class="w-6 h-6 "
+ class="w-6 h-6 text-error"
viewBox="0 0 24 24"
stroke-width="1.5"
stroke="currentColor"
@@ -393,11 +393,11 @@
on:click={stopApplication}
type="submit"
disabled={!$isDeploymentEnabled}
- class="btn btn-sm btn-error gap-2"
+ class="btn btn-sm gap-2"
>
<svg
xmlns="http://www.w3.org/2000/svg"
- class="w-6 h-6 "
+ class="w-6 h-6 text-error"
viewBox="0 0 24 24"
stroke-width="1.5"
stroke="currentColor"
diff --git a/apps/ui/src/routes/services/[id]/__layout.svelte b/apps/ui/src/routes/services/[id]/__layout.svelte
index 40057aa506..b57dafdafb 100644
--- a/apps/ui/src/routes/services/[id]/__layout.svelte
+++ b/apps/ui/src/routes/services/[id]/__layout.svelte
@@ -280,11 +280,11 @@
on:click={stopService}
type="submit"
disabled={!$isDeploymentEnabled}
- class="btn btn-sm btn-error gap-2"
+ class="btn btn-sm gap-2"
>
<svg
xmlns="http://www.w3.org/2000/svg"
- class="w-6 h-6 "
+ class="w-6 h-6 text-error "
viewBox="0 0 24 24"
stroke-width="1.5"
stroke="currentColor"
@@ -293,7 +293,8 @@
stroke-linejoin="round"
>
<path stroke="none" d="M0 0h24v24H0z" fill="none" />
- <rect x="5" y="5" width="14" height="14" rx="2" />
+ <rect x="6" y="5" width="4" height="14" rx="1" />
+ <rect x="14" y="5" width="4" height="14" rx="1" />
</svg>
Stop
</button>