fix: Add HTTP proxy checks

This commit is contained in:
Andras Bacsai 2022-04-14 15:04:18 +02:00
parent 2bd3802a6f
commit 3a252509d0
2 changed files with 19 additions and 5 deletions

View File

@ -127,10 +127,10 @@ export async function startTcpProxy(
const containerName = `haproxy-for-${publicPort}`;
const found = await checkContainer(engine, containerName);
const foundDB = await checkContainer(engine, id);
const foundDependentContainer = await checkContainer(engine, id);
try {
if (foundDB && !found) {
if (foundDependentContainer && !found) {
const { stdout: Config } = await asyncExecShell(
`DOCKER_HOST="${host}" docker network inspect bridge --format '{{json .IPAM.Config }}'`
);
@ -157,10 +157,10 @@ export async function startHttpProxy(
const containerName = `haproxy-for-${publicPort}`;
const found = await checkContainer(engine, containerName);
const foundDB = await checkContainer(engine, id);
const foundDependentContainer = await checkContainer(engine, id);
try {
if (foundDB && !found) {
if (foundDependentContainer && !found) {
const { stdout: Config } = await asyncExecShell(
`DOCKER_HOST="${host}" docker network inspect bridge --format '{{json .IPAM.Config }}'`
);

View File

@ -1,11 +1,12 @@
import { ErrorHandler, generateDatabaseConfiguration, prisma } from '$lib/database';
import { checkContainer, startTcpProxy } from '$lib/haproxy';
import { startHttpProxy, startTcpProxy } from '$lib/haproxy';
export default async function (): Promise<void | {
status: number;
body: { message: string; error: string };
}> {
try {
// TCP Proxies
const databasesWithPublicPort = await prisma.database.findMany({
where: { publicPort: { not: null } },
include: { settings: true, destinationDocker: true }
@ -28,6 +29,19 @@ export default async function (): Promise<void | {
await startTcpProxy(destinationDocker, `${id}-ftp`, ftpPublicPort, 22);
}
}
// 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) {
await startHttpProxy(destinationDocker, id, publicPort, 9000);
}
}
} catch (error) {
return ErrorHandler(error.response?.body || error);
}