[READ-ONLY] Mirror of https://github.com/FoxxMD/komodo-import. Import existing compose stacks into Komodo foxxmd.github.io/komodo-import
compose docker import komodo toml
0

Configure Feed

Select the types of activity you want to include in your feed.

Add ability to write to komodo environment

FoxxMD (Aug 13, 2025, 4:45 PM UTC) eb024dad 8fc9701a

+49 -19
+20 -9
src/builders/stack/filesOnServer.ts
··· 3 3 import { _PartialStackConfig } from 'komodo_client/dist/types.js'; 4 4 import { parse, ParsedPath, sep, join } from 'path'; 5 5 import { TomlStack } from "../../common/infrastructure/tomlObjects.js"; 6 - import { findFilesRecurive, sortComposePaths } from "../../common/utils/io.js"; 6 + import { findFilesRecurive, readText, sortComposePaths } from "../../common/utils/io.js"; 7 7 import { stripIndents } from "common-tags"; 8 8 import { isDebugMode, removeUndefinedKeys } from "../../common/utils/utils.js"; 9 9 import { DEFAULT_COMPOSE_GLOB, DEFAULT_ENV_GLOB, selectComposeFiles, selectEnvFiles } from "./stackUtils.js"; ··· 21 21 autoUpdate = false, 22 22 pollForUpdate = false, 23 23 server, 24 - hostParentPath 24 + hostParentPath, 25 + writeEnv = false, 25 26 } = options; 26 27 27 28 const pathInfo: ParsedPath = parse(path); ··· 51 52 stack.config.file_paths = await selectComposeFiles(composeFileGlob, path, logger); 52 53 53 54 const envFiles = await selectEnvFiles(envFileGlob, path, logger); 54 - if(envFiles !== undefined) { 55 - stack.config.env_file_path = komodoEnvName 56 - logger.info(`Using ${komodoEnvName} for Komodo-written env file`); 57 - stack.config.additional_env_files = envFiles; 55 + if (envFiles !== undefined) { 56 + if (writeEnv) { 57 + logger.verbose('Writing env file(s) contents to Komodo Environmnent'); 58 + const envContents: string[] = []; 59 + for (const f of envFiles) { 60 + envContents.push(await readText(envFiles)) 61 + } 62 + stack.config.environment = envContents.join('\n'); 63 + } 64 + else { 65 + stack.config.env_file_path = komodoEnvName 66 + logger.info(`Using ${komodoEnvName} for Komodo-written env file`); 67 + stack.config.additional_env_files = envFiles; 68 + } 58 69 } 59 70 60 71 logger.info('Stack config complete'); ··· 62 73 return removeUndefinedKeys(stack); 63 74 } catch (e) { 64 75 logJson = true; 65 - throw new Error(`Error occurred while processing Stack for folder ${folderName}`, {cause: e}); 76 + throw new Error(`Error occurred while processing Stack for folder ${folderName}`, { cause: e }); 66 77 } finally { 67 - if(logJson) { 78 + if (logJson) { 68 79 logger.debug(`Stack Config: ${JSON.stringify(stack)}}`); 69 80 } 70 81 } ··· 85 96 const stacks: TomlStack[] = []; 86 97 for (const dir of dirs) { 87 98 try { 88 - stacks.push(await buildFileStack(dir, {...options, logger})); 99 + stacks.push(await buildFileStack(dir, { ...options, logger })); 89 100 } catch (e) { 90 101 logger.error(new Error(`Unable to build Stack for folder ${dir}`, { cause: e })); 91 102 }
+19 -8
src/builders/stack/gitStack.ts
··· 3 3 import { _PartialStackConfig } from 'komodo_client/dist/types.js'; 4 4 import { parse, ParsedPath, sep, join } from 'path'; 5 5 import { TomlStack } from "../../common/infrastructure/tomlObjects.js"; 6 - import { dirHasGitConfig, findFilesRecurive, readDirectories, sortComposePaths } from "../../common/utils/io.js"; 6 + import { dirHasGitConfig, findFilesRecurive, readDirectories, readText, sortComposePaths } from "../../common/utils/io.js"; 7 7 import { stripIndents } from "common-tags"; 8 8 import { isDebugMode, removeUndefinedKeys } from "../../common/utils/utils.js"; 9 9 import { DEFAULT_COMPOSE_GLOB, DEFAULT_ENV_GLOB, selectComposeFiles, selectEnvFiles } from "./stackUtils.js"; 10 10 import { detectGitRepo, GitRepoData, komodoRepoFromRemote, matchGitDataWithKomodo, matchRemote, RemoteInfo } from "../../common/utils/git.js"; 11 11 import { SimpleError } from "../../common/errors.js"; 12 + import { readFile } from "fs/promises"; 12 13 13 14 export type BuildGitStackOptions = GitStackConfig & { logger: Logger }; 14 15 ··· 24 25 pollForUpdate = false, 25 26 server, 26 27 inMonorepo = false, 27 - hostParentPath 28 + hostParentPath, 29 + writeEnv = false, 28 30 } = options 29 31 30 32 let gitStackConfig: _PartialStackConfig; ··· 43 45 try { 44 46 gitData = await detectGitRepo(path); 45 47 } catch (e) { 46 - if(e instanceof SimpleError) { 48 + if (e instanceof SimpleError) { 47 49 throw new SimpleError(`Unable to parse path as git repo: ${e.message}`); 48 50 } else { 49 51 throw e; ··· 55 57 if (repo === undefined) { 56 58 logger.verbose(`No linked repo because ${repoHint}`); 57 59 const [domain, repo] = komodoRepoFromRemote(gitData[1].url); 58 - if(repo === undefined) { 60 + if (repo === undefined) { 59 61 throw new Error(`Could not parse repo from Remote URL ${gitData[1].url}`); 60 62 } 61 63 logger.debug(`Parsed Repo '${repo}' with ${provider?.domain !== undefined ? `provider` : 'URL'} domain '${provider?.domain ?? domain}' from Remote URL ${gitData[1].url}`); 62 - if(provider?.username !== undefined) { 64 + if (provider?.username !== undefined) { 63 65 logger.debug(`Using provider username ${provider.username}`); 64 66 } 65 67 gitStackConfig = { ··· 108 110 109 111 const envFiles = await selectEnvFiles(envFileGlob, path, logger); 110 112 if (envFiles !== undefined) { 111 - stack.config.env_file_path = komodoEnvName 112 - logger.info(`Using ${komodoEnvName} for Komodo-written env file`); 113 - stack.config.additional_env_files = envFiles.map(x => inMonorepo ? join(monoRepoPath, x) : x); 113 + if (writeEnv) { 114 + logger.verbose('Writing env file(s) contents to Komodo Environmnent'); 115 + const envContents: string[] = []; 116 + for (const f of envFiles) { 117 + envContents.push(await readText(envFiles)) 118 + } 119 + stack.config.environment = envContents.join('\n'); 120 + } else { 121 + stack.config.env_file_path = komodoEnvName 122 + logger.info(`Using ${komodoEnvName} for Komodo-written env file`); 123 + stack.config.additional_env_files = envFiles.map(x => inMonorepo ? join(monoRepoPath, x) : x); 124 + } 114 125 } 115 126 116 127 logger.info('Git Stack config complete');
+7 -1
src/builders/stack/stackBuilder.ts
··· 97 97 stackOptions = { 98 98 ...stackOptions, 99 99 ...gitStackConfig, 100 + writeEnv: parseBool(process.env.GIT_WRITE_ENV, false), 100 101 inMonorepo: true 101 102 } 102 103 } else { ··· 122 123 } else { 123 124 124 125 try { 125 - stacks.push(await buildGitStack(f, { inMonorepo: false, ...options, logger })); 126 + stacks.push(await buildGitStack(f, { 127 + inMonorepo: false, 128 + writeEnv: parseBool(process.env.GIT_WRITE_ENV, false), 129 + ...options, 130 + logger 131 + })); 126 132 continue; 127 133 } catch (e) { 128 134 if (e instanceof SimpleError) {
+3 -1
src/common/infrastructure/config/stackConfig.ts
··· 2 2 3 3 export interface FilesOnServerConfig extends CommonImportOptions { 4 4 hostParentPath: string 5 + writeEnv?: boolean 5 6 } 6 7 7 8 export interface GitStackCommonConfig extends CommonImportOptions { 8 9 inMonorepo?: boolean | string 9 - hostParentPath?: string 10 + hostParentPath?: string, 11 + writeEnv?: boolean 10 12 } 11 13 12 14 export interface GitStackStandaloneConfig extends GitStackCommonConfig {