This commit is contained in:
Andras Bacsai 2022-11-03 14:59:37 +01:00
parent e6024c997f
commit 9f3677b694
8 changed files with 77 additions and 197 deletions

1
apps/api/devTags.json Normal file

File diff suppressed because one or more lines are too long

View File

@ -1,3 +1,35 @@
- templateVersion: 1.0.0
defaultVersion: v1.8.6
type: appsmith
name: Appsmith
services:
$$id:
image: appsmith/appsmith-ce:$$core_version
environment:
- APPSMITH_MAIL_ENABLED: $$config_appsmith_mail_enabled
- APPSMITH_DISABLE_TELEMETRY: $$config_appsmith_disable_telemetry
- APPSMITH_DISABLE_INTERCOM: $$config_appsmith_disable_intercom
volumes:
- $$id-stacks-data:/appsmith-stacks
ports:
- '8080'
variables:
- id: $$config_appsmith_mail_enabled
name: APPSMITH_MAIL_ENABLED
label: Enable Mail
defaultValue: false
description: ''
- id: $$config_appsmith_disable_telemetry
name: APPSMITH_DISABLE_TELEMETRY
label: Disable Telemetry
defaultValue: true
description: ''
- id: $$config_appsmith_disable_intercom
name: APPSMITH_DISABLE_INTERCOM
label: Disable Intercom
defaultValue: true
description: ''
documentation: https://hub.docker.com/r/zadam/trilium
- templateVersion: 1.0.0
defaultVersion: 0.56.2
type: trilium

View File

@ -1,111 +0,0 @@
// Convert caprover format to coolify format
import fs from 'fs/promises';
import yaml from 'js-yaml';
const templateYml = await fs.readFile('./convert.yaml', 'utf8')
const template = yaml.load(templateYml)
const newTemplate = {
"templateVersion": "1.0.0",
"defaultVersion": "latest",
"type": "",
"name": "",
"description": "",
"services": {
},
"variables": []
}
const version = template.caproverOneClickApp.variables.find(v => v.id === '$$cap_APP_VERSION' || v.id === '$$cap_version').defaultValue || 'latest'
newTemplate.name = template.caproverOneClickApp.displayName
newTemplate.type = template.caproverOneClickApp.displayName.replaceAll(' ', '').toLowerCase()
newTemplate.documentation = template.caproverOneClickApp.documentation
newTemplate.description = template.caproverOneClickApp.description
newTemplate.defaultVersion = version
const varSet = new Set()
const caproverVariables = template.caproverOneClickApp.variables
for (const service of Object.keys(template.services)) {
const serviceTemplate = template.services[service]
const newServiceName = service.replaceAll('cap_appname', 'id')
const newService = {
image: '',
command: '',
environment: [],
volumes: []
}
const FROM = serviceTemplate.caproverExtra?.dockerfileLines?.find((line) => line.startsWith('FROM'))
if (serviceTemplate.image) {
newService.image = serviceTemplate.image.replaceAll('cap_APP_VERSION', 'core_version').replaceAll('cap_version', 'core_version')
} else if (FROM) {
newService.image = FROM.split(' ')[1].replaceAll('cap_APP_VERSION', 'core_version').replaceAll('cap_version', 'core_version')
}
const CMD = serviceTemplate.caproverExtra?.dockerfileLines?.find((line) => line.startsWith('CMD'))
if (serviceTemplate.command) {
newService.command = serviceTemplate.command
} else if (CMD) {
newService.command = CMD.replace('CMD ', '').replaceAll('"', '').replaceAll('[', '').replaceAll(']', '').replaceAll(',', ' ').replace(/\s+/g, ' ')
} else {
delete newService.command
}
const ENTRYPOINT = serviceTemplate.caproverExtra?.dockerfileLines?.find((line) => line.startsWith('ENTRYPOINT'))
if (serviceTemplate.entrypoint) {
newService.command = serviceTemplate.entrypoint
} else if (ENTRYPOINT) {
newService.entrypoint = ENTRYPOINT.replace('ENTRYPOINT ', '').replaceAll('"', '').replaceAll('[', '').replaceAll(']', '').replaceAll(',', ' ').replace(/\s+/g, ' ')
} else {
delete newService.entrypoint
}
if (serviceTemplate.environment && Object.keys(serviceTemplate.environment).length > 0) {
for (const env of Object.keys(serviceTemplate.environment)) {
const foundCaproverVariable = caproverVariables.find((item) => item.id === serviceTemplate.environment[env])
let value = null;
let defaultValue = foundCaproverVariable?.defaultValue ? foundCaproverVariable?.defaultValue.toString()?.replace('$$cap_gen_random_hex', '$$$generate_hex') : ''
if (serviceTemplate.environment[env].startsWith('srv-captain--$$cap_appname')) {
value = `$$config_${env}`.toLowerCase()
defaultValue = serviceTemplate.environment[env].replaceAll('srv-captain--$$cap_appname', '$$$id').replace('$$cap_', '').replaceAll('captain-overlay-network', `$$$config_${env}`).toLowerCase()
} else {
value = '$$config_' + serviceTemplate.environment[env].replaceAll('srv-captain--$$cap_appname', '$$$id').replace('$$cap_', '').replaceAll('captain-overlay-network', `$$$config_${env}`).toLowerCase()
}
newService.environment.push(`${env}=${value}`)
const foundVariable = varSet.has(env)
if (!foundVariable) {
newTemplate.variables.push({
"id": value,
"name": env,
"label": foundCaproverVariable?.label || '',
"defaultValue": defaultValue,
"description": foundCaproverVariable?.description || '',
})
}
varSet.add(env)
}
}
if (serviceTemplate.volumes && serviceTemplate.volumes.length > 0) {
for (const volume of serviceTemplate.volumes) {
const [source, target] = volume.split(':')
if (source === '/var/run/docker.sock' || source === '/tmp') {
continue;
}
newService.volumes.push(`${source.replaceAll('$$cap_appname-', '$$$id-')}:${target}`)
}
}
newTemplate.services[newServiceName] = newService
const services = { ...newTemplate.services }
newTemplate.services = {}
for (const key of Object.keys(services).sort()) {
newTemplate.services[key] = services[key]
}
}
await fs.writeFile('./caprover_new.yml', yaml.dump([{ ...newTemplate }]))
await fs.writeFile('./caprover_new.json', JSON.stringify([{ ...newTemplate }], null, 2))

