feat: Ports range
This commit is contained in:
@@ -4,9 +4,16 @@ import { dockerInstance } from '$lib/docker';
|
|||||||
import { forceSSLOnApplication } from '$lib/haproxy';
|
import { forceSSLOnApplication } from '$lib/haproxy';
|
||||||
import * as db from '$lib/database';
|
import * as db from '$lib/database';
|
||||||
import { dev } from '$app/env';
|
import { dev } from '$app/env';
|
||||||
|
import getPort, { portNumbers } from 'get-port';
|
||||||
|
import cuid from 'cuid';
|
||||||
|
|
||||||
export default async function () {
|
export default async function () {
|
||||||
try {
|
try {
|
||||||
|
const data = await db.prisma.setting.findFirst();
|
||||||
|
const { minPort, maxPort } = data;
|
||||||
|
|
||||||
|
const publicPort = await getPort({ port: portNumbers(minPort, maxPort) });
|
||||||
|
const randomCuid = cuid();
|
||||||
const destinationDockers = await prisma.destinationDocker.findMany({});
|
const destinationDockers = await prisma.destinationDocker.findMany({});
|
||||||
for (const destination of destinationDockers) {
|
for (const destination of destinationDockers) {
|
||||||
if (destination.isCoolifyProxyUsed) {
|
if (destination.isCoolifyProxyUsed) {
|
||||||
@@ -30,10 +37,10 @@ export default async function () {
|
|||||||
} else {
|
} else {
|
||||||
const host = getEngine(destination.engine);
|
const host = getEngine(destination.engine);
|
||||||
await asyncExecShell(
|
await asyncExecShell(
|
||||||
`DOCKER_HOST=${host} docker run --rm --name certbot -p 9080:9080 -v "coolify-letsencrypt:/etc/letsencrypt" certbot/certbot --logs-dir /etc/letsencrypt/logs certonly --standalone --preferred-challenges http --http-01-address 0.0.0.0 --http-01-port 9080 -d ${domain} --agree-tos --non-interactive --register-unsafely-without-email`
|
`DOCKER_HOST=${host} docker run --rm --name certbot-${randomCuid} -p 9080:${publicPort} -v "coolify-letsencrypt:/etc/letsencrypt" certbot/certbot --logs-dir /etc/letsencrypt/logs certonly --standalone --preferred-challenges http --http-01-address 0.0.0.0 --http-01-port ${publicPort} -d ${domain} --agree-tos --non-interactive --register-unsafely-without-email`
|
||||||
);
|
);
|
||||||
const { stderr } = await asyncExecShell(
|
const { stderr } = await asyncExecShell(
|
||||||
`DOCKER_HOST=${host} docker run --rm --name bash -v "coolify-letsencrypt:/etc/letsencrypt" -v "coolify-ssl-certs:/app/ssl" alpine:latest cat /etc/letsencrypt/live/${domain}/fullchain.pem /etc/letsencrypt/live/${domain}/privkey.pem > /app/ssl/${domain}.pem`
|
`DOCKER_HOST=${host} docker run --rm -v "coolify-letsencrypt:/etc/letsencrypt" -v "coolify-ssl-certs:/app/ssl" alpine:latest cat /etc/letsencrypt/live/${domain}/fullchain.pem /etc/letsencrypt/live/${domain}/privkey.pem > /app/ssl/${domain}.pem`
|
||||||
);
|
);
|
||||||
if (stderr) throw new Error(stderr);
|
if (stderr) throw new Error(stderr);
|
||||||
}
|
}
|
||||||
@@ -52,7 +59,7 @@ export default async function () {
|
|||||||
console.log('DEV MODE: SSL is enabled');
|
console.log('DEV MODE: SSL is enabled');
|
||||||
} else {
|
} else {
|
||||||
await asyncExecShell(
|
await asyncExecShell(
|
||||||
`docker run --rm --name certbot -p 9080:9080 -v "coolify-letsencrypt:/etc/letsencrypt" certbot/certbot --logs-dir /etc/letsencrypt/logs certonly --standalone --preferred-challenges http --http-01-address 0.0.0.0 --http-01-port 9080 -d ${domain} --agree-tos --non-interactive --register-unsafely-without-email`
|
`docker run --rm --name certbot-${randomCuid} -p 9080:${publicPort} -v "coolify-letsencrypt:/etc/letsencrypt" certbot/certbot --logs-dir /etc/letsencrypt/logs certonly --standalone --preferred-challenges http --http-01-address 0.0.0.0 --http-01-port ${publicPort} -d ${domain} --agree-tos --non-interactive --register-unsafely-without-email`
|
||||||
);
|
);
|
||||||
|
|
||||||
const { stderr } = await asyncExecShell(
|
const { stderr } = await asyncExecShell(
|
||||||
|
@@ -9,10 +9,9 @@ import {
|
|||||||
configureSimpleServiceProxyOn,
|
configureSimpleServiceProxyOn,
|
||||||
reloadHaproxy,
|
reloadHaproxy,
|
||||||
setWwwRedirection,
|
setWwwRedirection,
|
||||||
startHttpProxy,
|
startHttpProxy
|
||||||
startTcpProxy
|
|
||||||
} from '$lib/haproxy';
|
} from '$lib/haproxy';
|
||||||
import getPort from 'get-port';
|
import getPort, { portNumbers } from 'get-port';
|
||||||
import { getDomain } from '$lib/components/common';
|
import { getDomain } from '$lib/components/common';
|
||||||
import { ErrorHandler } from '$lib/database';
|
import { ErrorHandler } from '$lib/database';
|
||||||
import { makeLabelForServices } from '$lib/buildPacks/common';
|
import { makeLabelForServices } from '$lib/buildPacks/common';
|
||||||
@@ -35,14 +34,20 @@ export const post: RequestHandler = async (event) => {
|
|||||||
minio: { rootUser, rootUserPassword }
|
minio: { rootUser, rootUserPassword }
|
||||||
} = service;
|
} = service;
|
||||||
|
|
||||||
|
const data = await db.prisma.setting.findFirst();
|
||||||
|
const { minPort, maxPort } = data;
|
||||||
|
|
||||||
const domain = getDomain(fqdn);
|
const domain = getDomain(fqdn);
|
||||||
const isHttps = fqdn.startsWith('https://');
|
const isHttps = fqdn.startsWith('https://');
|
||||||
|
|
||||||
const network = destinationDockerId && destinationDocker.network;
|
const network = destinationDockerId && destinationDocker.network;
|
||||||
const host = getEngine(destinationDocker.engine);
|
const host = getEngine(destinationDocker.engine);
|
||||||
const publicPort = await getPort();
|
|
||||||
|
const publicPort = await getPort({ port: portNumbers(minPort, maxPort) });
|
||||||
|
|
||||||
const consolePort = 9001;
|
const consolePort = 9001;
|
||||||
const apiPort = 9000;
|
const apiPort = 9000;
|
||||||
|
|
||||||
const { workdir } = await createDirectories({ repository: type, buildId: id });
|
const { workdir } = await createDirectories({ repository: type, buildId: id });
|
||||||
|
|
||||||
const config = {
|
const config = {
|
||||||
|
Reference in New Issue
Block a user