fix: Reconfigure proxy on restart

This commit is contained in:
Andras Bacsai 2022-03-01 14:02:46 +01:00
parent 61679749eb
commit e722f8a87c
9 changed files with 46 additions and 28 deletions

View File

@ -27,6 +27,15 @@ async function main() {
proxyUser: cuid()
}
});
} else {
await prisma.setting.update({
where: {
id: settingsFound.id
},
data: {
proxyHash: null
}
});
}
const localDocker = await prisma.destinationDocker.findFirst({
where: { engine: '/var/run/docker.sock' }

View File

@ -79,7 +79,7 @@ backend backend-certbot
{{#applications}}
{{#isRunning}}
# updatedAt={{updatedAt}}
backend {{domain}}
option forwardfor
server {{id}} {{id}}:{{port}} check
@ -88,7 +88,7 @@ backend {{domain}}
{{#services}}
{{#isRunning}}
# updatedAt={{updatedAt}}
backend {{domain}}
option forwardfor
server {{id}} {{id}}:{{port}} check
@ -96,6 +96,7 @@ backend {{domain}}
{{/services}}
{{#coolify}}
# updatedAt={{updatedAt}}
backend {{domain}}
option forwardfor
option httpchk GET /undead.json
@ -128,7 +129,8 @@ export async function configureHAProxy() {
id,
port,
destinationDocker: { engine, network },
settings: { previews }
settings: { previews },
updatedAt
} = application;
const isRunning = await checkContainer(engine, id);
const domain = getDomain(fqdn);
@ -143,7 +145,8 @@ export async function configureHAProxy() {
isRunning,
isHttps,
redirectValue,
redirectTo: isWWW ? domain : 'www.' + domain
redirectTo: isWWW ? domain : 'www.' + domain,
updatedAt: updatedAt.getTime()
});
}
if (previews) {
@ -166,7 +169,8 @@ export async function configureHAProxy() {
isRunning,
isHttps,
redirectValue,
redirectTo: isWWW ? previewDomain : 'www.' + previewDomain
redirectTo: isWWW ? previewDomain : 'www.' + previewDomain,
updatedAt: updatedAt.getTime()
});
}
}
@ -187,7 +191,8 @@ export async function configureHAProxy() {
fqdn,
id,
type,
destinationDocker: { engine }
destinationDocker: { engine },
updatedAt
} = service;
const found = db.supportedServiceTypesAndVersions.find((a) => a.name === type);
if (found) {
@ -207,12 +212,13 @@ export async function configureHAProxy() {
isRunning,
isHttps,
redirectValue,
redirectTo: isWWW ? domain : 'www.' + domain
redirectTo: isWWW ? domain : 'www.' + domain,
updatedAt: updatedAt.getTime()
});
}
}
}
const { fqdn } = await db.prisma.setting.findFirst();
const { fqdn, updatedAt } = await db.prisma.setting.findFirst();
if (fqdn) {
const domain = getDomain(fqdn);
const isHttps = fqdn.startsWith('https://');
@ -224,7 +230,8 @@ export async function configureHAProxy() {
domain,
isHttps,
redirectValue,
redirectTo: isWWW ? domain : 'www.' + domain
redirectTo: isWWW ? domain : 'www.' + domain,
updatedAt
});
}
const output = mustache.render(template, data);

View File

@ -255,6 +255,6 @@ export default async function (job) {
sentry.captureException(error);
throw new Error(error);
}
saveBuildLog({ line: 'Proxy will be configured shortly.', buildId, applicationId });
saveBuildLog({ line: 'Proxy will be updated shortly.', buildId, applicationId });
}
}

View File

@ -86,7 +86,7 @@
async function handleDeploySubmit() {
try {
const { buildId } = await post(`/applications/${id}/deploy.json`, { ...application });
return await goto(`/applications/${id}/logs/build?buildId=${buildId}`);
return window.location.assign(`/applications/${id}/logs/build?buildId=${buildId}`);
} catch ({ error }) {
return errorNotification(error);
}

View File

@ -29,6 +29,7 @@ export const post: RequestHandler = async (event) => {
.digest('hex');
await db.prisma.application.update({ where: { id }, data: { configHash } });
}
await db.prisma.application.update({ where: { id }, data: { updatedAt: new Date() } });
await buildQueue.add(buildId, { build_id: buildId, type: 'manual', ...applicationFound });
return {
status: 200,

View File

@ -51,7 +51,6 @@
build.took = data.builds[0].took;
build.since = data.builds[0].since;
}
window.location.reload();
return build;
});
return;

View File

@ -117,6 +117,8 @@
setTimeout(() => {
window.location.reload();
}, 5000);
} finally {
restarting = false;
}
}
}

View File

@ -84,6 +84,10 @@ export const post: RequestHandler = async (event) => {
data: { configHash }
});
}
await db.prisma.application.update({
where: { id: applicationFound.id },
data: { updatedAt: new Date() }
});
await buildQueue.add(buildId, {
build_id: buildId,
type: 'webhook_commit',
@ -128,6 +132,10 @@ export const post: RequestHandler = async (event) => {
pullmergeRequestAction === 'reopened' ||
pullmergeRequestAction === 'synchronize'
) {
await db.prisma.application.update({
where: { id: applicationFound.id },
data: { updatedAt: new Date() }
});
await buildQueue.add(buildId, {
build_id: buildId,
type: 'webhook_pr',
@ -143,16 +151,8 @@ export const post: RequestHandler = async (event) => {
};
} else if (pullmergeRequestAction === 'closed') {
if (applicationFound.destinationDockerId) {
const domain = getDomain(applicationFound.fqdn);
const isHttps = applicationFound.fqdn.startsWith('https://');
const isWWW = applicationFound.fqdn.includes('www.');
const fqdn = `${isHttps ? 'https://' : 'http://'}${
isWWW ? 'www.' : ''
}${pullmergeRequestId}.${domain}`;
const id = `${applicationFound.id}-${pullmergeRequestId}`;
const engine = applicationFound.destinationDocker.engine;
await removeDestinationDocker({ id, engine });
}
return {

View File

@ -48,6 +48,10 @@ export const post: RequestHandler = async (event) => {
data: { configHash }
});
}
await db.prisma.application.update({
where: { id: applicationFound.id },
data: { updatedAt: new Date() }
});
await buildQueue.add(buildId, {
build_id: buildId,
type: 'webhook_commit',
@ -125,6 +129,10 @@ export const post: RequestHandler = async (event) => {
action === 'open' ||
action === 'update'
) {
await db.prisma.application.update({
where: { id: applicationFound.id },
data: { updatedAt: new Date() }
});
await buildQueue.add(buildId, {
build_id: buildId,
type: 'webhook_mr',
@ -140,16 +148,8 @@ export const post: RequestHandler = async (event) => {
};
} else if (action === 'close') {
if (applicationFound.destinationDockerId) {
const domain = getDomain(applicationFound.fqdn);
const isHttps = applicationFound.fqdn.startsWith('https://');
const isWWW = applicationFound.fqdn.includes('www.');
const fqdn = `${isHttps ? 'https://' : 'http://'}${
isWWW ? 'www.' : ''
}${pullmergeRequestId}.${domain}`;
const id = `${applicationFound.id}-${pullmergeRequestId}`;
const engine = applicationFound.destinationDocker.engine;
await removeDestinationDocker({ id, engine });
}