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: WIP Traefik

Andras Bacsaieb62888c39ff
diff --git a/src/lib/haproxy/index.ts b/src/lib/haproxy/index.ts
index f440500476..5101862870 100644
--- a/src/lib/haproxy/index.ts
+++ b/src/lib/haproxy/index.ts
@@ -122,6 +122,7 @@ export async function stopTcpHttpProxy(
}
if (forceName) containerName = forceName;
const found = await checkContainer(engine, containerName);
+
try {
if (found) {
return await asyncExecShell(
@@ -137,15 +138,15 @@ export async function startTraefikTCPProxy(
id: string,
publicPort: number,
privatePort: number,
- volume?: string
+ type?: string
): Promise<{ stdout: string; stderr: string } | Error> {
const { network, engine } = destinationDocker;
const host = getEngine(engine);
-
const containerName = `${id}-${publicPort}`;
const found = await checkContainer(engine, containerName, true);
- const foundDependentContainer = await checkContainer(engine, id, true);
-
+ let dependentId = id;
+ if (type === 'wordpressftp') dependentId = `${id}-ftp`;
+ const foundDependentContainer = await checkContainer(engine, dependentId, true);
try {
if (foundDependentContainer && !found) {
const { stdout: Config } = await asyncExecShell(
@@ -210,7 +211,6 @@ export async function startTcpProxy(
const containerName = `haproxy-for-${publicPort}`;
const found = await checkContainer(engine, containerName, true);
const foundDependentContainer = await checkContainer(engine, id, true);
-
try {
if (foundDependentContainer && !found) {
const { stdout: Config } = await asyncExecShell(
diff --git a/src/lib/queues/proxyTcpHttp.ts b/src/lib/queues/proxyTcpHttp.ts
index 1367987771..c70339bad0 100644
--- a/src/lib/queues/proxyTcpHttp.ts
+++ b/src/lib/queues/proxyTcpHttp.ts
@@ -71,7 +71,7 @@ export default async function (): Promise<void | {
ftpPublicPort,
`haproxy-for-${ftpPublicPort}`
);
- await startTraefikTCPProxy(destinationDocker, `${id}-ftp`, ftpPublicPort, 22);
+ await startTraefikTCPProxy(destinationDocker, id, ftpPublicPort, 22, 'wordpressftp');
} else {
await stopTcpHttpProxy(id, destinationDocker, ftpPublicPort, `${id}-${ftpPublicPort}`);
await startTcpProxy(destinationDocker, `${id}-ftp`, ftpPublicPort, 22);
diff --git a/src/routes/services/[id]/wordpress/ftp.json.ts b/src/routes/services/[id]/wordpress/ftp.json.ts
index 8267e1807b..fab9cd7df4 100644
--- a/src/routes/services/[id]/wordpress/ftp.json.ts
+++ b/src/routes/services/[id]/wordpress/ftp.json.ts
@@ -36,49 +36,51 @@ export const post: RequestHandler = async (event) => {
});
const {
service: { destinationDockerId, destinationDocker },
- ftpPublicPort: oldPublicPort,
+ ftpPublicPort,
ftpUser: user,
ftpPassword: savedPassword,
ftpHostKey,
ftpHostKeyPrivate
} = data;
- if (user) ftpUser = user;
- if (savedPassword) ftpPassword = decrypt(savedPassword);
+ const { network, engine } = destinationDocker;
+ const settings = await db.prisma.setting.findFirst();
+ const host = getEngine(engine);
+ if (ftpEnabled) {
+ if (user) ftpUser = user;
+ if (savedPassword) ftpPassword = decrypt(savedPassword);
+
+ const { stdout: password } = await asyncExecShell(
+ `echo ${ftpPassword} | openssl passwd -1 -stdin`
+ );
+ if (destinationDockerId) {
+ try {
+ await fs.stat(hostkeyDir);
+ } catch (error) {
+ await asyncExecShell(`mkdir -p ${hostkeyDir}`);
+ }
+ if (!ftpHostKey) {
+ await asyncExecShell(
+ `ssh-keygen -t ed25519 -f ssh_host_ed25519_key -N "" -q -f ${hostkeyDir}/${id}.ed25519`
+ );
+ const { stdout: ftpHostKey } = await asyncExecShell(`cat ${hostkeyDir}/${id}.ed25519`);
+ await db.prisma.wordpress.update({
+ where: { serviceId: id },
+ data: { ftpHostKey: encrypt(ftpHostKey) }
+ });
+ } else {
+ await asyncExecShell(`echo "${decrypt(ftpHostKey)}" > ${hostkeyDir}/${id}.ed25519`);
+ }
+ if (!ftpHostKeyPrivate) {
+ await asyncExecShell(`ssh-keygen -t rsa -b 4096 -N "" -f ${hostkeyDir}/${id}.rsa`);
+ const { stdout: ftpHostKeyPrivate } = await asyncExecShell(`cat ${hostkeyDir}/${id}.rsa`);
+ await db.prisma.wordpress.update({
+ where: { serviceId: id },
+ data: { ftpHostKeyPrivate: encrypt(ftpHostKeyPrivate) }
+ });
+ } else {
+ await asyncExecShell(`echo "${decrypt(ftpHostKeyPrivate)}" > ${hostkeyDir}/${id}.rsa`);
+ }
- const { stdout: password } = await asyncExecShell(
- `echo ${ftpPassword} | openssl passwd -1 -stdin`
- );
- if (destinationDockerId) {
- try {
- await fs.stat(hostkeyDir);
- } catch (error) {
- await asyncExecShell(`mkdir -p ${hostkeyDir}`);
- }
- if (!ftpHostKey) {
- await asyncExecShell(
- `ssh-keygen -t ed25519 -f ssh_host_ed25519_key -N "" -q -f ${hostkeyDir}/${id}.ed25519`
- );
- const { stdout: ftpHostKey } = await asyncExecShell(`cat ${hostkeyDir}/${id}.ed25519`);
- await db.prisma.wordpress.update({
- where: { serviceId: id },
- data: { ftpHostKey: encrypt(ftpHostKey) }
- });
- } else {
- await asyncExecShell(`echo "${decrypt(ftpHostKey)}" > ${hostkeyDir}/${id}.ed25519`);
- }
- if (!ftpHostKeyPrivate) {
- await asyncExecShell(`ssh-keygen -t rsa -b 4096 -N "" -f ${hostkeyDir}/${id}.rsa`);
- const { stdout: ftpHostKeyPrivate } = await asyncExecShell(`cat ${hostkeyDir}/${id}.rsa`);
- await db.prisma.wordpress.update({
- where: { serviceId: id },
- data: { ftpHostKeyPrivate: encrypt(ftpHostKeyPrivate) }
- });
- } else {
- await asyncExecShell(`echo "${decrypt(ftpHostKeyPrivate)}" > ${hostkeyDir}/${id}.rsa`);
- }
- const { network, engine } = destinationDocker;
- const host = getEngine(engine);
- if (ftpEnabled) {
await db.prisma.wordpress.update({
where: { serviceId: id },
data: {
@@ -147,28 +149,7 @@ export const post: RequestHandler = async (event) => {
await asyncExecShell(
`DOCKER_HOST=${host} docker compose -f ${hostkeyDir}/${id}-docker-compose.yml up -d`
);
- const settings = await db.prisma.setting.findFirst();
- if (settings.isTraefikUsed) {
- await startTraefikTCPProxy(destinationDocker, `${id}-ftp`, publicPort, 22);
- } else {
- await startTcpProxy(destinationDocker, `${id}-ftp`, publicPort, 22);
- }
- } else {
- await db.prisma.wordpress.update({
- where: { serviceId: id },
- data: { ftpPublicPort: null }
- });
- try {
- await asyncExecShell(
- `DOCKER_HOST=${host} docker stop -t 0 ${id}-ftp && docker rm ${id}-ftp`
- );
- } catch (error) {
- //
- }
- await stopTcpHttpProxy(destinationDocker, oldPublicPort);
}
- }
- if (ftpEnabled) {
return {
status: 201,
body: {
@@ -178,6 +159,18 @@ export const post: RequestHandler = async (event) => {
}
};
} else {
+ await db.prisma.wordpress.update({
+ where: { serviceId: id },
+ data: { ftpPublicPort: null }
+ });
+ try {
+ await asyncExecShell(
+ `DOCKER_HOST=${host} docker stop -t 0 ${id}-ftp && docker rm ${id}-ftp`
+ );
+ } catch (error) {
+ //
+ }
+ await stopTcpHttpProxy(id, destinationDocker, ftpPublicPort);
return {
status: 200,
body: {}
diff --git a/src/routes/settings/index.svelte b/src/routes/settings/index.svelte
index 8c975d2a92..6eeeb2bdf0 100644
--- a/src/routes/settings/index.svelte
+++ b/src/routes/settings/index.svelte
@@ -166,7 +166,7 @@
await post(`/update.json`, { type: to });
const data = await get(`/settings.json`);
$isTraefikUsed = data.settings.isTraefikUsed;
- return toast.push('Proxy migration completed.');
+ return toast.push('Proxy migration started, it takes a few seconds.');
} catch ({ error }) {
return errorNotification(error);
} finally {
diff --git a/src/routes/update.json.ts b/src/routes/update.json.ts
index ef5f0920b9..8d697f32ed 100644
--- a/src/routes/update.json.ts
+++ b/src/routes/update.json.ts
@@ -64,12 +64,12 @@ export const post: RequestHandler = async (event) => {
}
} else if (type === 'traefik') {
try {
- const found = await checkContainer('/var/run/docker.sock', 'coolify-haproxy');
- if (found) {
- await asyncExecShell(`docker stop -t 0 coolify-haproxy`);
- await asyncExecShell(`docker rm coolify-haproxy`);
- }
- await startTraefikProxy('/var/run/docker.sock');
+ // const found = await checkContainer('/var/run/docker.sock', 'coolify-haproxy');
+ // if (found) {
+ // await asyncExecShell(`docker stop -t 0 coolify-haproxy`);
+ // await asyncExecShell(`docker rm coolify-haproxy`);
+ // }
+ // await startTraefikProxy('/var/run/docker.sock');
await db.prisma.setting.update({
where: { id: settings.id },
data: { isTraefikUsed: true }
@@ -83,12 +83,12 @@ export const post: RequestHandler = async (event) => {
}
} else if (type === 'haproxy') {
try {
- const found = await checkContainer('/var/run/docker.sock', 'coolify-proxy');
- if (found) {
- await asyncExecShell(`docker stop -t 0 coolify-proxy`);
- await asyncExecShell(`docker rm coolify-proxy`);
- }
- await startCoolifyProxy('/var/run/docker.sock');
+ // const found = await checkContainer('/var/run/docker.sock', 'coolify-proxy');
+ // if (found) {
+ // await asyncExecShell(`docker stop -t 0 coolify-proxy`);
+ // await asyncExecShell(`docker rm coolify-proxy`);
+ // }
+ // await startCoolifyProxy('/var/run/docker.sock');
await db.prisma.setting.update({
where: { id: settings.id },
data: { isTraefikUsed: false }
diff --git a/src/routes/webhooks/traefik/other.json.ts b/src/routes/webhooks/traefik/other.json.ts
index ab0aa7c9ef..ea99e770eb 100644
--- a/src/routes/webhooks/traefik/other.json.ts
+++ b/src/routes/webhooks/traefik/other.json.ts
@@ -40,14 +40,14 @@ export const get: RequestHandler = async (event) => {
traefik = {
[type]: {
routers: {
- [`${id}-${publicPort}`]: {
+ [id]: {
entrypoints: [type],
rule: `Host(\`${domain}\`)`,
- service: `${id}-${publicPort}`
+ service: id
}
},
services: {
- [`${id}-${publicPort}`]: {
+ [id]: {
loadbalancer: {
servers: [{ url: `http://${id}:${privatePort}` }]
}