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.

debug more

Andras Bacsai26d86cbcb563
diff --git a/apps/api/src/index.ts b/apps/api/src/index.ts
index 8c81b0350c..9befdd981e 100644
--- a/apps/api/src/index.ts
+++ b/apps/api/src/index.ts
@@ -5,7 +5,7 @@ import env from '@fastify/env';
import cookie from '@fastify/cookie';
import path, { join } from 'path';
import autoLoad from '@fastify/autoload';
-import { asyncExecShell, isDev, listSettings, prisma, version } from './lib/common';
+import { asyncExecShell, createRemoteEngineConfiguration, isDev, listSettings, prisma, version } from './lib/common';
import { scheduler } from './lib/scheduler';
import { compareVersions } from 'compare-versions';
import Graceful from '@ladjs/graceful'
@@ -136,10 +136,14 @@ fastify.listen({ port, host }, async (err: any, address: any) => {
// scheduler.workers.has('infrastructure') && scheduler.workers.get('infrastructure').postMessage("action:cleanupPrismaEngines")
// }, 60000)
- await getArch();
- await getIPAddress();
+ await Promise.all([
+ getArch(),
+ getIPAddress(),
+ // configureRemoteDockers(),
+ ])
});
async function getIPAddress() {
+ console.log('getIPAddress')
const { publicIpv4, publicIpv6 } = await import('public-ip')
try {
const settings = await listSettings();
@@ -167,6 +171,7 @@ async function initServer() {
} catch (error) { }
}
async function getArch() {
+ console.log('getArch')
try {
const settings = await prisma.setting.findFirst({})
if (settings && !settings.arch) {
@@ -176,3 +181,19 @@ async function getArch() {
}
+
+async function configureRemoteDockers() {
+ console.log('configureRemoteDockers')
+ try {
+ const remoteDocker = await prisma.destinationDocker.findMany({
+ where: { remoteVerified: true, remoteEngine: true }
+ });
+ if (remoteDocker.length > 0) {
+ for (const docker of remoteDocker) {
+ await createRemoteEngineConfiguration(docker.id)
+ }
+ }
+ } catch (error) {
+ console.log(error)
+ }
+}
diff --git a/apps/api/src/jobs/infrastructure.ts b/apps/api/src/jobs/infrastructure.ts
index 0dda946b70..97369fb3ab 100644
--- a/apps/api/src/jobs/infrastructure.ts
+++ b/apps/api/src/jobs/infrastructure.ts
@@ -1,7 +1,7 @@
import { parentPort } from 'node:worker_threads';
import axios from 'axios';
import { compareVersions } from 'compare-versions';
-import { asyncExecShell, cleanupDockerStorage, executeDockerCmd, isDev, prisma, startTraefikTCPProxy, generateDatabaseConfiguration, startTraefikProxy, listSettings, version } from '../lib/common';
+import { asyncExecShell, cleanupDockerStorage, executeDockerCmd, isDev, prisma, startTraefikTCPProxy, generateDatabaseConfiguration, startTraefikProxy, listSettings, version, createRemoteEngineConfiguration } from '../lib/common';
async function autoUpdater() {
try {
@@ -45,7 +45,7 @@ async function checkProxies() {
let portReachable;
const { arch, ipv4, ipv6 } = await listSettings();
-
+
// Coolify Proxy local
const engine = '/var/run/docker.sock';
const localDocker = await prisma.destinationDocker.findFirst({
@@ -59,13 +59,20 @@ async function checkProxies() {
}
// Coolify Proxy remote
const remoteDocker = await prisma.destinationDocker.findMany({
- where: { engine, isCoolifyProxyUsed: true, remoteEngine: true }
+ where: { remoteEngine: true, remoteVerified: true }
});
if (remoteDocker.length > 0) {
for (const docker of remoteDocker) {
- portReachable = await isReachable(80, { host: docker.remoteIpAddress })
- if (!portReachable) {
- await startTraefikProxy(docker.id);
+ if (docker.isCoolifyProxyUsed) {
+ portReachable = await isReachable(80, { host: docker.remoteIpAddress })
+ if (!portReachable) {
+ await startTraefikProxy(docker.id);
+ }
+ }
+ try {
+ await createRemoteEngineConfiguration(docker.id)
+ } catch (error) {
+ console.log({ error })
}
}
}
diff --git a/apps/api/src/lib/common.ts b/apps/api/src/lib/common.ts
index 6b8a84b0c8..b97a6dfbff 100644
--- a/apps/api/src/lib/common.ts
+++ b/apps/api/src/lib/common.ts
@@ -451,19 +451,24 @@ export async function getFreeSSHLocalPort(id: string): Promise<number | boolean>
}
export async function createRemoteEngineConfiguration(id: string) {
+
const homedir = os.homedir();
const sshKeyFile = `/tmp/id_rsa-${id}`
+ console.log(sshKeyFile)
const localPort = await getFreeSSHLocalPort(id);
+ console.log(localPort)
const { sshKey: { privateKey }, remoteIpAddress, remotePort, remoteUser } = await prisma.destinationDocker.findFirst({ where: { id }, include: { sshKey: true } })
await fs.writeFile(sshKeyFile, decrypt(privateKey) + '\n', { encoding: 'utf8', mode: 400 })
// Needed for remote docker compose
const { stdout: numberOfSSHAgentsRunning } = await asyncExecShell(`ps ax | grep [s]sh-agent | grep coolify-ssh-agent.pid | grep -v grep | wc -l`)
+ console.log({ numberOfSSHAgentsRunning })
if (numberOfSSHAgentsRunning !== '' && Number(numberOfSSHAgentsRunning.trim()) == 0) {
await asyncExecShell(`eval $(ssh-agent -sa /tmp/coolify-ssh-agent.pid)`)
}
await asyncExecShell(`SSH_AUTH_SOCK=/tmp/coolify-ssh-agent.pid ssh-add -q ${sshKeyFile}`)
const { stdout: numberOfSSHTunnelsRunning } = await asyncExecShell(`ps ax | grep 'ssh -F /dev/null -o StrictHostKeyChecking no -fNL ${localPort}:localhost:${remotePort}' | grep -v grep | wc -l`)
+ console.log({ numberOfSSHTunnelsRunning })
if (numberOfSSHTunnelsRunning !== '' && Number(numberOfSSHTunnelsRunning.trim()) == 0) {
try {
await asyncExecShell(`SSH_AUTH_SOCK=/tmp/coolify-ssh-agent.pid ssh -F /dev/null -o "StrictHostKeyChecking no" -fNL ${localPort}:localhost:${remotePort} ${remoteUser}@${remoteIpAddress}`)
@@ -490,6 +495,7 @@ export async function createRemoteEngineConfiguration(id: string) {
} catch (error) {
await fs.mkdir(`${homedir}/.ssh/`)
}
+ console.log(config.toString())
return await fs.writeFile(`${homedir}/.ssh/config`, sshConfig.stringify(config))
}
export async function executeDockerCmd({ debug, buildId, applicationId, dockerId, command }: { debug?: boolean, buildId?: string, applicationId?: string, dockerId: string, command: string }): Promise<any> {