fix: Proxy for http
This commit is contained in:
parent
eb62888c39
commit
c0d711170b
@ -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 });
|
||||
}
|
||||
|
@ -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));
|
||||
|
@ -85,6 +85,7 @@ export default async function (): Promise<void | {
|
||||
where: { publicPort: { not: null } },
|
||||
include: { service: { include: { destinationDocker: true } } }
|
||||
});
|
||||
console.log(minioInstances);
|
||||
for (const minio of minioInstances) {
|
||||
const { service, publicPort } = minio;
|
||||
const { destinationDockerId, destinationDocker, id } = service;
|
||||
@ -101,6 +102,7 @@ export default async function (): Promise<void | {
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
return ErrorHandler(error.response?.body || error);
|
||||
}
|
||||
}
|
||||
|
@ -12,12 +12,7 @@ export const post: RequestHandler = async (event) => {
|
||||
|
||||
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 {
|
||||
|
@ -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'
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user