wip(fix): traefik

This commit is contained in:
Andras Bacsai
2022-05-18 12:32:53 +02:00
parent 59086e9eb4
commit dc3add495c
5 changed files with 64 additions and 58 deletions

View File

@@ -3,7 +3,6 @@ import * as db from '$lib/database';
import { promises as fs } from 'fs';
import yaml from 'js-yaml';
import type { RequestHandler } from '@sveltejs/kit';
import { startHttpProxy } from '$lib/haproxy';
import { ErrorHandler, getFreePort, getServiceImage } from '$lib/database';
import { makeLabelForServices } from '$lib/buildPacks/common';
import type { ComposeFile } from '$lib/types/composeFile';
@@ -95,7 +94,6 @@ export const post: RequestHandler = async (event) => {
await asyncExecShell(`DOCKER_HOST=${host} docker compose -f ${composeFileDestination} pull`);
await asyncExecShell(`DOCKER_HOST=${host} docker compose -f ${composeFileDestination} up -d`);
await db.updateMinioService({ id, publicPort });
await startHttpProxy(destinationDocker, id, publicPort, apiPort);
return {
status: 200
};

View File

@@ -6,38 +6,10 @@ import { listServicesWithIncludes } from '$lib/database';
import { checkContainer } from '$lib/haproxy';
import type { RequestHandler } from '@sveltejs/kit';
const traefik = {
http: {
routers: {},
services: {},
middlewares: {
'redirect-to-https': {
redirectscheme: {
scheme: 'https'
}
},
'redirect-to-http': {
redirectscheme: {
scheme: 'http'
}
},
'redirect-to-non-www': {
redirectregex: {
regex: '^https?://www\\.(.+)',
replacement: 'http://${1}'
}
},
'redirect-to-www': {
redirectregex: {
regex: '^https?://(?:www\\.)?(.+)',
replacement: 'http://www.${1}'
}
}
}
}
};
function configureMiddleware({ id, port, domain, nakedDomain, isHttps, isWWW, isDualCerts }) {
function configureMiddleware(
{ id, port, domain, nakedDomain, isHttps, isWWW, isDualCerts },
traefik
) {
if (isHttps) {
traefik.http.routers[id] = {
entrypoints: ['web'],
@@ -155,6 +127,36 @@ function configureMiddleware({ id, port, domain, nakedDomain, isHttps, isWWW, is
}
}
export const get: RequestHandler = async (event) => {
const traefik = {
http: {
routers: {},
services: {},
middlewares: {
'redirect-to-https': {
redirectscheme: {
scheme: 'https'
}
},
'redirect-to-http': {
redirectscheme: {
scheme: 'http'
}
},
'redirect-to-non-www': {
redirectregex: {
regex: '^https?://www\\.(.+)',
replacement: 'http://${1}'
}
},
'redirect-to-www': {
redirectregex: {
regex: '^https?://(?:www\\.)?(.+)',
replacement: 'http://www.${1}'
}
}
}
}
};
const applications = await db.prisma.application.findMany({
include: { destinationDocker: true, settings: true }
});
@@ -230,7 +232,6 @@ export const get: RequestHandler = async (event) => {
type,
destinationDocker,
destinationDockerId,
updatedAt,
dualCerts,
plausibleAnalytics
} = service;
@@ -288,11 +289,11 @@ export const get: RequestHandler = async (event) => {
});
}
for (const application of data.applications) {
configureMiddleware(application);
configureMiddleware(application, traefik);
}
for (const service of data.services) {
const { id, scriptName } = service;
configureMiddleware(service);
configureMiddleware(service, traefik);
if (scriptName) {
traefik.http.middlewares[`${id}-redir`] = {
@@ -309,9 +310,14 @@ export const get: RequestHandler = async (event) => {
}
}
for (const coolify of data.coolify) {
configureMiddleware(coolify);
configureMiddleware(coolify, traefik);
}
if (Object.keys(traefik.http.routers).length === 0) {
traefik.http.routers = null;
}
if (Object.keys(traefik.http.services).length === 0) {
traefik.http.services = null;
}
return {
status: 200,
body: {

View File

@@ -40,14 +40,14 @@ export const get: RequestHandler = async (event) => {
traefik = {
[type]: {
routers: {
[id]: {
[`${id}-${publicPort}`]: {
entrypoints: [type],
rule: `Host(\`${domain}\`)`,
service: id
service: `${id}-${publicPort}`
}
},
services: {
[id]: {
[`${id}-${publicPort}`]: {
loadbalancer: {
servers: [{ url: `http://${id}:${privatePort}` }]
}