Skip to content

An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.

fix: Reconfigure proxy on restart

Andras Bacsaie722f8a87ce0
diff --git a/prisma/seed.cjs b/prisma/seed.cjs
index 2dacc9a728..61f3928f6f 100644
--- a/prisma/seed.cjs
+++ b/prisma/seed.cjs
@@ -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' }
diff --git a/src/lib/haproxy/configuration.ts b/src/lib/haproxy/configuration.ts
index a881d9f31d..524e0026c1 100644
--- a/src/lib/haproxy/configuration.ts
+++ b/src/lib/haproxy/configuration.ts
@@ -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);
diff --git a/src/lib/queues/builder.ts b/src/lib/queues/builder.ts
index 54976b0502..cefcfc6ed7 100644
--- a/src/lib/queues/builder.ts
+++ b/src/lib/queues/builder.ts
@@ -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 });
}
}
diff --git a/src/routes/applications/[id]/__layout.svelte b/src/routes/applications/[id]/__layout.svelte
index c803bf515b..3a04337e47 100644
--- a/src/routes/applications/[id]/__layout.svelte
+++ b/src/routes/applications/[id]/__layout.svelte
@@ -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);
}
diff --git a/src/routes/applications/[id]/deploy.json.ts b/src/routes/applications/[id]/deploy.json.ts
index 059401ba14..ce5182c448 100644
--- a/src/routes/applications/[id]/deploy.json.ts
+++ b/src/routes/applications/[id]/deploy.json.ts
@@ -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,
diff --git a/src/routes/applications/[id]/logs/build/index.svelte b/src/routes/applications/[id]/logs/build/index.svelte
index 6ce49f78a2..f88985265c 100644
--- a/src/routes/applications/[id]/logs/build/index.svelte
+++ b/src/routes/applications/[id]/logs/build/index.svelte
@@ -51,7 +51,6 @@
build.took = data.builds[0].took;
build.since = data.builds[0].since;
}
- window.location.reload();
return build;
});
return;
diff --git a/src/routes/destinations/[id]/_LocalDocker.svelte b/src/routes/destinations/[id]/_LocalDocker.svelte
index 287f544ef5..bf4d8447a9 100644
--- a/src/routes/destinations/[id]/_LocalDocker.svelte
+++ b/src/routes/destinations/[id]/_LocalDocker.svelte
@@ -117,6 +117,8 @@
setTimeout(() => {
window.location.reload();
}, 5000);
+ } finally {
+ restarting = false;
}
}
}
diff --git a/src/routes/webhooks/github/events.ts b/src/routes/webhooks/github/events.ts
index 91ac4d3014..40a60e29ba 100644
--- a/src/routes/webhooks/github/events.ts
+++ b/src/routes/webhooks/github/events.ts
@@ -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 {
diff --git a/src/routes/webhooks/gitlab/events.ts b/src/routes/webhooks/gitlab/events.ts
index b87e59395f..89aec7b4dd 100644
--- a/src/routes/webhooks/gitlab/events.ts
+++ b/src/routes/webhooks/gitlab/events.ts
@@ -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 });
}