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.

Merged v2.4.0

dominicbachmann9da08d600bf4
diff --cc src/lib/database/applications.ts
index 42887905e3,1c6e172c2a..0f432b5d34
--- a/src/lib/database/applications.ts
+++ b/src/lib/database/applications.ts
@@@ -1,29 -1,20 +1,35 @@@
import { decrypt, encrypt } from '$lib/crypto';
import { asyncExecShell, getEngine } from '$lib/common';
-import { getDomain, removeDestinationDocker } from '$lib/common';
+import { removeDestinationDocker } from '$lib/common';
import { prisma } from './common';
-export async function listApplications(teamId) {
+import type {
+ DestinationDocker,
+ GitSource,
+ Secret,
+ ApplicationSettings,
+ Application,
+ ApplicationPersistentStorage
+} from '@prisma/client';
+
+export async function listApplications(teamId: string): Promise<Application[]> {
- return await prisma.application.findMany({ where: { teams: { some: { id: teamId } } } });
+ if (teamId === '0') {
+ return await prisma.application.findMany({ include: { teams: true } });
+ }
+ return await prisma.application.findMany({
+ where: { teams: { some: { id: teamId } } },
+ include: { teams: true }
+ });
}
-export async function newApplication({ name, teamId }) {
+export async function newApplication({
+ name,
+ teamId
+}: {
+ name: string;
+ teamId: string;
+}): Promise<Application> {
return await prisma.application.create({
data: {
name,
@@@ -132,32 -127,39 +138,40 @@@ export async function getApplicationWeb
throw { status: 404, body: { message: e.message } };
}
}
-export async function getApplicationById({ id }) {
- const body = await prisma.application.findFirst({
- where: { id },
- include: { destinationDocker: true }
- });
- export async function getApplication({
- id,
- teamId
- }: {
- id: string;
- teamId: string;
- }): Promise<
- return { ...body };
-}
-export async function getApplication({ id, teamId }) {
- let body = {};
++export async function getApplication({ id, teamId }: { id: string; teamId: string }): Promise<
+ Application & {
+ destinationDocker: DestinationDocker;
+ settings: ApplicationSettings;
+ gitSource: GitSource;
+ secrets: Secret[];
+ persistentStorage: ApplicationPersistentStorage[];
+ }
+> {
- const body = await prisma.application.findFirst({
- where: { id, teams: { some: { id: teamId } } },
- include: {
- destinationDocker: true,
- settings: true,
- gitSource: { include: { githubApp: true, gitlabApp: true } },
- secrets: true,
- persistentStorage: true
- }
- });
++ let body;
+ if (teamId === '0') {
+ body = await prisma.application.findFirst({
+ where: { id },
+ include: {
+ destinationDocker: true,
+ settings: true,
+ gitSource: { include: { githubApp: true, gitlabApp: true } },
+ secrets: true,
+ persistentStorage: true
+ }
+ });
+ } else {
+ body = await prisma.application.findFirst({
+ where: { id, teams: { some: { id: teamId } } },
+ include: {
+ destinationDocker: true,
+ settings: true,
+ gitSource: { include: { githubApp: true, gitlabApp: true } },
+ secrets: true,
+ persistentStorage: true
+ }
+ });
+ }
if (body?.gitSource?.githubApp?.clientSecret) {
body.gitSource.githubApp.clientSecret = decrypt(body.gitSource.githubApp.clientSecret);
diff --cc src/lib/database/common.ts
index 7c34aa235b,287dcd834e..541fb86851
--- a/src/lib/database/common.ts
+++ b/src/lib/database/common.ts
@@@ -1,8 -1,12 +1,12 @@@
import { dev } from '$app/env';
import { sentry } from '$lib/common';
+ import {
+ supportedDatabaseTypesAndVersions,
+ supportedServiceTypesAndVersions
+ } from '$lib/components/common';
import * as Prisma from '@prisma/client';
import { default as ProdPrisma } from '@prisma/client';
-import type { PrismaClientOptions } from '@prisma/client/runtime';
+import type { Database, DatabaseSettings } from '@prisma/client';
import generator from 'generate-password';
import forge from 'node-forge';
@@@ -87,135 -86,7 +91,7 @@@ export async function generateSshKeyPai
});
}
- export const supportedDatabaseTypesAndVersions = [
- {
- name: 'mongodb',
- fancyName: 'MongoDB',
- baseImage: 'bitnami/mongodb',
- versions: ['5.0.5', '4.4.11', '4.2.18', '4.0.27']
- },
- { name: 'mysql', fancyName: 'MySQL', baseImage: 'bitnami/mysql', versions: ['8.0.27', '5.7.36'] },
- {
- name: 'postgresql',
- fancyName: 'PostgreSQL',
- baseImage: 'bitnami/postgresql',
- versions: ['14.1.0', '13.5.0', '12.9.0', '11.14.0', '10.19.0', '9.6.24']
- },
- {
- name: 'redis',
- fancyName: 'Redis',
- baseImage: 'bitnami/redis',
- versions: ['6.2.6', '6.0.16', '5.0.14']
- },
- { name: 'couchdb', fancyName: 'CouchDB', baseImage: 'bitnami/couchdb', versions: ['3.2.1'] }
- ];
- export const supportedServiceTypesAndVersions = [
- {
- name: 'plausibleanalytics',
- fancyName: 'Plausible Analytics',
- baseImage: 'plausible/analytics',
- images: ['bitnami/postgresql:13.2.0', 'yandex/clickhouse-server:21.3.2.5'],
- versions: ['latest'],
- ports: {
- main: 8000
- }
- },
- {
- name: 'nocodb',
- fancyName: 'NocoDB',
- baseImage: 'nocodb/nocodb',
- versions: ['latest'],
- ports: {
- main: 8080
- }
- },
- {
- name: 'minio',
- fancyName: 'MinIO',
- baseImage: 'minio/minio',
- versions: ['latest'],
- ports: {
- main: 9001
- }
- },
- {
- name: 'vscodeserver',
- fancyName: 'VSCode Server',
- baseImage: 'codercom/code-server',
- versions: ['latest'],
- ports: {
- main: 8080
- }
- },
- {
- name: 'wordpress',
- fancyName: 'Wordpress',
- baseImage: 'wordpress',
- images: ['bitnami/mysql:5.7'],
- versions: ['latest', 'php8.1', 'php8.0', 'php7.4', 'php7.3'],
- ports: {
- main: 80
- }
- },
- {
- name: 'vaultwarden',
- fancyName: 'Vaultwarden',
- baseImage: 'vaultwarden/server',
- versions: ['latest'],
- ports: {
- main: 80
- }
- },
- {
- name: 'languagetool',
- fancyName: 'LanguageTool',
- baseImage: 'silviof/docker-languagetool',
- versions: ['latest'],
- ports: {
- main: 8010
- }
- },
- {
- name: 'n8n',
- fancyName: 'n8n',
- baseImage: 'n8nio/n8n',
- versions: ['latest'],
- ports: {
- main: 5678
- }
- },
- {
- name: 'uptimekuma',
- fancyName: 'Uptime Kuma',
- baseImage: 'louislam/uptime-kuma',
- versions: ['latest'],
- ports: {
- main: 3001
- }
- },
- {
- name: 'ghost',
- fancyName: 'Ghost',
- baseImage: 'bitnami/ghost',
- images: ['bitnami/mariadb'],
- versions: ['latest'],
- ports: {
- main: 2368
- }
- },
- {
- name: 'meilisearch',
- fancyName: 'Meilisearch',
- baseImage: 'getmeili/meilisearch',
- images: [],
- versions: ['latest'],
- ports: {
- main: 7700
- }
- }
- ];
-
-export function getVersions(type) {
+export function getVersions(type: string): string[] {
const found = supportedDatabaseTypesAndVersions.find((t) => t.name === type);
if (found) {
return found.versions;
diff --cc src/lib/database/databases.ts
index 6080b5a20b,7fc2379442..78b39e1871
--- a/src/lib/database/databases.ts
+++ b/src/lib/database/databases.ts
@@@ -1,21 -1,22 +1,28 @@@
import { decrypt, encrypt } from '$lib/crypto';
-import * as db from '$lib/database';
import cuid from 'cuid';
import { generatePassword } from '.';
-import { prisma, ErrorHandler } from './common';
-import getPort, { portNumbers } from 'get-port';
+import { prisma } from './common';
import { asyncExecShell, getEngine, removeContainer } from '$lib/common';
+import type { Database, DatabaseSettings, DestinationDocker } from '@prisma/client';
-export async function listDatabases(teamId) {
+export async function listDatabases(teamId: string): Promise<Database[]> {
- return await prisma.database.findMany({ where: { teams: { some: { id: teamId } } } });
+ if (teamId === '0') {
+ return await prisma.database.findMany({ include: { teams: true } });
+ } else {
+ return await prisma.database.findMany({
+ where: { teams: { some: { id: teamId } } },
+ include: { teams: true }
+ });
+ }
}
-export async function newDatabase({ name, teamId }) {
+
+export async function newDatabase({
+ name,
+ teamId
+}: {
+ name: string;
+ teamId: string;
+}): Promise<Database> {
const dbUser = cuid();
const dbUserPassword = encrypt(generatePassword());
const rootUser = cuid();
@@@ -36,18 -37,20 +43,25 @@@
});
}
-export async function getDatabase({ id, teamId }) {
- let body = {};
+export async function getDatabase({
+ id,
+ teamId
+}: {
+ id: string;
+ teamId: string;
+}): Promise<Database & { destinationDocker: DestinationDocker; settings: DatabaseSettings }> {
- const body = await prisma.database.findFirst({
- where: { id, teams: { some: { id: teamId } } },
- include: { destinationDocker: true, settings: true }
- });
-
++ let body;
+ if (teamId === '0') {
+ body = await prisma.database.findFirst({
+ where: { id },
+ include: { destinationDocker: true, settings: true }
+ });
+ } else {
+ body = await prisma.database.findFirst({
+ where: { id, teams: { some: { id: teamId } } },
+ include: { destinationDocker: true, settings: true }
+ });
+ }
-
if (body.dbUserPassword) body.dbUserPassword = decrypt(body.dbUserPassword);
if (body.rootUserPassword) body.rootUserPassword = decrypt(body.rootUserPassword);
diff --cc src/lib/database/destinations.ts
index b3f9679c4e,5bd63c81b6..9e126d6bae
--- a/src/lib/database/destinations.ts
+++ b/src/lib/database/destinations.ts
@@@ -1,30 -1,21 +1,35 @@@
import { asyncExecShell, getEngine } from '$lib/common';
- import { decrypt } from '$lib/crypto';
-import { decrypt, encrypt } from '$lib/crypto';
import { dockerInstance } from '$lib/docker';
import { startCoolifyProxy } from '$lib/haproxy';
import { getDatabaseImage } from '.';
import { prisma } from './common';
+import type { DestinationDocker, Service, Application, Prisma } from '@prisma/client';
+import type { CreateDockerDestination } from '$lib/types/destinations';
-export async function listDestinations(teamId) {
+type DestinationConfigurationObject = {
+ id: string;
+ destinationId: string;
+};
+
+type FindDestinationFromTeam = {
+ id: string;
+ teamId: string;
+};
+
+export async function listDestinations(teamId: string): Promise<DestinationDocker[]> {
- return await prisma.destinationDocker.findMany({ where: { teams: { some: { id: teamId } } } });
+ if (teamId === '0') {
+ return await prisma.destinationDocker.findMany({ include: { teams: true } });
+ }
+ return await prisma.destinationDocker.findMany({
+ where: { teams: { some: { id: teamId } } },
+ include: { teams: true }
+ });
}
-export async function configureDestinationForService({ id, destinationId }) {
+export async function configureDestinationForService({
+ id,
+ destinationId
+}: DestinationConfigurationObject): Promise<Service> {
return await prisma.service.update({
where: { id },
data: { destinationDocker: { connect: { id: destinationId } } }
@@@ -142,22 -129,21 +147,27 @@@ export async function removeDestination
}
}
-export async function getDestination({ id, teamId }) {
- let destination = {};
+export async function getDestination({
+ id,
+ teamId
+}: FindDestinationFromTeam): Promise<DestinationDocker & { sshPrivateKey?: string }> {
- const destination = (await prisma.destinationDocker.findFirst({
- where: { id, teams: { some: { id: teamId } } }
- })) as DestinationDocker & { sshPrivateKey?: string };
- if (destination.remoteEngine) {
- destination.sshPrivateKey = decrypt(destination.sshPrivateKey);
++ let destination;
+ if (teamId === '0') {
+ destination = await prisma.destinationDocker.findFirst({
+ where: { id }
+ });
+ } else {
+ destination = await prisma.destinationDocker.findFirst({
+ where: { id, teams: { some: { id: teamId } } }
+ });
}
+
return destination;
}
-export async function getDestinationByApplicationId({ id, teamId }) {
+export async function getDestinationByApplicationId({
+ id,
+ teamId
+}: FindDestinationFromTeam): Promise<DestinationDocker> {
return await prisma.destinationDocker.findFirst({
where: { application: { some: { id } }, teams: { some: { id: teamId } } }
});
diff --cc src/lib/database/gitSources.ts
index 2d165b974c,7e4e90633f..f77df7ae7a
--- a/src/lib/database/gitSources.ts
+++ b/src/lib/database/gitSources.ts
@@@ -1,13 -1,15 +1,18 @@@
import { decrypt, encrypt } from '$lib/crypto';
import { prisma } from './common';
+import type { GithubApp, GitlabApp, GitSource, Prisma, Application } from '@prisma/client';
-export async function listSources(teamId) {
+export async function listSources(
+ teamId: string | Prisma.StringFilter
+): Promise<(GitSource & { githubApp?: GithubApp; gitlabApp?: GitlabApp })[]> {
+ if (teamId === '0') {
+ return await prisma.gitSource.findMany({
+ include: { githubApp: true, gitlabApp: true, teams: true }
+ });
+ }
return await prisma.gitSource.findMany({
where: { teams: { some: { id: teamId } } },
- include: { githubApp: true, gitlabApp: true }
+ include: { githubApp: true, gitlabApp: true, teams: true }
});
}
@@@ -47,17 -35,19 +52,25 @@@ export async function removeSource({ i
if (source.gitlabAppId) await prisma.gitlabApp.delete({ where: { id: source.gitlabAppId } });
}
-export async function getSource({ id, teamId }) {
- let body = {};
+export async function getSource({
+ id,
+ teamId
+}: {
+ id: string;
+ teamId: string;
+}): Promise<GitSource & { githubApp: GithubApp; gitlabApp: GitlabApp }> {
- const body = await prisma.gitSource.findFirst({
- where: { id, teams: { some: { id: teamId } } },
- include: { githubApp: true, gitlabApp: true }
- });
++ let body;
+ if (teamId === '0') {
+ body = await prisma.gitSource.findFirst({
+ where: { id },
+ include: { githubApp: true, gitlabApp: true }
+ });
+ } else {
+ body = await prisma.gitSource.findFirst({
+ where: { id, teams: { some: { id: teamId } } },
+ include: { githubApp: true, gitlabApp: true }
+ });
+ }
if (body?.githubApp?.clientSecret)
body.githubApp.clientSecret = decrypt(body.githubApp.clientSecret);
if (body?.githubApp?.webhookSecret)
diff --cc src/lib/database/services.ts
index 359722bf81,b4d3559466..8f80ebd9fb
--- a/src/lib/database/services.ts
+++ b/src/lib/database/services.ts
@@@ -4,34 -4,44 +4,50 @@@ import cuid from 'cuid'
import { generatePassword } from '.';
import { prisma } from './common';
-export async function listServices(teamId) {
+export async function listServices(teamId: string): Promise<Service[]> {
- return await prisma.service.findMany({ where: { teams: { some: { id: teamId } } } });
+ if (teamId === '0') {
+ return await prisma.service.findMany({ include: { teams: true } });
+ } else {
+ return await prisma.service.findMany({
+ where: { teams: { some: { id: teamId } } },
+ include: { teams: true }
+ });
+ }
}
-export async function newService({ name, teamId }) {
+export async function newService({
+ name,
+ teamId
+}: {
+ name: string;
+ teamId: string;
+}): Promise<Service> {
return await prisma.service.create({ data: { name, teams: { connect: { id: teamId } } } });
}
-export async function getService({ id, teamId }) {
- let body = {};
+export async function getService({ id, teamId }: { id: string; teamId: string }): Promise<Service> {
- const body = await prisma.service.findFirst({
- where: { id, teams: { some: { id: teamId } } },
- include: {
- destinationDocker: true,
- plausibleAnalytics: true,
- minio: true,
- vscodeserver: true,
- wordpress: true,
- ghost: true,
- serviceSecret: true,
- meiliSearch: true
- }
- });
++ let body;
+ const include = {
+ destinationDocker: true,
+ plausibleAnalytics: true,
+ minio: true,
+ vscodeserver: true,
+ wordpress: true,
+ ghost: true,
+ serviceSecret: true,
+ meiliSearch: true
+ };
+ if (teamId === '0') {
+ body = await prisma.service.findFirst({
+ where: { id },
+ include
+ });
+ } else {
+ body = await prisma.service.findFirst({
+ where: { id, teams: { some: { id: teamId } } },
+ include
+ });
+ }
if (body.plausibleAnalytics?.postgresqlPassword)
body.plausibleAnalytics.postgresqlPassword = decrypt(
@@@ -65,17 -75,15 +81,21 @@@
return s;
});
}
+ if (body.wordpress?.ftpPassword) {
+ body.wordpress.ftpPassword = decrypt(body.wordpress.ftpPassword);
+ }
+ const settings = await prisma.setting.findFirst();
- return { ...body };
+ return { ...body, settings };
}
-export async function configureServiceType({ id, type }) {
+export async function configureServiceType({
+ id,
+ type
+}: {
+ id: string;
+ type: string;
+}): Promise<void> {
if (type === 'plausibleanalytics') {
const password = encrypt(generatePassword());
const postgresqlUser = cuid();
@@@ -191,13 -199,7 +211,14 @@@
});
}
}
-export async function setServiceVersion({ id, version }) {
++
+export async function setServiceVersion({
+ id,
+ version
+}: {
+ id: string;
+ version: string;
+}): Promise<Service> {
return await prisma.service.update({
where: { id },
data: { version }
@@@ -233,99 -217,19 +254,107 @@@ export async function updatePlausibleAn
await prisma.plausibleAnalytics.update({ where: { serviceId: id }, data: { email, username } });
await prisma.service.update({ where: { id }, data: { name, fqdn } });
}
-export async function updateService({ id, fqdn, name }) {
++
+export async function updateService({
+ id,
+ fqdn,
+ name
+}: {
+ id: string;
+ fqdn: string;
+ name: string;
+}): Promise<Service> {
+ return await prisma.service.update({ where: { id }, data: { fqdn, name } });
+}
++
+export async function updateLanguageToolService({
+ id,
+ fqdn,
+ name
+}: {
+ id: string;
+ fqdn: string;
+ name: string;
+}): Promise<Service> {
return await prisma.service.update({ where: { id }, data: { fqdn, name } });
}
-export async function updateWordpress({ id, fqdn, name, mysqlDatabase, extraConfig }) {
++
+export async function updateMeiliSearchService({
+ id,
+ fqdn,
+ name
+}: {
+ id: string;
+ fqdn: string;
+ name: string;
+}): Promise<Service> {
+ return await prisma.service.update({ where: { id }, data: { fqdn, name } });
+}
++
+export async function updateVaultWardenService({
+ id,
+ fqdn,
+ name
+}: {
+ id: string;
+ fqdn: string;
+ name: string;
+}): Promise<Service> {
+ return await prisma.service.update({ where: { id }, data: { fqdn, name } });
+}
++
+export async function updateVsCodeServer({
+ id,
+ fqdn,
+ name
+}: {
+ id: string;
+ fqdn: string;
+ name: string;
+}): Promise<Service> {
+ return await prisma.service.update({ where: { id }, data: { fqdn, name } });
+}
++
+export async function updateWordpress({
+ id,
+ fqdn,
+ name,
+ mysqlDatabase,
+ extraConfig
+}: {
+ id: string;
+ fqdn: string;
+ name: string;
+ mysqlDatabase: string;
+ extraConfig: string;
+}): Promise<Service> {
return await prisma.service.update({
where: { id },
data: { fqdn, name, wordpress: { update: { mysqlDatabase, extraConfig } } }
});
}
-export async function updateMinioService({ id, publicPort }) {
++
+export async function updateMinioService({
+ id,
+ publicPort
+}: {
+ id: string;
+ publicPort: number;
+}): Promise<Minio> {
return await prisma.minio.update({ where: { serviceId: id }, data: { publicPort } });
}
-export async function updateGhostService({ id, fqdn, name, mariadbDatabase }) {
++
+export async function updateGhostService({
+ id,
+ fqdn,
+ name,
+ mariadbDatabase
+}: {
+ id: string;
+ fqdn: string;
+ name: string;
+ mariadbDatabase: string;
+}): Promise<Service> {
return await prisma.service.update({
where: { id },
data: { fqdn, name, ghost: { update: { mariadbDatabase } } }
diff --cc src/lib/haproxy/configuration.ts
index 9fba173fb2,831d9490b6..f93a34838f
--- a/src/lib/haproxy/configuration.ts
+++ b/src/lib/haproxy/configuration.ts
@@@ -1,7 -1,8 +1,5 @@@
import { dev } from '$app/env';
-import got from 'got';
-import mustache from 'mustache';
-import crypto from 'crypto';
-
+import got, { type Got } from 'got';
- import mustache from 'mustache';
- import crypto from 'crypto';
import * as db from '$lib/database';
import { checkContainer, checkHAProxy } from '.';
import { asyncExecShell, getDomain, getEngine } from '$lib/common';
@@@ -140,92 -141,27 +139,92 @@@ export async function configureHAProxy(
const haproxy = await haproxyInstance();
await checkHAProxy(haproxy);
- try {
- const data = {
- applications: [],
- services: [],
- coolify: []
- };
- const applications = await db.prisma.application.findMany({
- include: { destinationDocker: true, settings: true }
- });
- for (const application of applications) {
- const {
- fqdn,
- id,
- port,
- destinationDocker,
- destinationDockerId,
- settings: { previews },
- updatedAt
- } = application;
- if (destinationDockerId) {
- const { engine, network } = destinationDocker;
+ const data = {
+ applications: [],
+ services: [],
+ coolify: []
+ };
+ const applications = await db.prisma.application.findMany({
+ include: { destinationDocker: true, settings: true }
+ });
+ for (const application of applications) {
+ const {
+ fqdn,
+ id,
+ port,
+ destinationDocker,
+ destinationDockerId,
+ settings: { previews },
+ updatedAt
+ } = application;
+ if (destinationDockerId) {
+ const { engine, network } = destinationDocker;
+ const isRunning = await checkContainer(engine, id);
+ if (fqdn) {
+ const domain = getDomain(fqdn);
+ const isHttps = fqdn.startsWith('https://');
+ const isWWW = fqdn.includes('www.');
+ const redirectValue = `${isHttps ? 'https://' : 'http://'}${domain}%[capture.req.uri]`;
+ if (isRunning) {
+ data.applications.push({
+ id,
+ port: port || 3000,
+ domain,
+ isRunning,
+ isHttps,
+ redirectValue,
+ redirectTo: isWWW ? domain.replace('www.', '') : 'www.' + domain,
+ updatedAt: updatedAt.getTime()
+ });
+ }
+ if (previews) {
+ const host = getEngine(engine);
+ const { stdout } = await asyncExecShell(
+ `DOCKER_HOST=${host} docker container ls --filter="status=running" --filter="network=${network}" --filter="name=${id}-" --format="{{json .Names}}"`
+ );
+ const containers = stdout
+ .trim()
+ .split('\n')
+ .filter((a) => a)
+ .map((c) => c.replace(/"/g, ''));
+ if (containers.length > 0) {
+ for (const container of containers) {
+ const previewDomain = `${container.split('-')[1]}.${domain}`;
+ data.applications.push({
+ id: container,
+ port: port || 3000,
+ domain: previewDomain,
+ isRunning,
+ isHttps,
+ redirectValue,
+ redirectTo: isWWW ? previewDomain.replace('www.', '') : 'www.' + previewDomain,
+ updatedAt: updatedAt.getTime()
+ });
+ }
+ }
+ }
+ }
+ }
+ }
+ const services = await db.prisma.service.findMany({
+ include: {
+ destinationDocker: true,
+ minio: true,
+ plausibleAnalytics: true,
+ vscodeserver: true,
+ wordpress: true,
+ ghost: true
+ }
+ });
+
+ for (const service of services) {
+ const { fqdn, id, type, destinationDocker, destinationDockerId, updatedAt } = service;
+ if (destinationDockerId) {
+ const { engine } = destinationDocker;
- const found = db.supportedServiceTypesAndVersions.find((a) => a.name === type);
++ const found = supportedServiceTypesAndVersions.find((a) => a.name === type);
+ if (found) {
+ const port = found.ports.main;
+ const publicPort = service[type]?.publicPort;
const isRunning = await checkContainer(engine, id);
if (fqdn) {
const domain = getDomain(fqdn);
@@@ -248,35 -183,105 +247,51 @@@
}
}
}
- const services = await db.prisma.service.findMany({
- include: {
- destinationDocker: true,
- minio: true,
- plausibleAnalytics: true,
- vscodeserver: true,
- wordpress: true,
- ghost: true
- }
+ }
+ const { fqdn } = await db.prisma.setting.findFirst();
+ if (fqdn) {
+ const domain = getDomain(fqdn);
+ const isHttps = fqdn.startsWith('https://');
+ const isWWW = fqdn.includes('www.');
+ const redirectValue = `${isHttps ? 'https://' : 'http://'}${domain}%[capture.req.uri]`;
+ data.coolify.push({
+ id: dev ? 'host.docker.internal' : 'coolify',
+ port: 3000,
+ domain,
+ isHttps,
+ redirectValue,
+ redirectTo: isWWW ? domain.replace('www.', '') : 'www.' + domain
});
- }
- const output = mustache.render(template, data);
- const newHash = crypto.createHash('md5').update(output).digest('hex');
- const { proxyHash, id } = await db.listSettings();
- if (proxyHash !== newHash) {
- await db.prisma.setting.update({ where: { id }, data: { proxyHash: newHash } });
- await haproxy.post(`v2/services/haproxy/configuration/raw`, {
- searchParams: {
- skip_version: true
- },
- body: output,
- headers: {
- 'Content-Type': 'text/plain'
-
+ for (const service of services) {
+ const { fqdn, id, type, destinationDocker, destinationDockerId, updatedAt } = service;
+ if (destinationDockerId) {
+ const { engine } = destinationDocker;
+ const found = supportedServiceTypesAndVersions.find((a) => a.name === type);
+ if (found) {
+ const port = found.ports.main;
+ const publicPort = service[type]?.publicPort;
+ const isRunning = await checkContainer(engine, id);
+ if (fqdn) {
+ const domain = getDomain(fqdn);
+ const isHttps = fqdn.startsWith('https://');
+ const isWWW = fqdn.includes('www.');
+ const redirectValue = `${isHttps ? 'https://' : 'http://'}${domain}%[capture.req.uri]`;
+ if (isRunning) {
+ data.services.push({
+ id,
+ port,
+ publicPort,
+ domain,
+ isRunning,
+ isHttps,
+ redirectValue,
+ redirectTo: isWWW ? domain.replace('www.', '') : 'www.' + domain,
+ updatedAt: updatedAt.getTime()
+ });
+ }
+ }
+ }
}
- });
+ }
- const { fqdn } = await db.prisma.setting.findFirst();
- if (fqdn) {
- const domain = getDomain(fqdn);
- const isHttps = fqdn.startsWith('https://');
- const isWWW = fqdn.includes('www.');
- const redirectValue = `${isHttps ? 'https://' : 'http://'}${domain}%[capture.req.uri]`;
- data.coolify.push({
- id: dev ? 'host.docker.internal' : 'coolify',
- port: 3000,
- domain,
- isHttps,
- redirectValue,
- redirectTo: isWWW ? domain.replace('www.', '') : 'www.' + domain
- });
- }
- const output = mustache.render(template, data);
- const newHash = crypto.createHash('md5').update(output).digest('hex');
- const { proxyHash, id } = await db.listSettings();
- if (proxyHash !== newHash) {
- await db.prisma.setting.update({ where: { id }, data: { proxyHash: newHash } });
- await haproxy.post(`v2/services/haproxy/configuration/raw`, {
- searchParams: {
- skip_version: true
- },
- body: output,
- headers: {
- 'Content-Type': 'text/plain'
- }
- });
- }
- } catch (error) {
- throw error;
}
}
diff --cc src/lib/haproxy/index.ts
index c0c5bff04c,98a1453f34..473660fa13
--- a/src/lib/haproxy/index.ts
+++ b/src/lib/haproxy/index.ts
@@@ -115,13 -108,7 +115,13 @@@ export async function stopTcpHttpProxy
return error;
}
}
-
-export async function startTcpProxy(destinationDocker, id, publicPort, privatePort, volume = null) {
+export async function startTcpProxy(
+ destinationDocker: DestinationDocker,
+ id: string,
+ publicPort: number,
- privatePort: number
++ privatePort: number,
++ volume?: string
+): Promise<{ stdout: string; stderr: string } | Error> {
const { network, engine } = destinationDocker;
const host = getEngine(engine);
diff --cc src/lib/letsencrypt/index.ts
index a3417bb3c1,c9f9c037bd..228f6b5347
--- a/src/lib/letsencrypt/index.ts
+++ b/src/lib/letsencrypt/index.ts
@@@ -4,8 -4,9 +4,9 @@@ import * as db from '$lib/database'
import { dev } from '$app/env';
import cuid from 'cuid';
import getPort, { portNumbers } from 'get-port';
+ import { supportedServiceTypesAndVersions } from '$lib/components/common';
-export async function letsEncrypt(domain, id = null, isCoolify = false) {
+export async function letsEncrypt(domain: string, id?: string, isCoolify = false): Promise<void> {
try {
const data = await db.prisma.setting.findFirst();
const { minPort, maxPort } = data;
diff --cc src/lib/queues/builder.ts
index 2e788c019b,a09e2c3bf8..7419fa5dcf
--- a/src/lib/queues/builder.ts
+++ b/src/lib/queues/builder.ts
@@@ -20,17 -20,14 +20,15 @@@ import
setDefaultConfiguration
} from '$lib/buildPacks/common';
import yaml from 'js-yaml';
+import type { Job } from 'bullmq';
+import type { BuilderJob } from '$lib/types/builderJob';
+
+ import type { ComposeFile } from '$lib/types/composeFile';
+
-export default async function (job) {
- let {
+export default async function (job: Job<BuilderJob, void, string>): Promise<void> {
- /*
- Edge cases:
- 1 - Change build pack and redeploy, what should happen?
- */
+ const {
id: applicationId,
repository,
- branch,
- buildPack,
name,
destinationDocker,
destinationDockerId,