From cb980fb8149ee605d9affe939b852ead37f6ef73 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Mon, 3 Apr 2023 08:59:48 +0200 Subject: [PATCH] fix: docker compose generator --- apps/api/src/index.ts | 2 +- apps/api/src/jobs/deployApplication.ts | 8 ++--- apps/api/src/lib/buildPacks/compose.ts | 44 ++++++++++++++++---------- apps/api/src/lib/common.ts | 2 +- package.json | 2 +- 5 files changed, 35 insertions(+), 23 deletions(-) diff --git a/apps/api/src/index.ts b/apps/api/src/index.ts index d53d02fa6..18d2e6fc4 100644 --- a/apps/api/src/index.ts +++ b/apps/api/src/index.ts @@ -306,7 +306,7 @@ async function initServer() { } catch (error) {} try { console.log('[003] Cleaning up old build sources under /tmp/build-sources/...'); - await fs.rm('/tmp/build-sources', { recursive: true, force: true }); + if (!isDev) await fs.rm('/tmp/build-sources', { recursive: true, force: true }); } catch (error) { console.log(error); } diff --git a/apps/api/src/jobs/deployApplication.ts b/apps/api/src/jobs/deployApplication.ts index 5c35307b9..28b6e1b1f 100644 --- a/apps/api/src/jobs/deployApplication.ts +++ b/apps/api/src/jobs/deployApplication.ts @@ -240,7 +240,7 @@ import * as buildpacks from '../lib/buildPacks'; applicationId: application.id }); } - await fs.rm(workdir, { recursive: true, force: true }); + if (!isDev) await fs.rm(workdir, { recursive: true, force: true }); return; } try { @@ -263,7 +263,7 @@ import * as buildpacks from '../lib/buildPacks'; await saveBuildLog({ line: error.stderr, buildId, applicationId }); } } finally { - await fs.rm(workdir, { recursive: true, force: true }); + if (!isDev) await fs.rm(workdir, { recursive: true, force: true }); await prisma.build.update({ where: { id: buildId }, data: { status: 'success' } @@ -782,7 +782,7 @@ import * as buildpacks from '../lib/buildPacks'; applicationId: application.id }); } - await fs.rm(workdir, { recursive: true, force: true }); + if (!isDev) await fs.rm(workdir, { recursive: true, force: true }); return; } try { @@ -803,7 +803,7 @@ import * as buildpacks from '../lib/buildPacks'; await saveBuildLog({ line: error.stderr, buildId, applicationId }); } } finally { - await fs.rm(workdir, { recursive: true, force: true }); + if (!isDev) await fs.rm(workdir, { recursive: true, force: true }); await prisma.build.update({ where: { id: buildId }, data: { status: 'success' } }); } }); diff --git a/apps/api/src/lib/buildPacks/compose.ts b/apps/api/src/lib/buildPacks/compose.ts index 839f3e3ae..136ea9814 100644 --- a/apps/api/src/lib/buildPacks/compose.ts +++ b/apps/api/src/lib/buildPacks/compose.ts @@ -47,7 +47,12 @@ export default async function (data) { for (let [key, value] of Object.entries(dockerComposeYaml.services)) { value['container_name'] = `${applicationId}-${key}`; + if (value['env_file']) { + delete value['env_file']; + } + let environment = typeof value['environment'] === 'undefined' ? [] : value['environment']; + console.log({ key, environment }); if (Object.keys(environment).length > 0) { environment = Object.entries(environment).map(([key, value]) => `${key}=${value}`); } @@ -60,7 +65,7 @@ export default async function (data) { const buildArgs = typeof build['args'] === 'undefined' ? [] : build['args']; let finalArgs = [...buildEnvs]; if (Object.keys(buildArgs).length > 0) { - for (const arg of buildArgs) { + for (const arg of Object.keys(buildArgs)) { const [key, _] = arg.split('='); if (finalArgs.filter((env) => env.startsWith(key)).length === 0) { finalArgs.push(arg); @@ -87,7 +92,10 @@ export default async function (data) { v.startsWith('~') || v.startsWith('$PWD') ) { - v = v.replace(/^\./, `~`).replace(/^\.\./, '~').replace(/^\$PWD/, '~'); + v = v + .replace(/^\./, `~`) + .replace(/^\.\./, '~') + .replace(/^\$PWD/, '~'); } else { if (!path) { path = v; @@ -110,10 +118,11 @@ export default async function (data) { source.startsWith('~') || source.startsWith('$PWD') ) { - - source = source.replace(/^\./, `~`).replace(/^\.\./, '~').replace(/^\$PWD/, '~'); - console.log({source}) - + source = source + .replace(/^\./, `~`) + .replace(/^\.\./, '~') + .replace(/^\$PWD/, '~'); + console.log({ source }); } else { if (!target) { target = source; @@ -125,7 +134,6 @@ export default async function (data) { return `${source}:${target}${mode ? ':' + mode : ''}`; } - }); } if (volumes.length > 0) { @@ -136,16 +144,20 @@ export default async function (data) { if (dockerComposeConfiguration[key]?.port) { value['expose'] = [dockerComposeConfiguration[key].port]; } - if (value['networks']?.length > 0) { - value['networks'].forEach((network) => { - networks[network] = { - name: network - }; - }); - value['networks'] = [...(value['networks'] || ''), network]; - } else { - value['networks'] = [network]; + value['networks'] = [network]; + if (value['build']?.network) { + delete value['build']['network']; } + // if (value['networks']?.length > 0) { + // value['networks'].forEach((network) => { + // networks[network] = { + // name: network + // }; + // }); + // value['networks'] = [...(value['networks'] || ''), network]; + // } else { + // value['networks'] = [network]; + // } dockerComposeYaml.services[key] = { ...dockerComposeYaml.services[key], diff --git a/apps/api/src/lib/common.ts b/apps/api/src/lib/common.ts index facbbb636..a9ea1bb7a 100644 --- a/apps/api/src/lib/common.ts +++ b/apps/api/src/lib/common.ts @@ -19,7 +19,7 @@ import { saveBuildLog } from './buildPacks/common'; import { scheduler } from './scheduler'; import type { ExecaChildProcess } from 'execa'; -export const version = '3.12.29'; +export const version = '3.12.30'; export const isDev = process.env.NODE_ENV === 'development'; export const proxyPort = process.env.COOLIFY_PROXY_PORT; export const proxySecurePort = process.env.COOLIFY_PROXY_SECURE_PORT; diff --git a/package.json b/package.json index a5173e216..0ff73ec34 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "coolify", "description": "An open-source & self-hostable Heroku / Netlify alternative.", - "version": "3.12.29", + "version": "3.12.30", "license": "Apache-2.0", "repository": "github:coollabsio/coolify", "scripts": {