fix: WIP Traefik
This commit is contained in:
@@ -122,6 +122,7 @@ export async function stopTcpHttpProxy(
|
|||||||
}
|
}
|
||||||
if (forceName) containerName = forceName;
|
if (forceName) containerName = forceName;
|
||||||
const found = await checkContainer(engine, containerName);
|
const found = await checkContainer(engine, containerName);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (found) {
|
if (found) {
|
||||||
return await asyncExecShell(
|
return await asyncExecShell(
|
||||||
@@ -137,15 +138,15 @@ export async function startTraefikTCPProxy(
|
|||||||
id: string,
|
id: string,
|
||||||
publicPort: number,
|
publicPort: number,
|
||||||
privatePort: number,
|
privatePort: number,
|
||||||
volume?: string
|
type?: string
|
||||||
): Promise<{ stdout: string; stderr: string } | Error> {
|
): Promise<{ stdout: string; stderr: string } | Error> {
|
||||||
const { network, engine } = destinationDocker;
|
const { network, engine } = destinationDocker;
|
||||||
const host = getEngine(engine);
|
const host = getEngine(engine);
|
||||||
|
|
||||||
const containerName = `${id}-${publicPort}`;
|
const containerName = `${id}-${publicPort}`;
|
||||||
const found = await checkContainer(engine, containerName, true);
|
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 {
|
try {
|
||||||
if (foundDependentContainer && !found) {
|
if (foundDependentContainer && !found) {
|
||||||
const { stdout: Config } = await asyncExecShell(
|
const { stdout: Config } = await asyncExecShell(
|
||||||
@@ -210,7 +211,6 @@ export async function startTcpProxy(
|
|||||||
const containerName = `haproxy-for-${publicPort}`;
|
const containerName = `haproxy-for-${publicPort}`;
|
||||||
const found = await checkContainer(engine, containerName, true);
|
const found = await checkContainer(engine, containerName, true);
|
||||||
const foundDependentContainer = await checkContainer(engine, id, true);
|
const foundDependentContainer = await checkContainer(engine, id, true);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (foundDependentContainer && !found) {
|
if (foundDependentContainer && !found) {
|
||||||
const { stdout: Config } = await asyncExecShell(
|
const { stdout: Config } = await asyncExecShell(
|
||||||
|
@@ -71,7 +71,7 @@ export default async function (): Promise<void | {
|
|||||||
ftpPublicPort,
|
ftpPublicPort,
|
||||||
`haproxy-for-${ftpPublicPort}`
|
`haproxy-for-${ftpPublicPort}`
|
||||||
);
|
);
|
||||||
await startTraefikTCPProxy(destinationDocker, `${id}-ftp`, ftpPublicPort, 22);
|
await startTraefikTCPProxy(destinationDocker, id, ftpPublicPort, 22, 'wordpressftp');
|
||||||
} else {
|
} else {
|
||||||
await stopTcpHttpProxy(id, destinationDocker, ftpPublicPort, `${id}-${ftpPublicPort}`);
|
await stopTcpHttpProxy(id, destinationDocker, ftpPublicPort, `${id}-${ftpPublicPort}`);
|
||||||
await startTcpProxy(destinationDocker, `${id}-ftp`, ftpPublicPort, 22);
|
await startTcpProxy(destinationDocker, `${id}-ftp`, ftpPublicPort, 22);
|
||||||
|
@@ -36,12 +36,16 @@ export const post: RequestHandler = async (event) => {
|
|||||||
});
|
});
|
||||||
const {
|
const {
|
||||||
service: { destinationDockerId, destinationDocker },
|
service: { destinationDockerId, destinationDocker },
|
||||||
ftpPublicPort: oldPublicPort,
|
ftpPublicPort,
|
||||||
ftpUser: user,
|
ftpUser: user,
|
||||||
ftpPassword: savedPassword,
|
ftpPassword: savedPassword,
|
||||||
ftpHostKey,
|
ftpHostKey,
|
||||||
ftpHostKeyPrivate
|
ftpHostKeyPrivate
|
||||||
} = data;
|
} = data;
|
||||||
|
const { network, engine } = destinationDocker;
|
||||||
|
const settings = await db.prisma.setting.findFirst();
|
||||||
|
const host = getEngine(engine);
|
||||||
|
if (ftpEnabled) {
|
||||||
if (user) ftpUser = user;
|
if (user) ftpUser = user;
|
||||||
if (savedPassword) ftpPassword = decrypt(savedPassword);
|
if (savedPassword) ftpPassword = decrypt(savedPassword);
|
||||||
|
|
||||||
@@ -76,9 +80,7 @@ export const post: RequestHandler = async (event) => {
|
|||||||
} else {
|
} else {
|
||||||
await asyncExecShell(`echo "${decrypt(ftpHostKeyPrivate)}" > ${hostkeyDir}/${id}.rsa`);
|
await asyncExecShell(`echo "${decrypt(ftpHostKeyPrivate)}" > ${hostkeyDir}/${id}.rsa`);
|
||||||
}
|
}
|
||||||
const { network, engine } = destinationDocker;
|
|
||||||
const host = getEngine(engine);
|
|
||||||
if (ftpEnabled) {
|
|
||||||
await db.prisma.wordpress.update({
|
await db.prisma.wordpress.update({
|
||||||
where: { serviceId: id },
|
where: { serviceId: id },
|
||||||
data: {
|
data: {
|
||||||
@@ -147,12 +149,15 @@ export const post: RequestHandler = async (event) => {
|
|||||||
await asyncExecShell(
|
await asyncExecShell(
|
||||||
`DOCKER_HOST=${host} docker compose -f ${hostkeyDir}/${id}-docker-compose.yml up -d`
|
`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);
|
|
||||||
}
|
}
|
||||||
|
return {
|
||||||
|
status: 201,
|
||||||
|
body: {
|
||||||
|
publicPort,
|
||||||
|
ftpUser,
|
||||||
|
ftpPassword
|
||||||
|
}
|
||||||
|
};
|
||||||
} else {
|
} else {
|
||||||
await db.prisma.wordpress.update({
|
await db.prisma.wordpress.update({
|
||||||
where: { serviceId: id },
|
where: { serviceId: id },
|
||||||
@@ -165,19 +170,7 @@ export const post: RequestHandler = async (event) => {
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
await stopTcpHttpProxy(destinationDocker, oldPublicPort);
|
await stopTcpHttpProxy(id, destinationDocker, ftpPublicPort);
|
||||||
}
|
|
||||||
}
|
|
||||||
if (ftpEnabled) {
|
|
||||||
return {
|
|
||||||
status: 201,
|
|
||||||
body: {
|
|
||||||
publicPort,
|
|
||||||
ftpUser,
|
|
||||||
ftpPassword
|
|
||||||
}
|
|
||||||
};
|
|
||||||
} else {
|
|
||||||
return {
|
return {
|
||||||
status: 200,
|
status: 200,
|
||||||
body: {}
|
body: {}
|
||||||
|
@@ -166,7 +166,7 @@
|
|||||||
await post(`/update.json`, { type: to });
|
await post(`/update.json`, { type: to });
|
||||||
const data = await get(`/settings.json`);
|
const data = await get(`/settings.json`);
|
||||||
$isTraefikUsed = data.settings.isTraefikUsed;
|
$isTraefikUsed = data.settings.isTraefikUsed;
|
||||||
return toast.push('Proxy migration completed.');
|
return toast.push('Proxy migration started, it takes a few seconds.');
|
||||||
} catch ({ error }) {
|
} catch ({ error }) {
|
||||||
return errorNotification(error);
|
return errorNotification(error);
|
||||||
} finally {
|
} finally {
|
||||||
|
@@ -64,12 +64,12 @@ export const post: RequestHandler = async (event) => {
|
|||||||
}
|
}
|
||||||
} else if (type === 'traefik') {
|
} else if (type === 'traefik') {
|
||||||
try {
|
try {
|
||||||
const found = await checkContainer('/var/run/docker.sock', 'coolify-haproxy');
|
// const found = await checkContainer('/var/run/docker.sock', 'coolify-haproxy');
|
||||||
if (found) {
|
// if (found) {
|
||||||
await asyncExecShell(`docker stop -t 0 coolify-haproxy`);
|
// await asyncExecShell(`docker stop -t 0 coolify-haproxy`);
|
||||||
await asyncExecShell(`docker rm coolify-haproxy`);
|
// await asyncExecShell(`docker rm coolify-haproxy`);
|
||||||
}
|
// }
|
||||||
await startTraefikProxy('/var/run/docker.sock');
|
// await startTraefikProxy('/var/run/docker.sock');
|
||||||
await db.prisma.setting.update({
|
await db.prisma.setting.update({
|
||||||
where: { id: settings.id },
|
where: { id: settings.id },
|
||||||
data: { isTraefikUsed: true }
|
data: { isTraefikUsed: true }
|
||||||
@@ -83,12 +83,12 @@ export const post: RequestHandler = async (event) => {
|
|||||||
}
|
}
|
||||||
} else if (type === 'haproxy') {
|
} else if (type === 'haproxy') {
|
||||||
try {
|
try {
|
||||||
const found = await checkContainer('/var/run/docker.sock', 'coolify-proxy');
|
// const found = await checkContainer('/var/run/docker.sock', 'coolify-proxy');
|
||||||
if (found) {
|
// if (found) {
|
||||||
await asyncExecShell(`docker stop -t 0 coolify-proxy`);
|
// await asyncExecShell(`docker stop -t 0 coolify-proxy`);
|
||||||
await asyncExecShell(`docker rm coolify-proxy`);
|
// await asyncExecShell(`docker rm coolify-proxy`);
|
||||||
}
|
// }
|
||||||
await startCoolifyProxy('/var/run/docker.sock');
|
// await startCoolifyProxy('/var/run/docker.sock');
|
||||||
await db.prisma.setting.update({
|
await db.prisma.setting.update({
|
||||||
where: { id: settings.id },
|
where: { id: settings.id },
|
||||||
data: { isTraefikUsed: false }
|
data: { isTraefikUsed: false }
|
||||||
|
@@ -40,14 +40,14 @@ export const get: RequestHandler = async (event) => {
|
|||||||
traefik = {
|
traefik = {
|
||||||
[type]: {
|
[type]: {
|
||||||
routers: {
|
routers: {
|
||||||
[`${id}-${publicPort}`]: {
|
[id]: {
|
||||||
entrypoints: [type],
|
entrypoints: [type],
|
||||||
rule: `Host(\`${domain}\`)`,
|
rule: `Host(\`${domain}\`)`,
|
||||||
service: `${id}-${publicPort}`
|
service: id
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
services: {
|
services: {
|
||||||
[`${id}-${publicPort}`]: {
|
[id]: {
|
||||||
loadbalancer: {
|
loadbalancer: {
|
||||||
servers: [{ url: `http://${id}:${privatePort}` }]
|
servers: [{ url: `http://${id}:${privatePort}` }]
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user