diff --git a/src/lib/database/common.ts b/src/lib/database/common.ts index 53551882b..3196a40ee 100644 --- a/src/lib/database/common.ts +++ b/src/lib/database/common.ts @@ -305,6 +305,12 @@ export async function getFreePort() { select: { mysqlPublicPort: true } }) ).map((a) => a.mysqlPublicPort); - const usedPorts = [...dbUsed, ...wpFtpUsed, ...wpUsed]; + const minioUSed = await ( + await prisma.minio.findMany({ + where: { publicPort: { not: null } }, + select: { publicPort: true } + }) + ).map((a) => a.publicPort); + const usedPorts = [...dbUsed, ...wpFtpUsed, ...wpUsed, ...minioUSed]; return await getPort({ port: portNumbers(minPort, maxPort), exclude: usedPorts }); } diff --git a/src/lib/haproxy/index.ts b/src/lib/haproxy/index.ts index 510186287..b9a8e9581 100644 --- a/src/lib/haproxy/index.ts +++ b/src/lib/haproxy/index.ts @@ -202,8 +202,7 @@ export async function startTcpProxy( destinationDocker: DestinationDocker, id: string, publicPort: number, - privatePort: number, - volume?: string + privatePort: number ): Promise<{ stdout: string; stderr: string } | Error> { const { network, engine } = destinationDocker; const host = getEngine(engine); @@ -218,9 +217,7 @@ export async function startTcpProxy( ); const ip = JSON.parse(Config)[0].Gateway; return await asyncExecShell( - `DOCKER_HOST=${host} docker run --restart always -e PORT=${publicPort} -e APP=${id} -e PRIVATE_PORT=${privatePort} --add-host 'host.docker.internal:host-gateway' --add-host 'host.docker.internal:${ip}' --network ${network} -p ${publicPort}:${publicPort} --name ${containerName} ${ - volume ? `-v ${volume}` : '' - } -d coollabsio/${defaultProxyImageTcp}` + `DOCKER_HOST=${host} docker run --restart always -e PORT=${publicPort} -e APP=${id} -e PRIVATE_PORT=${privatePort} --add-host 'host.docker.internal:host-gateway' --add-host 'host.docker.internal:${ip}' --network ${network} -p ${publicPort}:${publicPort} --name ${containerName} -d coollabsio/${defaultProxyImageTcp}` ); } if (!foundDependentContainer && found) { @@ -262,11 +259,15 @@ export async function startTraefikHTTPProxy( `--entrypoints.http.address=:${publicPort}`, `--providers.http.endpoint=${otherTraefikEndpoint}?id=${id}&privatePort=${privatePort}&publicPort=${publicPort}&type=http`, '--providers.http.pollTimeout=2s', + '--certificatesresolvers.letsencrypt.acme.httpchallenge=true', + '--certificatesresolvers.letsencrypt.acme.storage=/etc/traefik/acme/acme.json', + '--certificatesresolvers.letsencrypt.acme.httpchallenge.entrypoint=http', '--log.level=error' ], ports: [`${publicPort}:${publicPort}`], extra_hosts: ['host.docker.internal:host-gateway', `host.docker.internal:${ip}`], - networks: ['coolify-infra', network] + networks: ['coolify-infra', network], + volumes: ['coolify-traefik-letsencrypt:/etc/traefik/acme'] } }, networks: { @@ -278,6 +279,9 @@ export async function startTraefikHTTPProxy( external: false, name: 'coolify-infra' } + }, + volumes: { + 'coolify-traefik-letsencrypt': {} } }; await fs.writeFile(`/tmp/docker-compose-${id}.yaml`, yaml.dump(tcpProxy)); diff --git a/src/lib/queues/proxyTcpHttp.ts b/src/lib/queues/proxyTcpHttp.ts index c70339bad..4d5f3ec29 100644 --- a/src/lib/queues/proxyTcpHttp.ts +++ b/src/lib/queues/proxyTcpHttp.ts @@ -85,6 +85,7 @@ export default async function (): Promise { try { const service = await db.getService({ id, teamId }); - const { - destinationDockerId, - destinationDocker, - fqdn, - minio: { publicPort } - } = service; + const { destinationDockerId, destinationDocker } = service; await db.updateMinioService({ id, publicPort: null }); if (destinationDockerId) { const engine = destinationDocker.engine; @@ -30,11 +25,6 @@ export const post: RequestHandler = async (event) => { } catch (error) { console.error(error); } - try { - await stopTcpHttpProxy(destinationDocker, publicPort); - } catch (error) { - console.log(error); - } } return { diff --git a/src/routes/webhooks/traefik/other.json.ts b/src/routes/webhooks/traefik/other.json.ts index ea99e770e..428c9e217 100644 --- a/src/routes/webhooks/traefik/other.json.ts +++ b/src/routes/webhooks/traefik/other.json.ts @@ -37,6 +37,7 @@ export const get: RequestHandler = async (event) => { const service = await db.prisma.service.findFirst({ where: { id } }); if (service?.fqdn) { const domain = getDomain(service.fqdn); + const isHttps = service.fqdn.startsWith('https://'); traefik = { [type]: { routers: { @@ -55,6 +56,19 @@ export const get: RequestHandler = async (event) => { } } }; + if (isHttps) { + if (dev) { + traefik[type].routers[id].tls = { + domains: { + main: `${domain}` + } + }; + } else { + traefik[type].routers[id].tls = { + certresolver: 'letsencrypt' + }; + } + } } } }