View File

@ -3,7 +3,7 @@ import yaml from 'js-yaml';
import got from 'got';
const repositories = [];
const templates = await fs.readFile('../devTemplates.yaml', 'utf8');
const templates = await fs.readFile('./apps/api/devTemplates.yaml', 'utf8');
const devTemplates = yaml.load(templates);
for (const template of devTemplates) {
let image = template.services['$$id'].image.replaceAll(':$$core_version', '');
@ -64,4 +64,4 @@ for (const repository of repositories) {
})
}
}
await fs.writeFile('./tags.json', JSON.stringify(services));
await fs.writeFile('./apps/api/devTags.json', JSON.stringify(services));

View File

@ -175,7 +175,7 @@ const host = '0.0.0.0';
await refreshTags()
await migrateServicesToNewTemplate()
}, 60000)
setInterval(async () => {
await copySSLCertificates();
}, 10000)
@ -215,13 +215,14 @@ async function getIPAddress() {
async function getTagsTemplates() {
const { default: got } = await import('got')
try {
const tags = await got.get('https://get.coollabs.io/coolify/service-tags.json').text()
if (isDev) {
const templates = await fs.readFile('./devTemplates.yaml', 'utf8')
const tags = await fs.readFile('./devTags.json', 'utf8')
await fs.writeFile('./templates.json', JSON.stringify(yaml.load(templates)))
await fs.writeFile('./tags.json', tags)
console.log('Tags and templates loaded in dev mode...')
} else {
const tags = await got.get('https://get.coollabs.io/coolify/service-tags.json').text()
const response = await got.get('https://get.coollabs.io/coolify/service-templates.yaml').text()
await fs.writeFile('/app/templates.json', JSON.stringify(yaml.load(response)))
await fs.writeFile('/app/tags.json', tags)
@ -387,17 +388,17 @@ async function checkProxies() {
}
// HTTP Proxies
const minioInstances = await prisma.minio.findMany({
where: { publicPort: { not: null } },
include: { service: { include: { destinationDocker: true } } }
});
for (const minio of minioInstances) {
const { service, publicPort } = minio;
const { destinationDockerId, destinationDocker, id } = service;
if (destinationDockerId && destinationDocker.isCoolifyProxyUsed) {
await startTraefikTCPProxy(destinationDocker, id, publicPort, 9000);
}
}
// const minioInstances = await prisma.minio.findMany({
// where: { publicPort: { not: null } },
// include: { service: { include: { destinationDocker: true } } }
// });
// for (const minio of minioInstances) {
// const { service, publicPort } = minio;
// const { destinationDockerId, destinationDocker, id } = service;
// if (destinationDockerId && destinationDocker.isCoolifyProxyUsed) {
// await startTraefikTCPProxy(destinationDocker, id, publicPort, 9000);
// }
// }
} catch (error) {
}

View File

@ -35,9 +35,7 @@ async function applicationConfiguration(traefik: any, remoteId: string | null =
const { network, id: dockerId } = destinationDocker;
const isRunning = true;
if (buildPack === 'compose') {
console.log(dockerComposeConfiguration)
const services = Object.entries(JSON.parse(dockerComposeConfiguration))
console.log(services)
if (services.length > 0) {
for (const service of services) {
const [key, value] = service
@ -637,80 +635,40 @@ export async function traefikOtherConfiguration(request: FastifyRequest<TraefikO
};
} else if (type === 'http') {
const service = await prisma.service.findFirst({
where: { id },
include: { serviceSetting: true }
where: { id }
});
if (service) {
if (service.type === 'minio') {
const domainSetting = service.serviceSetting.find((a) => a.name === 'MINIO_SERVER_URL')?.value
const domain = getDomain(domainSetting);
const isHttps = domainSetting.startsWith('https://');
traefik = {
[type]: {
routers: {
[id]: {
entrypoints: [type],
rule: `Host(\`${domain}\`)`,
service: id
}
},
services: {
[id]: {
loadbalancer: {
servers: [{ url: `http://${id}:${privatePort}` }]
}
if (service && service?.fqdn) {
const domain = getDomain(service.fqdn);
const isHttps = service.fqdn.startsWith('https://');
traefik = {
[type]: {
routers: {
[id]: {
entrypoints: [type],
rule: `Host(\`${domain}:${privatePort}\`)`,
service: id
}
},
services: {
[id]: {
loadbalancer: {
servers: [{ url: `http://${id}:${privatePort}` }]
}
}
}
};
if (isHttps) {
if (isDev) {
traefik[type].routers[id].tls = {
domains: {
main: `${domain}`
}
};
} else {
traefik[type].routers[id].tls = {
certresolver: 'letsencrypt'
};
}
}
} else {
if (service?.fqdn) {
const domain = getDomain(service.fqdn);
const isHttps = service.fqdn.startsWith('https://');
traefik = {
[type]: {
routers: {
[id]: {
entrypoints: [type],
rule: `Host(\`${domain}:${privatePort}\`)`,
service: id
}
},
services: {
[id]: {
loadbalancer: {
servers: [{ url: `http://${id}:${privatePort}` }]
}
}
}
};
if (isHttps) {
if (isDev) {
traefik[type].routers[id].tls = {
domains: {
main: `${domain}`
}
};
if (isHttps) {
if (isDev) {
traefik[type].routers[id].tls = {
domains: {
main: `${domain}`
}
};
} else {
traefik[type].routers[id].tls = {
certresolver: 'letsencrypt'
};
}
}
} else {
traefik[type].routers[id].tls = {
certresolver: 'letsencrypt'
};
}
}
} else {

View File

@ -6,7 +6,6 @@ import { TraefikOtherConfiguration } from './types';
const root: FastifyPluginAsync = async (fastify): Promise<void> => {
fastify.get<OnlyId>('/main.json', async (request, reply) => traefikConfiguration(request, false));
fastify.get<OnlyId>('/remote/:id', async (request) => traefikConfiguration(request, true));
fastify.get<TraefikOtherConfiguration>('/other.json', async (request, reply) => traefikOtherConfiguration(request));
};

File diff suppressed because one or more lines are too long