revert things

This commit is contained in:
Andras Bacsai 2022-10-04 22:00:50 +02:00
parent 430d51866c
commit 702798c275
4 changed files with 77 additions and 59 deletions

View File

@ -11,7 +11,7 @@
"build": "rimraf build && esbuild `find src \\( -name '*.ts' \\)| grep -v client/` --minify=true --platform=node --outdir=build --format=cjs", "build": "rimraf build && esbuild `find src \\( -name '*.ts' \\)| grep -v client/` --minify=true --platform=node --outdir=build --format=cjs",
"format": "prettier --write 'src/**/*.{js,ts,json,md}'", "format": "prettier --write 'src/**/*.{js,ts,json,md}'",
"lint": "prettier --check 'src/**/*.{js,ts,json,md}' && eslint --ignore-path .eslintignore .", "lint": "prettier --check 'src/**/*.{js,ts,json,md}' && eslint --ignore-path .eslintignore .",
"predev": "npx -y prisma migrate deploy && npx prisma generate && npx prisma db seed", "prestart": "npx -y prisma migrate deploy && npx prisma generate && npx prisma db seed",
"start": "NODE_ENV=production node index.js" "start": "NODE_ENV=production node index.js"
}, },
"dependencies": { "dependencies": {

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 = await prisma.setting.findFirst()
const fastify = Fastify({ const fastify = Fastify({
logger: false, logger: settings?.isAPIDebuggingEnabled || 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")
// }, 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")
// }, 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) { }

View File

@ -140,9 +140,27 @@ export const asyncExecShellStream = async ({
export const asyncSleep = (delay: number): Promise<unknown> => export const asyncSleep = (delay: number): Promise<unknown> =>
new Promise((resolve) => setTimeout(resolve, delay)); new Promise((resolve) => setTimeout(resolve, delay));
export const prisma = () => { export const prisma = new PrismaClient({
return null errorFormat: 'minimal'
} // log: [
// {
// emit: 'event',
// level: 'query',
// },
// {
// emit: 'stdout',
// level: 'error',
// },
// {
// emit: 'stdout',
// level: 'info',
// },
// {
// emit: 'stdout',
// level: 'warn',
// },
// ],
});
// prisma.$on('query', (e) => { // prisma.$on('query', (e) => {
// console.log({e}) // console.log({e})

View File

@ -18,10 +18,10 @@ const options: any = {
} }
} }
}, },
// jobs: [ jobs: [
// { name: 'infrastructure' }, { name: 'infrastructure' },
// { name: 'deployApplication' }, { name: 'deployApplication' },
// ], ],
}; };
if (isDev) options.root = path.join(__dirname, '../jobs'); if (isDev) options.root = path.join(__dirname, '../jobs');