dev intervals

This commit is contained in:
Andras Bacsai 2022-10-04 21:46:01 +02:00
parent f4051874b2
commit 9d08421f01

View File

@ -29,9 +29,9 @@ declare module 'fastify' {
const port = isDev ? 3001 : 3000; const port = isDev ? 3001 : 3000;
const host = '0.0.0.0'; const host = '0.0.0.0';
(async () => { (async () => {
const settings = prisma.setting.findFirst() // const settings = prisma.setting.findFirst()
const fastify = Fastify({ const fastify = Fastify({
logger: settings?.isAPIDebuggingEnabled || false, logger: false,
trustProxy: true trustProxy: true
}); });
@ -101,66 +101,66 @@ const host = '0.0.0.0';
}); });
fastify.register(cookie) fastify.register(cookie)
fastify.register(cors); fastify.register(cors);
fastify.addHook('onRequest', async (request, reply) => { // fastify.addHook('onRequest', async (request, reply) => {
let allowedList = ['coolify:3000']; // let allowedList = ['coolify:3000'];
const { ipv4, ipv6, fqdn } = await prisma.setting.findFirst({}) // const { ipv4, ipv6, fqdn } = await prisma.setting.findFirst({})
ipv4 && allowedList.push(`${ipv4}:3000`); // ipv4 && allowedList.push(`${ipv4}:3000`);
ipv6 && allowedList.push(ipv6); // ipv6 && allowedList.push(ipv6);
fqdn && allowedList.push(getDomain(fqdn)); // fqdn && allowedList.push(getDomain(fqdn));
isDev && allowedList.push('localhost:3000') && allowedList.push('localhost:3001') && allowedList.push('host.docker.internal:3001'); // isDev && allowedList.push('localhost:3000') && allowedList.push('localhost:3001') && allowedList.push('host.docker.internal:3001');
const remotes = await prisma.destinationDocker.findMany({ where: { remoteEngine: true, remoteVerified: true } }) // const remotes = await prisma.destinationDocker.findMany({ where: { remoteEngine: true, remoteVerified: true } })
if (remotes.length > 0) { // if (remotes.length > 0) {
remotes.forEach(remote => { // remotes.forEach(remote => {
allowedList.push(`${remote.remoteIpAddress}:3000`); // allowedList.push(`${remote.remoteIpAddress}:3000`);
}) // })
} // }
if (!allowedList.includes(request.headers.host)) { // if (!allowedList.includes(request.headers.host)) {
// console.log('not allowed', request.headers.host) // // console.log('not allowed', request.headers.host)
} // }
}) // })
try { try {
await fastify.listen({ port, host }) await fastify.listen({ port, host })
console.log(`Coolify's API is listening on ${host}:${port}`); console.log(`Coolify's API is listening on ${host}:${port}`);
await initServer(); await initServer();
const graceful = new Graceful({ brees: [scheduler] }); // const graceful = new Graceful({ brees: [scheduler] });
graceful.listen(); // graceful.listen();
setInterval(async () => { // setInterval(async () => {
if (!scheduler.workers.has('deployApplication')) { // if (!scheduler.workers.has('deployApplication')) {
scheduler.run('deployApplication'); // scheduler.run('deployApplication');
} // }
if (!scheduler.workers.has('infrastructure')) { // if (!scheduler.workers.has('infrastructure')) {
scheduler.run('infrastructure'); // scheduler.run('infrastructure');
} // }
}, 2000) // }, 2000)
// autoUpdater // autoUpdater
setInterval(async () => { // setInterval(async () => {
scheduler.workers.has('infrastructure') && scheduler.workers.get('infrastructure').postMessage("action:autoUpdater") // scheduler.workers.has('infrastructure') && scheduler.workers.get('infrastructure').postMessage("action:autoUpdater")
}, isDev ? 5000 : 60000 * 15) // }, 60000 * 15)
// cleanupStorage // // cleanupStorage
setInterval(async () => { // setInterval(async () => {
scheduler.workers.has('infrastructure') && scheduler.workers.get('infrastructure').postMessage("action:cleanupStorage") // scheduler.workers.has('infrastructure') && scheduler.workers.get('infrastructure').postMessage("action:cleanupStorage")
}, isDev ? 6000 : 60000 * 10) // }, 60000 * 10)
// checkProxies and checkFluentBit // // checkProxies and checkFluentBit
setInterval(async () => { // setInterval(async () => {
scheduler.workers.has('infrastructure') && scheduler.workers.get('infrastructure').postMessage("action:checkProxies") // scheduler.workers.has('infrastructure') && scheduler.workers.get('infrastructure').postMessage("action:checkProxies")
scheduler.workers.has('infrastructure') && scheduler.workers.get('infrastructure').postMessage("action:checkFluentBit") // scheduler.workers.has('infrastructure') && scheduler.workers.get('infrastructure').postMessage("action:checkFluentBit")
}, 10000) // }, 10000)
setInterval(async () => { // setInterval(async () => {
scheduler.workers.has('infrastructure') && scheduler.workers.get('infrastructure').postMessage("action:copySSLCertificates") // scheduler.workers.has('infrastructure') && scheduler.workers.get('infrastructure').postMessage("action:copySSLCertificates")
}, 2000) // }, 2000)
await Promise.all([ // await Promise.all([
getArch(), // getArch(),
getIPAddress(), // getIPAddress(),
configureRemoteDockers(), // configureRemoteDockers(),
]) // ])
} catch (error) { } catch (error) {
console.error(error); console.error(error);
process.exit(1); process.exit(1);
@ -178,13 +178,13 @@ async function getIPAddress() {
if (!settings.ipv4) { if (!settings.ipv4) {
console.log(`Getting public IPv4 address...`); console.log(`Getting public IPv4 address...`);
const ipv4 = await publicIpv4({ timeout: 2000 }) const ipv4 = await publicIpv4({ timeout: 2000 })
await prisma.setting.update({ where: { id: settings.id }, data: { ipv4 } }) // await prisma.setting.update({ where: { id: settings.id }, data: { ipv4 } })
} }
if (!settings.ipv6) { if (!settings.ipv6) {
console.log(`Getting public IPv6 address...`); console.log(`Getting public IPv6 address...`);
const ipv6 = await publicIpv6({ timeout: 2000 }) const ipv6 = await publicIpv6({ timeout: 2000 })
await prisma.setting.update({ where: { id: settings.id }, data: { ipv6 } }) // await prisma.setting.update({ where: { id: settings.id }, data: { ipv6 } })
} }
} catch (error) { } } catch (error) { }