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() proxyUser: cuid()
} }
}); });
} else {
await prisma.setting.update({
where: {
id: settingsFound.id
},
data: {
proxyHash: null
}
});
} }
const localDocker = await prisma.destinationDocker.findFirst({ const localDocker = await prisma.destinationDocker.findFirst({
where: { engine: '/var/run/docker.sock' } where: { engine: '/var/run/docker.sock' }

View File

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

View File

@ -255,6 +255,6 @@ export default async function (job) {
sentry.captureException(error); sentry.captureException(error);
throw new Error(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() { async function handleDeploySubmit() {
try { try {
const { buildId } = await post(`/applications/${id}/deploy.json`, { ...application }); 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 }) { } catch ({ error }) {
return errorNotification(error); return errorNotification(error);
} }

View File

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

View File

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

View File

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

View File

@ -84,6 +84,10 @@ export const post: RequestHandler = async (event) => {
data: { configHash } data: { configHash }
}); });
} }
await db.prisma.application.update({
where: { id: applicationFound.id },
data: { updatedAt: new Date() }
});
await buildQueue.add(buildId, { await buildQueue.add(buildId, {
build_id: buildId, build_id: buildId,
type: 'webhook_commit', type: 'webhook_commit',
@ -128,6 +132,10 @@ export const post: RequestHandler = async (event) => {
pullmergeRequestAction === 'reopened' || pullmergeRequestAction === 'reopened' ||
pullmergeRequestAction === 'synchronize' pullmergeRequestAction === 'synchronize'
) { ) {
await db.prisma.application.update({
where: { id: applicationFound.id },
data: { updatedAt: new Date() }
});
await buildQueue.add(buildId, { await buildQueue.add(buildId, {
build_id: buildId, build_id: buildId,
type: 'webhook_pr', type: 'webhook_pr',
@ -143,16 +151,8 @@ export const post: RequestHandler = async (event) => {
}; };
} else if (pullmergeRequestAction === 'closed') { } else if (pullmergeRequestAction === 'closed') {
if (applicationFound.destinationDockerId) { 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 id = `${applicationFound.id}-${pullmergeRequestId}`;
const engine = applicationFound.destinationDocker.engine; const engine = applicationFound.destinationDocker.engine;
await removeDestinationDocker({ id, engine }); await removeDestinationDocker({ id, engine });
} }
return { return {

View File

@ -48,6 +48,10 @@ export const post: RequestHandler = async (event) => {
data: { configHash } data: { configHash }
}); });
} }
await db.prisma.application.update({
where: { id: applicationFound.id },
data: { updatedAt: new Date() }
});
await buildQueue.add(buildId, { await buildQueue.add(buildId, {
build_id: buildId, build_id: buildId,
type: 'webhook_commit', type: 'webhook_commit',
@ -125,6 +129,10 @@ export const post: RequestHandler = async (event) => {
action === 'open' || action === 'open' ||
action === 'update' action === 'update'
) { ) {
await db.prisma.application.update({
where: { id: applicationFound.id },
data: { updatedAt: new Date() }
});
await buildQueue.add(buildId, { await buildQueue.add(buildId, {
build_id: buildId, build_id: buildId,
type: 'webhook_mr', type: 'webhook_mr',
@ -140,16 +148,8 @@ export const post: RequestHandler = async (event) => {
}; };
} else if (action === 'close') { } else if (action === 'close') {
if (applicationFound.destinationDockerId) { 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 id = `${applicationFound.id}-${pullmergeRequestId}`;
const engine = applicationFound.destinationDocker.engine; const engine = applicationFound.destinationDocker.engine;
await removeDestinationDocker({ id, engine }); await removeDestinationDocker({ id, engine });
} }