fix: Remove wrong/stuck proxy configurations
This commit is contained in:
@@ -119,7 +119,8 @@ export async function getApplicationWebhook({ projectId, branch }) {
|
|||||||
}
|
}
|
||||||
export async function getApplicationById({ id }) {
|
export async function getApplicationById({ id }) {
|
||||||
const body = await prisma.application.findFirst({
|
const body = await prisma.application.findFirst({
|
||||||
where: { id }
|
where: { id },
|
||||||
|
include: { destinationDocker: true }
|
||||||
});
|
});
|
||||||
|
|
||||||
return { ...body };
|
return { ...body };
|
||||||
|
@@ -187,6 +187,59 @@ export async function reloadHaproxy(engine) {
|
|||||||
const host = getEngine(engine);
|
const host = getEngine(engine);
|
||||||
return await asyncExecShell(`DOCKER_HOST=${host} docker exec coolify-haproxy kill -HUP 1`);
|
return await asyncExecShell(`DOCKER_HOST=${host} docker exec coolify-haproxy kill -HUP 1`);
|
||||||
}
|
}
|
||||||
|
export async function checkProxyConfigurations() {
|
||||||
|
const haproxy = await haproxyInstance();
|
||||||
|
await checkHAProxy(haproxy);
|
||||||
|
try {
|
||||||
|
const stats: any = await haproxy.get(`v2/services/haproxy/stats/native`).json();
|
||||||
|
for (const stat of stats[0].stats) {
|
||||||
|
if (stat.stats.status === 'DOWN' && stat.type === 'server') {
|
||||||
|
const {
|
||||||
|
name,
|
||||||
|
backend_name: backendName,
|
||||||
|
stats: { lastchg }
|
||||||
|
} = stat;
|
||||||
|
const application = await db.getApplicationById(name);
|
||||||
|
if (!application) {
|
||||||
|
const transactionId = await getNextTransactionId();
|
||||||
|
await haproxy
|
||||||
|
.delete(`v2/services/haproxy/configuration/backends/${backendName}`, {
|
||||||
|
searchParams: {
|
||||||
|
transaction_id: transactionId
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.json();
|
||||||
|
return await completeTransaction(transactionId);
|
||||||
|
}
|
||||||
|
const found = await checkContainer(application.destinationDocker.engine, name);
|
||||||
|
if (!found) {
|
||||||
|
const transactionId = await getNextTransactionId();
|
||||||
|
await haproxy
|
||||||
|
.delete(`v2/services/haproxy/configuration/backends/${backendName}`, {
|
||||||
|
searchParams: {
|
||||||
|
transaction_id: transactionId
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.json();
|
||||||
|
return await completeTransaction(transactionId);
|
||||||
|
}
|
||||||
|
if (lastchg > 120) {
|
||||||
|
const transactionId = await getNextTransactionId();
|
||||||
|
await haproxy
|
||||||
|
.delete(`v2/services/haproxy/configuration/backends/${backendName}`, {
|
||||||
|
searchParams: {
|
||||||
|
transaction_id: transactionId
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.json();
|
||||||
|
await completeTransaction(transactionId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
export async function configureProxyForApplication({ domain, imageId, applicationId, port }) {
|
export async function configureProxyForApplication({ domain, imageId, applicationId, port }) {
|
||||||
const haproxy = await haproxyInstance();
|
const haproxy = await haproxyInstance();
|
||||||
await checkHAProxy(haproxy);
|
await checkHAProxy(haproxy);
|
||||||
|
@@ -4,7 +4,12 @@ import * as buildpacks from '../buildPacks';
|
|||||||
import * as importers from '../importers';
|
import * as importers from '../importers';
|
||||||
import { dockerInstance } from '../docker';
|
import { dockerInstance } from '../docker';
|
||||||
import { asyncExecShell, createDirectories, getDomain, getEngine, saveBuildLog } from '../common';
|
import { asyncExecShell, createDirectories, getDomain, getEngine, saveBuildLog } from '../common';
|
||||||
import { configureProxyForApplication, reloadHaproxy, setWwwRedirection } from '../haproxy';
|
import {
|
||||||
|
checkProxyConfigurations,
|
||||||
|
configureProxyForApplication,
|
||||||
|
reloadHaproxy,
|
||||||
|
setWwwRedirection
|
||||||
|
} from '../haproxy';
|
||||||
import * as db from '$lib/database';
|
import * as db from '$lib/database';
|
||||||
import { decrypt } from '$lib/crypto';
|
import { decrypt } from '$lib/crypto';
|
||||||
import { sentry } from '$lib/common';
|
import { sentry } from '$lib/common';
|
||||||
@@ -253,6 +258,7 @@ export default async function (job) {
|
|||||||
try {
|
try {
|
||||||
if (destinationDockerId && destinationDocker.isCoolifyProxyUsed) {
|
if (destinationDockerId && destinationDocker.isCoolifyProxyUsed) {
|
||||||
saveBuildLog({ line: 'Proxy configuration started!', buildId, applicationId });
|
saveBuildLog({ line: 'Proxy configuration started!', buildId, applicationId });
|
||||||
|
await checkProxyConfigurations();
|
||||||
await configureProxyForApplication({ domain, imageId, applicationId, port });
|
await configureProxyForApplication({ domain, imageId, applicationId, port });
|
||||||
if (isHttps) await letsEncrypt({ domain, id: applicationId });
|
if (isHttps) await letsEncrypt({ domain, id: applicationId });
|
||||||
await setWwwRedirection(fqdn);
|
await setWwwRedirection(fqdn);
|
||||||
|
@@ -6,6 +6,7 @@ import type { RequestHandler } from '@sveltejs/kit';
|
|||||||
import { letsEncrypt } from '$lib/letsencrypt';
|
import { letsEncrypt } from '$lib/letsencrypt';
|
||||||
import {
|
import {
|
||||||
checkHAProxy,
|
checkHAProxy,
|
||||||
|
checkProxyConfigurations,
|
||||||
configureSimpleServiceProxyOn,
|
configureSimpleServiceProxyOn,
|
||||||
reloadHaproxy,
|
reloadHaproxy,
|
||||||
setWwwRedirection,
|
setWwwRedirection,
|
||||||
@@ -95,6 +96,7 @@ export const post: RequestHandler = async (event) => {
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
await asyncExecShell(`DOCKER_HOST=${host} docker compose -f ${composeFileDestination} up -d`);
|
await asyncExecShell(`DOCKER_HOST=${host} docker compose -f ${composeFileDestination} up -d`);
|
||||||
|
await checkProxyConfigurations();
|
||||||
await configureSimpleServiceProxyOn({ id, domain, port: consolePort });
|
await configureSimpleServiceProxyOn({ id, domain, port: consolePort });
|
||||||
await db.updateMinioService({ id, publicPort });
|
await db.updateMinioService({ id, publicPort });
|
||||||
await startHttpProxy(destinationDocker, id, publicPort, apiPort);
|
await startHttpProxy(destinationDocker, id, publicPort, apiPort);
|
||||||
|
@@ -6,6 +6,7 @@ import type { RequestHandler } from '@sveltejs/kit';
|
|||||||
import { letsEncrypt } from '$lib/letsencrypt';
|
import { letsEncrypt } from '$lib/letsencrypt';
|
||||||
import {
|
import {
|
||||||
checkHAProxy,
|
checkHAProxy,
|
||||||
|
checkProxyConfigurations,
|
||||||
configureSimpleServiceProxyOn,
|
configureSimpleServiceProxyOn,
|
||||||
reloadHaproxy,
|
reloadHaproxy,
|
||||||
setWwwRedirection
|
setWwwRedirection
|
||||||
@@ -55,6 +56,7 @@ export const post: RequestHandler = async (event) => {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
await asyncExecShell(`DOCKER_HOST=${host} docker compose -f ${composeFileDestination} up -d`);
|
await asyncExecShell(`DOCKER_HOST=${host} docker compose -f ${composeFileDestination} up -d`);
|
||||||
|
await checkProxyConfigurations();
|
||||||
await configureSimpleServiceProxyOn({ id, domain, port: 8080 });
|
await configureSimpleServiceProxyOn({ id, domain, port: 8080 });
|
||||||
|
|
||||||
if (isHttps) {
|
if (isHttps) {
|
||||||
|
@@ -6,6 +6,7 @@ import type { RequestHandler } from '@sveltejs/kit';
|
|||||||
import { letsEncrypt } from '$lib/letsencrypt';
|
import { letsEncrypt } from '$lib/letsencrypt';
|
||||||
import {
|
import {
|
||||||
checkHAProxy,
|
checkHAProxy,
|
||||||
|
checkProxyConfigurations,
|
||||||
configureSimpleServiceProxyOn,
|
configureSimpleServiceProxyOn,
|
||||||
reloadHaproxy,
|
reloadHaproxy,
|
||||||
setWwwRedirection
|
setWwwRedirection
|
||||||
@@ -186,6 +187,7 @@ COPY ./init-db.sh /docker-entrypoint-initdb.d/init-db.sh`;
|
|||||||
await asyncExecShell(
|
await asyncExecShell(
|
||||||
`DOCKER_HOST=${host} docker compose -f ${composeFileDestination} up --build -d`
|
`DOCKER_HOST=${host} docker compose -f ${composeFileDestination} up --build -d`
|
||||||
);
|
);
|
||||||
|
await checkProxyConfigurations();
|
||||||
await configureSimpleServiceProxyOn({ id, domain, port: 8000 });
|
await configureSimpleServiceProxyOn({ id, domain, port: 8000 });
|
||||||
|
|
||||||
if (isHttps) {
|
if (isHttps) {
|
||||||
|
@@ -6,6 +6,7 @@ import type { RequestHandler } from '@sveltejs/kit';
|
|||||||
import { letsEncrypt } from '$lib/letsencrypt';
|
import { letsEncrypt } from '$lib/letsencrypt';
|
||||||
import {
|
import {
|
||||||
checkHAProxy,
|
checkHAProxy,
|
||||||
|
checkProxyConfigurations,
|
||||||
configureSimpleServiceProxyOn,
|
configureSimpleServiceProxyOn,
|
||||||
reloadHaproxy,
|
reloadHaproxy,
|
||||||
setWwwRedirection
|
setWwwRedirection
|
||||||
@@ -73,6 +74,7 @@ export const post: RequestHandler = async (event) => {
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
await asyncExecShell(`DOCKER_HOST=${host} docker compose -f ${composeFileDestination} up -d`);
|
await asyncExecShell(`DOCKER_HOST=${host} docker compose -f ${composeFileDestination} up -d`);
|
||||||
|
await checkProxyConfigurations();
|
||||||
await configureSimpleServiceProxyOn({ id, domain, port: 80 });
|
await configureSimpleServiceProxyOn({ id, domain, port: 80 });
|
||||||
|
|
||||||
if (isHttps) {
|
if (isHttps) {
|
||||||
|
@@ -6,6 +6,7 @@ import type { RequestHandler } from '@sveltejs/kit';
|
|||||||
import { letsEncrypt } from '$lib/letsencrypt';
|
import { letsEncrypt } from '$lib/letsencrypt';
|
||||||
import {
|
import {
|
||||||
checkHAProxy,
|
checkHAProxy,
|
||||||
|
checkProxyConfigurations,
|
||||||
configureSimpleServiceProxyOn,
|
configureSimpleServiceProxyOn,
|
||||||
reloadHaproxy,
|
reloadHaproxy,
|
||||||
setWwwRedirection
|
setWwwRedirection
|
||||||
@@ -83,6 +84,7 @@ export const post: RequestHandler = async (event) => {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
await asyncExecShell(`DOCKER_HOST=${host} docker compose -f ${composeFileDestination} up -d`);
|
await asyncExecShell(`DOCKER_HOST=${host} docker compose -f ${composeFileDestination} up -d`);
|
||||||
|
await checkProxyConfigurations();
|
||||||
await configureSimpleServiceProxyOn({ id, domain, port: 8080 });
|
await configureSimpleServiceProxyOn({ id, domain, port: 8080 });
|
||||||
|
|
||||||
if (isHttps) {
|
if (isHttps) {
|
||||||
|
@@ -6,6 +6,7 @@ import type { RequestHandler } from '@sveltejs/kit';
|
|||||||
import { letsEncrypt } from '$lib/letsencrypt';
|
import { letsEncrypt } from '$lib/letsencrypt';
|
||||||
import {
|
import {
|
||||||
checkHAProxy,
|
checkHAProxy,
|
||||||
|
checkProxyConfigurations,
|
||||||
configureSimpleServiceProxyOn,
|
configureSimpleServiceProxyOn,
|
||||||
reloadHaproxy,
|
reloadHaproxy,
|
||||||
setWwwRedirection
|
setWwwRedirection
|
||||||
@@ -120,6 +121,7 @@ export const post: RequestHandler = async (event) => {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
await asyncExecShell(`DOCKER_HOST=${host} docker compose -f ${composeFileDestination} up -d`);
|
await asyncExecShell(`DOCKER_HOST=${host} docker compose -f ${composeFileDestination} up -d`);
|
||||||
|
await checkProxyConfigurations();
|
||||||
await configureSimpleServiceProxyOn({ id, domain, port: 80 });
|
await configureSimpleServiceProxyOn({ id, domain, port: 80 });
|
||||||
|
|
||||||
if (isHttps) {
|
if (isHttps) {
|
||||||
|
@@ -3,6 +3,7 @@ import { getDomain, getUserDetails } from '$lib/common';
|
|||||||
import * as db from '$lib/database';
|
import * as db from '$lib/database';
|
||||||
import { listSettings, ErrorHandler } from '$lib/database';
|
import { listSettings, ErrorHandler } from '$lib/database';
|
||||||
import {
|
import {
|
||||||
|
checkProxyConfigurations,
|
||||||
configureCoolifyProxyOff,
|
configureCoolifyProxyOff,
|
||||||
configureCoolifyProxyOn,
|
configureCoolifyProxyOn,
|
||||||
forceSSLOnApplication,
|
forceSSLOnApplication,
|
||||||
@@ -79,6 +80,7 @@ export const post: RequestHandler = async (event) => {
|
|||||||
|
|
||||||
const { fqdn, isRegistrationEnabled, dualCerts, minPort, maxPort } = await event.request.json();
|
const { fqdn, isRegistrationEnabled, dualCerts, minPort, maxPort } = await event.request.json();
|
||||||
try {
|
try {
|
||||||
|
await checkProxyConfigurations();
|
||||||
const {
|
const {
|
||||||
id,
|
id,
|
||||||
fqdn: oldFqdn,
|
fqdn: oldFqdn,
|
||||||
|
Reference in New Issue
Block a user