remove console logs

This commit is contained in:
Andras Bacsai 2022-09-05 13:15:58 +02:00
parent 6ca1d978d4
commit c9aecd51f3
3 changed files with 1 additions and 23 deletions
apps/api/src
index.ts
lib
routes/api/v1/destinations

@ -143,7 +143,6 @@ fastify.listen({ port, host }, async (err: any, address: any) => {
]) ])
}); });
async function getIPAddress() { async function getIPAddress() {
console.log('getIPAddress')
const { publicIpv4, publicIpv6 } = await import('public-ip') const { publicIpv4, publicIpv6 } = await import('public-ip')
try { try {
const settings = await listSettings(); const settings = await listSettings();
@ -171,7 +170,6 @@ async function initServer() {
} catch (error) { } } catch (error) { }
} }
async function getArch() { async function getArch() {
console.log('getArch')
try { try {
const settings = await prisma.setting.findFirst({}) const settings = await prisma.setting.findFirst({})
if (settings && !settings.arch) { if (settings && !settings.arch) {
@ -180,10 +178,7 @@ async function getArch() {
} catch (error) { } } catch (error) { }
} }
async function configureRemoteDockers() { async function configureRemoteDockers() {
console.log('configureRemoteDockers')
try { try {
const remoteDocker = await prisma.destinationDocker.findMany({ const remoteDocker = await prisma.destinationDocker.findMany({
where: { remoteVerified: true, remoteEngine: true } where: { remoteVerified: true, remoteEngine: true }
@ -193,7 +188,5 @@ async function configureRemoteDockers() {
await createRemoteEngineConfiguration(docker.id) await createRemoteEngineConfiguration(docker.id)
} }
} }
} catch (error) { } catch (error) { }
console.log(error)
}
} }

@ -451,17 +451,13 @@ export async function getFreeSSHLocalPort(id: string): Promise<number | boolean>
} }
export async function createRemoteEngineConfiguration(id: string) { export async function createRemoteEngineConfiguration(id: string) {
const homedir = os.homedir(); const homedir = os.homedir();
const sshKeyFile = `/tmp/id_rsa-${id}` const sshKeyFile = `/tmp/id_rsa-${id}`
console.log(sshKeyFile)
const localPort = await getFreeSSHLocalPort(id); const localPort = await getFreeSSHLocalPort(id);
console.log(localPort)
const { sshKey: { privateKey }, remoteIpAddress, remotePort, remoteUser } = await prisma.destinationDocker.findFirst({ where: { id }, include: { sshKey: true } }) 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 }) await fs.writeFile(sshKeyFile, decrypt(privateKey) + '\n', { encoding: 'utf8', mode: 400 })
// Needed for remote docker compose // 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`) 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) { if (numberOfSSHAgentsRunning !== '' && Number(numberOfSSHAgentsRunning.trim()) == 0) {
try { try {
await fs.stat(`/tmp/coolify-ssh-agent.pid`) await fs.stat(`/tmp/coolify-ssh-agent.pid`)
@ -472,11 +468,9 @@ export async function createRemoteEngineConfiguration(id: string) {
await asyncExecShell(`SSH_AUTH_SOCK=/tmp/coolify-ssh-agent.pid ssh-add -q ${sshKeyFile}`) 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`) 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) { if (numberOfSSHTunnelsRunning !== '' && Number(numberOfSSHTunnelsRunning.trim()) == 0) {
try { try {
await asyncExecShell(`SSH_AUTH_SOCK=/tmp/coolify-ssh-agent.pid ssh -F /dev/null -o "StrictHostKeyChecking no" -fNL ${localPort}:localhost:${remotePort} ${remoteUser}@${remoteIpAddress}`) await asyncExecShell(`SSH_AUTH_SOCK=/tmp/coolify-ssh-agent.pid ssh -F /dev/null -o "StrictHostKeyChecking no" -fNL ${localPort}:localhost:${remotePort} ${remoteUser}@${remoteIpAddress}`)
} catch (error) { } catch (error) {
console.log(error) console.log(error)
} }
@ -499,7 +493,6 @@ export async function createRemoteEngineConfiguration(id: string) {
} catch (error) { } catch (error) {
await fs.mkdir(`${homedir}/.ssh/`) await fs.mkdir(`${homedir}/.ssh/`)
} }
console.log(config.toString())
return await fs.writeFile(`${homedir}/.ssh/config`, sshConfig.stringify(config)) 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> { export async function executeDockerCmd({ debug, buildId, applicationId, dockerId, command }: { debug?: boolean, buildId?: string, applicationId?: string, dockerId: string, command: string }): Promise<any> {
@ -1369,7 +1362,6 @@ export function makeLabelForServices(type) {
} }
export function errorHandler({ status = 500, message = 'Unknown error.' }: { status: number, message: string | any }) { export function errorHandler({ status = 500, message = 'Unknown error.' }: { status: number, message: string | any }) {
if (message.message) message = message.message if (message.message) message = message.message
console.log({ status, message })
throw { status, message }; throw { status, message };
} }
export async function generateSshKeyPair(): Promise<{ publicKey: string; privateKey: string }> { export async function generateSshKeyPair(): Promise<{ publicKey: string; privateKey: string }> {

@ -209,28 +209,21 @@ export async function verifyRemoteDockerEngine(request: FastifyRequest<OnlyId>,
try { try {
const { id } = request.params; const { id } = request.params;
await createRemoteEngineConfiguration(id); await createRemoteEngineConfiguration(id);
const { remoteIpAddress, remoteUser, network, isCoolifyProxyUsed } = await prisma.destinationDocker.findFirst({ where: { id } }) const { remoteIpAddress, remoteUser, network, isCoolifyProxyUsed } = await prisma.destinationDocker.findFirst({ where: { id } })
const host = `ssh://${remoteUser}@${remoteIpAddress}` const host = `ssh://${remoteUser}@${remoteIpAddress}`
console.log({ host })
const { stdout } = await asyncExecShell(`DOCKER_HOST=${host} docker network ls --filter 'name=${network}' --no-trunc --format "{{json .}}"`); const { stdout } = await asyncExecShell(`DOCKER_HOST=${host} docker network ls --filter 'name=${network}' --no-trunc --format "{{json .}}"`);
console.log({ stdout })
if (!stdout) { if (!stdout) {
await asyncExecShell(`DOCKER_HOST=${host} docker network create --attachable ${network}`); await asyncExecShell(`DOCKER_HOST=${host} docker network create --attachable ${network}`);
} }
const { stdout: coolifyNetwork } = await asyncExecShell(`DOCKER_HOST=${host} docker network ls --filter 'name=coolify-infra' --no-trunc --format "{{json .}}"`); const { stdout: coolifyNetwork } = await asyncExecShell(`DOCKER_HOST=${host} docker network ls --filter 'name=coolify-infra' --no-trunc --format "{{json .}}"`);
console.log({ coolifyNetwork })
if (!coolifyNetwork) { if (!coolifyNetwork) {
await asyncExecShell(`DOCKER_HOST=${host} docker network create --attachable coolify-infra`); await asyncExecShell(`DOCKER_HOST=${host} docker network create --attachable coolify-infra`);
} }
console.log({ isCoolifyProxyUsed })
if (isCoolifyProxyUsed) await startTraefikProxy(id); if (isCoolifyProxyUsed) await startTraefikProxy(id);
await prisma.destinationDocker.update({ where: { id }, data: { remoteVerified: true } }) await prisma.destinationDocker.update({ where: { id }, data: { remoteVerified: true } })
return reply.code(201).send() return reply.code(201).send()
} catch ({ status, message }) { } catch ({ status, message }) {
console.log({ status, message })
return errorHandler({ status, message }) return errorHandler({ status, message })
} }
} }