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: rde

Andras Bacsai132707caa715
diff --git a/apps/api/src/lib/common.ts b/apps/api/src/lib/common.ts
index abf967c30e..70173a31ee 100644
--- a/apps/api/src/lib/common.ts
+++ b/apps/api/src/lib/common.ts
@@ -565,9 +565,9 @@ export async function executeCommand({ command, dockerId = null, sshCommand = fa
}
if (sshCommand) {
if (shell) {
- return execaCommand(`ssh ${remoteIpAddress}-remote ${command}`, { shell: true, stdio: 'inherit' });
+ return execaCommand(`ssh ${remoteIpAddress}-remote ${command}`);
}
- return await execa('ssh', [`${remoteIpAddress}-remote`, ...dockerArgs]);
+ return await execa('ssh', [`${remoteIpAddress}-remote`, dockerCommand, ...dockerArgs]);
}
if (stream) {
return await new Promise(async (resolve, reject) => {
diff --git a/apps/api/src/routes/api/v1/destinations/handlers.ts b/apps/api/src/routes/api/v1/destinations/handlers.ts
index e376d33ea5..f5ccb2614e 100644
--- a/apps/api/src/routes/api/v1/destinations/handlers.ts
+++ b/apps/api/src/routes/api/v1/destinations/handlers.ts
@@ -103,7 +103,7 @@ export async function newDestination(request: FastifyRequest<NewDestination>, re
return reply.code(201).send({ id: destination.id });
} else {
const destination = await prisma.destinationDocker.create({
- data: { name, teams: { connect: { id: teamId } }, engine, network, isCoolifyProxyUsed, remoteEngine: true, remoteIpAddress, remoteUser, remotePort }
+ data: { name, teams: { connect: { id: teamId } }, engine, network, isCoolifyProxyUsed, remoteEngine: true, remoteIpAddress, remoteUser, remotePort: Number(remotePort) }
});
return reply.code(201).send({ id: destination.id })
}
@@ -203,22 +203,31 @@ export async function assignSSHKey(request: FastifyRequest) {
}
}
export async function verifyRemoteDockerEngineFn(id: string) {
- await createRemoteEngineConfiguration(id);
const { remoteIpAddress, network, isCoolifyProxyUsed } = await prisma.destinationDocker.findFirst({ where: { id } })
- const host = `ssh://${remoteIpAddress}-remote`
- const { stdout } = await executeCommand({ command: `docker network ls --filter 'name=${network}' --no-trunc --format "{{json .}}"`, dockerId: id });
- if (!stdout) {
+ const daemonJson = `daemon-${id}.json`
+ try {
+ await executeCommand({ sshCommand: true, command: `docker network inspect ${network}`, dockerId: id });
+ } catch (error) {
await executeCommand({ command: `docker network create --attachable ${network}`, dockerId: id });
}
- const { stdout: coolifyNetwork } = await executeCommand({ command: `docker network ls --filter 'name=coolify-infra' --no-trunc --format "{{json .}}"`, dockerId: id });
- if (!coolifyNetwork) {
+
+ try {
+ await executeCommand({ sshCommand: true, command: `docker network inspect coolify-infra`, dockerId: id });
+ } catch (error) {
await executeCommand({ command: `docker network create --attachable coolify-infra`, dockerId: id });
}
+
if (isCoolifyProxyUsed) await startTraefikProxy(id);
+ let isUpdated = false;
+ let daemonJsonParsed = {
+ "live-restore": true,
+ "features": {
+ "buildkit": true
+ }
+ };
try {
const { stdout: daemonJson } = await executeCommand({ sshCommand: true, dockerId: id, command: `cat /etc/docker/daemon.json` });
- let daemonJsonParsed = JSON.parse(daemonJson);
- let isUpdated = false;
+ daemonJsonParsed = JSON.parse(daemonJson);
if (!daemonJsonParsed['live-restore'] || daemonJsonParsed['live-restore'] !== true) {
isUpdated = true;
daemonJsonParsed['live-restore'] = true
@@ -230,21 +239,19 @@ export async function verifyRemoteDockerEngineFn(id: string) {
buildkit: true
}
}
+ } catch (error) {
+ isUpdated = true;
+ }
+ try {
if (isUpdated) {
- await executeCommand({ sshCommand: true, shell: true, dockerId: id, command: `echo '${JSON.stringify(daemonJsonParsed)}' > /etc/docker/daemon.json` });
+ await executeCommand({ shell: true, command: `echo '${JSON.stringify(daemonJsonParsed, null, 2)}' > /tmp/${daemonJson}` })
+ await executeCommand({ dockerId: id, command: `scp /tmp/${daemonJson} ${remoteIpAddress}-remote:/etc/docker/daemon.json` });
+ await executeCommand({ command: `rm /tmp/${daemonJson}` })
await executeCommand({ sshCommand: true, dockerId: id, command: `systemctl restart docker` });
}
- } catch (error) {
- const daemonJsonParsed = {
- "live-restore": true,
- "features": {
- "buildkit": true
- }
- }
- await executeCommand({ sshCommand: true, shell: true, dockerId: id, command: `echo '${JSON.stringify(daemonJsonParsed)}' > /etc/docker/daemon.json` });
- await executeCommand({ sshCommand: true, dockerId: id, command: `systemctl restart docker` });
- } finally {
await prisma.destinationDocker.update({ where: { id }, data: { remoteVerified: true } })
+ } catch (error) {
+ throw new Error('Error while verifying remote docker engine')
}
}
export async function verifyRemoteDockerEngine(request: FastifyRequest<OnlyId>, reply: FastifyReply) {