Something went wrong. Try again.
[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
Something went wrong. Try again.
2.8 kB · 81 lines
TypeScript
at feedback
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081import { Logger, childLogger } from "@foxxmd/logging";import { FilesOnServerConfig } from "../../common/infrastructure/config/stackConfig.js";import { _PartialStackConfig } from 'komodo_client/dist/types.js';import { parse, ParsedPath, sep, join } from 'path';import { TomlStack } from "../../common/infrastructure/tomlObjects.js";import { readText } from "../../common/utils/io.js";import { isDebugMode, removeRootPathSeparator, removeUndefinedKeys } from "../../common/utils/utils.js";import { DEFAULT_COMPOSE_GLOB, DEFAULT_ENV_GLOB, parseEnvConfig, selectComposeFiles, selectEnvFiles } from "./stackUtils.js";
export type BuildFileStackOptions = FilesOnServerConfig & { logger: Logger };
export const buildFileStack = async (path: string, options: BuildFileStackOptions): Promise<TomlStack> => {
const { composeFileGlob = DEFAULT_COMPOSE_GLOB, envFileGlob = DEFAULT_ENV_GLOB, komodoEnvName = '.komodoEnv', imageRegistryAccount, imageRegistryProvider, autoUpdate, pollForUpdate, server, hostParentPath, composeFiles = [], projectName, writeEnv = false, } = options;
const pathInfo: ParsedPath = parse(path);
const folderName = `${pathInfo.name}${pathInfo.ext !== '' ? pathInfo.ext : ''}`;
const logger = childLogger(options.logger, [folderName, 'Files On Server']); logger.info(`Found Stack '${folderName}' at dir ${path}`);
let stack: TomlStack; let logJson = isDebugMode();
try { stack = { name: projectName ?? folderName, config: { server, run_directory: join(hostParentPath, folderName), files_on_host: true, registry_account: imageRegistryAccount, registry_provider: imageRegistryProvider, auto_update: autoUpdate, poll_for_updates: pollForUpdate } };
if(composeFiles.length > 0) { stack.config.file_paths = composeFiles.map(x => removeRootPathSeparator(x.replace(path, ''))); } else { stack.config.file_paths = await selectComposeFiles(composeFileGlob, path, logger); }
stack.config = { ...stack.config, ...await(parseEnvConfig(path, { envFileGlob, writeEnv, komodoEnvName, logger })) }
logger.info('Stack config complete');
return removeUndefinedKeys(stack); } catch (e) { logJson = true; throw new Error(`Error occurred while processing Stack for folder ${folderName}`, { cause: e }); } finally { if (logJson) { logger.debug(`Stack Config: ${JSON.stringify(stack)}`); } }}