fix: Proxy for http
This commit is contained in:
parent
eb62888c39
commit
c0d711170b
@ -305,6 +305,12 @@ export async function getFreePort() {
|
|||||||
select: { mysqlPublicPort: true }
|
select: { mysqlPublicPort: true }
|
||||||
})
|
})
|
||||||
).map((a) => a.mysqlPublicPort);
|
).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 });
|
return await getPort({ port: portNumbers(minPort, maxPort), exclude: usedPorts });
|
||||||
}
|
}
|
||||||
|
@ -202,8 +202,7 @@ export async function startTcpProxy(
|
|||||||
destinationDocker: DestinationDocker,
|
destinationDocker: DestinationDocker,
|
||||||
id: string,
|
id: string,
|
||||||
publicPort: number,
|
publicPort: number,
|
||||||
privatePort: number,
|
privatePort: number
|
||||||
volume?: string
|
|
||||||
): Promise<{ stdout: string; stderr: string } | Error> {
|
): Promise<{ stdout: string; stderr: string } | Error> {
|
||||||
const { network, engine } = destinationDocker;
|
const { network, engine } = destinationDocker;
|
||||||
const host = getEngine(engine);
|
const host = getEngine(engine);
|
||||||
@ -218,9 +217,7 @@ export async function startTcpProxy(
|
|||||||
);
|
);
|
||||||
const ip = JSON.parse(Config)[0].Gateway;
|
const ip = JSON.parse(Config)[0].Gateway;
|
||||||
return await asyncExecShell(
|
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} ${
|
`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}`
|
||||||
volume ? `-v ${volume}` : ''
|
|
||||||
} -d coollabsio/${defaultProxyImageTcp}`
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (!foundDependentContainer && found) {
|
if (!foundDependentContainer && found) {
|
||||||
@ -262,11 +259,15 @@ export async function startTraefikHTTPProxy(
|
|||||||
`--entrypoints.http.address=:${publicPort}`,
|
`--entrypoints.http.address=:${publicPort}`,
|
||||||
`--providers.http.endpoint=${otherTraefikEndpoint}?id=${id}&privatePort=${privatePort}&publicPort=${publicPort}&type=http`,
|
`--providers.http.endpoint=${otherTraefikEndpoint}?id=${id}&privatePort=${privatePort}&publicPort=${publicPort}&type=http`,
|
||||||
'--providers.http.pollTimeout=2s',
|
'--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'
|
'--log.level=error'
|
||||||
],
|
],
|
||||||
ports: [`${publicPort}:${publicPort}`],
|
ports: [`${publicPort}:${publicPort}`],
|
||||||
extra_hosts: ['host.docker.internal:host-gateway', `host.docker.internal:${ip}`],
|
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: {
|
networks: {
|
||||||
@ -278,6 +279,9 @@ export async function startTraefikHTTPProxy(
|
|||||||
external: false,
|
external: false,
|
||||||
name: 'coolify-infra'
|
name: 'coolify-infra'
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
volumes: {
|
||||||
|
'coolify-traefik-letsencrypt': {}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
await fs.writeFile(`/tmp/docker-compose-${id}.yaml`, yaml.dump(tcpProxy));
|
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 } },
|
where: { publicPort: { not: null } },
|
||||||
include: { service: { include: { destinationDocker: true } } }
|
include: { service: { include: { destinationDocker: true } } }
|
||||||
});
|
});
|
||||||
|
console.log(minioInstances);
|
||||||
for (const minio of minioInstances) {
|
for (const minio of minioInstances) {
|
||||||
const { service, publicPort } = minio;
|
const { service, publicPort } = minio;
|
||||||
const { destinationDockerId, destinationDocker, id } = service;
|
const { destinationDockerId, destinationDocker, id } = service;
|
||||||
@ -101,6 +102,7 @@ export default async function (): Promise<void | {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
console.log(error);
|
||||||
return ErrorHandler(error.response?.body || error);
|
return ErrorHandler(error.response?.body || error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,12 +12,7 @@ export const post: RequestHandler = async (event) => {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const service = await db.getService({ id, teamId });
|
const service = await db.getService({ id, teamId });
|
||||||
const {
|
const { destinationDockerId, destinationDocker } = service;
|
||||||
destinationDockerId,
|
|
||||||
destinationDocker,
|
|
||||||
fqdn,
|
|
||||||
minio: { publicPort }
|
|
||||||
} = service;
|
|
||||||
await db.updateMinioService({ id, publicPort: null });
|
await db.updateMinioService({ id, publicPort: null });
|
||||||
if (destinationDockerId) {
|
if (destinationDockerId) {
|
||||||
const engine = destinationDocker.engine;
|
const engine = destinationDocker.engine;
|
||||||
@ -30,11 +25,6 @@ export const post: RequestHandler = async (event) => {
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
}
|
}
|
||||||
try {
|
|
||||||
await stopTcpHttpProxy(destinationDocker, publicPort);
|
|
||||||
} catch (error) {
|
|
||||||
console.log(error);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
@ -37,6 +37,7 @@ export const get: RequestHandler = async (event) => {
|
|||||||
const service = await db.prisma.service.findFirst({ where: { id } });
|
const service = await db.prisma.service.findFirst({ where: { id } });
|
||||||
if (service?.fqdn) {
|
if (service?.fqdn) {
|
||||||
const domain = getDomain(service.fqdn);
|
const domain = getDomain(service.fqdn);
|
||||||
|
const isHttps = service.fqdn.startsWith('https://');
|
||||||
traefik = {
|
traefik = {
|
||||||
[type]: {
|
[type]: {
|
||||||
routers: {
|
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