fixes and remote tempaltes
This commit is contained in:
@@ -1,3 +1,5 @@
|
|||||||
|
// Convert caprover format to coolify format
|
||||||
|
|
||||||
import fs from 'fs/promises';
|
import fs from 'fs/promises';
|
||||||
import yaml from 'js-yaml';
|
import yaml from 'js-yaml';
|
||||||
const templateYml = await fs.readFile('./caprover.yml', 'utf8')
|
const templateYml = await fs.readFile('./caprover.yml', 'utf8')
|
||||||
|
@@ -106,32 +106,44 @@ const host = '0.0.0.0';
|
|||||||
});
|
});
|
||||||
fastify.register(cookie)
|
fastify.register(cookie)
|
||||||
fastify.register(cors);
|
fastify.register(cors);
|
||||||
fastify.addHook('onRequest', async (request, reply) => {
|
// To detect allowed origins
|
||||||
let allowedList = ['coolify:3000'];
|
// fastify.addHook('onRequest', async (request, reply) => {
|
||||||
const { ipv4, ipv6, fqdn } = await prisma.setting.findFirst({})
|
// let allowedList = ['coolify:3000'];
|
||||||
|
// const { ipv4, ipv6, fqdn } = await prisma.setting.findFirst({})
|
||||||
|
|
||||||
|
// ipv4 && allowedList.push(`${ipv4}:3000`);
|
||||||
|
// ipv6 && allowedList.push(ipv6);
|
||||||
|
// fqdn && allowedList.push(getDomain(fqdn));
|
||||||
|
// 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 } })
|
||||||
|
// if (remotes.length > 0) {
|
||||||
|
// remotes.forEach(remote => {
|
||||||
|
// allowedList.push(`${remote.remoteIpAddress}:3000`);
|
||||||
|
// })
|
||||||
|
// }
|
||||||
|
// if (!allowedList.includes(request.headers.host)) {
|
||||||
|
// // console.log('not allowed', request.headers.host)
|
||||||
|
// }
|
||||||
|
// })
|
||||||
|
|
||||||
|
|
||||||
ipv4 && allowedList.push(`${ipv4}:3000`);
|
|
||||||
ipv6 && allowedList.push(ipv6);
|
|
||||||
fqdn && allowedList.push(getDomain(fqdn));
|
|
||||||
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 } })
|
|
||||||
if (remotes.length > 0) {
|
|
||||||
remotes.forEach(remote => {
|
|
||||||
allowedList.push(`${remote.remoteIpAddress}:3000`);
|
|
||||||
})
|
|
||||||
}
|
|
||||||
if (!allowedList.includes(request.headers.host)) {
|
|
||||||
// console.log('not allowed', request.headers.host)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
try {
|
try {
|
||||||
const templateJson = await getTemplates()
|
const { default: got } = await import('got')
|
||||||
if (isDev) {
|
let templates = {}
|
||||||
await fs.writeFile('./template.json', JSON.stringify(templateJson, null, 2))
|
try {
|
||||||
} else {
|
const response = await got.get('https://get.coollabs.io/coolify/service-templates.yaml').text()
|
||||||
await fs.writeFile('/app/template.json', JSON.stringify(templateJson, null, 2))
|
templates = yaml.load(response)
|
||||||
|
} catch (error) {
|
||||||
|
console.log("Couldn't get latest templates.")
|
||||||
|
console.log(error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isDev) {
|
||||||
|
await fs.writeFile('./template.json', JSON.stringify(templates, null, 2))
|
||||||
|
} else {
|
||||||
|
await fs.writeFile('/app/template.json', JSON.stringify(templates, null, 2))
|
||||||
|
}
|
||||||
|
const templateJson = await getTemplates()
|
||||||
await migrateServicesToNewTemplate(templateJson)
|
await migrateServicesToNewTemplate(templateJson)
|
||||||
|
|
||||||
await fastify.listen({ port, host })
|
await fastify.listen({ port, host })
|
||||||
|
File diff suppressed because it is too large
Load Diff
@@ -484,7 +484,7 @@ export async function saveService(request: FastifyRequest<SaveService>, reply: F
|
|||||||
let { name, fqdn, exposePort, type, serviceSetting } = request.body;
|
let { name, fqdn, exposePort, type, serviceSetting } = request.body;
|
||||||
if (fqdn) fqdn = fqdn.toLowerCase();
|
if (fqdn) fqdn = fqdn.toLowerCase();
|
||||||
if (exposePort) exposePort = Number(exposePort);
|
if (exposePort) exposePort = Number(exposePort);
|
||||||
|
console.log({ serviceSetting })
|
||||||
type = fixType(type)
|
type = fixType(type)
|
||||||
// const update = saveUpdateableFields(type, request.body[type])
|
// const update = saveUpdateableFields(type, request.body[type])
|
||||||
const data = {
|
const data = {
|
||||||
@@ -496,12 +496,12 @@ export async function saveService(request: FastifyRequest<SaveService>, reply: F
|
|||||||
// data[type] = { update: update }
|
// data[type] = { update: update }
|
||||||
// }
|
// }
|
||||||
for (const setting of serviceSetting) {
|
for (const setting of serviceSetting) {
|
||||||
const { id: settingId, name, value, changed = false, isNew = false } = setting
|
const { id: settingId, name, value, changed = false, isNew = false, variableName } = setting
|
||||||
if (changed) {
|
if (changed) {
|
||||||
await prisma.serviceSetting.update({ where: { id: settingId }, data: { value } })
|
await prisma.serviceSetting.update({ where: { id: settingId }, data: { value } })
|
||||||
}
|
}
|
||||||
if (isNew) {
|
if (isNew) {
|
||||||
await prisma.serviceSetting.create({ data: { name, value, service: { connect: { id } } } })
|
await prisma.serviceSetting.create({ data: { name, value, variableName, service: { connect: { id } } } })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
await prisma.service.update({
|
await prisma.service.update({
|
||||||
@@ -510,6 +510,7 @@ export async function saveService(request: FastifyRequest<SaveService>, reply: F
|
|||||||
});
|
});
|
||||||
return reply.code(201).send()
|
return reply.code(201).send()
|
||||||
} catch ({ status, message }) {
|
} catch ({ status, message }) {
|
||||||
|
console.log({ status, message })
|
||||||
return errorHandler({ status, message })
|
return errorHandler({ status, message })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user