2022-02-28 16:06:44 +01:00
|
|
|
import * as db from '$lib/database';
|
2022-02-10 15:47:44 +01:00
|
|
|
import { getDomain } from '$lib/common';
|
|
|
|
import {
|
|
|
|
checkContainer,
|
2022-02-27 11:52:05 +01:00
|
|
|
checkProxyConfigurations,
|
2022-02-10 15:47:44 +01:00
|
|
|
configureCoolifyProxyOn,
|
2022-02-28 16:06:44 +01:00
|
|
|
configureHAProxy,
|
2022-02-10 15:47:44 +01:00
|
|
|
forceSSLOnApplication,
|
2022-02-13 22:56:37 +01:00
|
|
|
setWwwRedirection,
|
2022-02-15 21:44:36 +01:00
|
|
|
startCoolifyProxy,
|
|
|
|
startHttpProxy
|
2022-02-10 15:47:44 +01:00
|
|
|
} from '$lib/haproxy';
|
|
|
|
|
|
|
|
export default async function () {
|
2022-02-27 11:52:05 +01:00
|
|
|
try {
|
|
|
|
await checkProxyConfigurations();
|
|
|
|
} catch (error) {
|
|
|
|
console.log(error);
|
|
|
|
}
|
2022-02-10 15:47:44 +01:00
|
|
|
try {
|
2022-02-28 16:06:44 +01:00
|
|
|
const applications = await db.prisma.application.findMany({
|
|
|
|
include: { destinationDocker: true }
|
|
|
|
});
|
|
|
|
|
|
|
|
for (const application of applications) {
|
|
|
|
const {
|
|
|
|
fqdn,
|
|
|
|
id,
|
|
|
|
port,
|
|
|
|
destinationDocker: { engine }
|
|
|
|
} = application;
|
|
|
|
const containerRunning = await checkContainer(engine, id);
|
|
|
|
await configureHAProxy(fqdn, id, port, containerRunning, engine);
|
|
|
|
}
|
|
|
|
|
|
|
|
const services = await db.prisma.service.findMany({
|
|
|
|
include: {
|
|
|
|
destinationDocker: true,
|
|
|
|
minio: true,
|
|
|
|
plausibleAnalytics: true,
|
|
|
|
vscodeserver: true,
|
|
|
|
wordpress: true
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
for (const service of services) {
|
|
|
|
const {
|
|
|
|
fqdn,
|
|
|
|
id,
|
|
|
|
type,
|
|
|
|
destinationDocker: { engine }
|
|
|
|
} = service;
|
|
|
|
const found = db.supportedServiceTypesAndVersions.find((a) => a.name === type);
|
|
|
|
if (found) {
|
|
|
|
const port = found.ports.main;
|
|
|
|
const publicPort = service[type]?.publicPort;
|
|
|
|
const containerRunning = await checkContainer(engine, id);
|
|
|
|
await configureHAProxy(fqdn, id, port, containerRunning, engine);
|
|
|
|
if (publicPort) {
|
|
|
|
const containerFound = await checkContainer(
|
|
|
|
service.destinationDocker.engine,
|
|
|
|
`haproxy-for-${publicPort}`
|
|
|
|
);
|
|
|
|
if (!containerFound) {
|
|
|
|
await startHttpProxy(service.destinationDocker, id, publicPort, 9000);
|
2022-02-10 15:47:44 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Check Coolify FQDN and configure proxy if needed
|
|
|
|
const { fqdn } = await db.listSettings();
|
|
|
|
if (fqdn) {
|
|
|
|
const domain = getDomain(fqdn);
|
2022-02-15 15:55:55 +01:00
|
|
|
await startCoolifyProxy('/var/run/docker.sock');
|
|
|
|
await configureCoolifyProxyOn(fqdn);
|
2022-02-13 22:56:37 +01:00
|
|
|
await setWwwRedirection(fqdn);
|
2022-02-10 15:47:44 +01:00
|
|
|
const isHttps = fqdn.startsWith('https://');
|
2022-02-18 13:59:23 +01:00
|
|
|
if (isHttps) await forceSSLOnApplication(domain);
|
2022-02-10 15:47:44 +01:00
|
|
|
}
|
|
|
|
} catch (error) {
|
|
|
|
throw error;
|
|
|
|
}
|
|
|
|
}
|