Skip to content

Commit 5ce5e8d

Browse files
committed
fix: Add env to enable glob dot
1 parent e4e9894 commit 5ce5e8d

File tree

8 files changed

+49
-23
lines changed

8 files changed

+49
-23
lines changed

docsite/docs/usage/overview.mdx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,11 +201,12 @@ The configuration and behaviors below are applicable to all Stacks:
201201
| ENV | Required | Default | Description |
202202
| :------------------------ | :------- | -------------------------------------- | :----------------------------------------------------------------------------------------------------------------------------------------------------------- |
203203
| `SERVER_NAME` | ☑️ | | The name of the Komodo [Server](https://komo.do/docs/resources#server) where a Stack is located |
204-
| `STACKS_FROM` | ☑️ | `dir` | What [**Stack Sources**](#stack-sources) to generate Stacks from? `dir` or `compose` |
204+
| `STACKS_FROM` | ☑️ | `dir` | What [**Stack Sources**](#stack-sources) to generate Stacks from? `dir` or `compose` |
205205
| `HOST_DIR` | ☑️ | | The parent directory on the **host** that mounted into the Komodo Import container |
206206
| `WRITE_ENV` | - | `true` | Write the contents of found .env files to Komodo **Environment**. Likely want this as `true`. |
207207
| `COMPOSE_FILE_GLOB` | - | `**/{compose,docker-compose}*.y?(a)ml` | The [glob](https://github.com/isaacs/node-glob?tab=readme-ov-file#glob-primer) pattern to use for finding files for **Files Paths** in Stack config |
208208
| `ENV_FILE_GLOB` | - | `**/.env` | The [glob](https://github.com/isaacs/node-glob?tab=readme-ov-file#glob-primer) pattern to use for finding files for **Additional Env Files** in Stack config |
209+
| `GLOB_DOT` | - | `false` | Allow glob patterns, outside of ENV pattern, to find files/folders that start with `.` |
209210
| `KOMODO_ENV_NAME` | - | `.komodoenv` | If existing .env files are found, and `WRITE_ENV=false`, then this name will be used for the .env that Komodo writes using its own Environment section |
210211
| `IMAGE_REGISTRY_PROVIDER` | - | | Name of Image Registry to use |
211212
| `IMAGE_REGISTRY_ACCOUNT` | - | | Image Registry account to use |

docsite/src/components/QuickstartCompose.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ import ApiOutput from './QuickStartSnippets/apiOutput.mdx';
2626
const doc = parseDocument(ComposeExample);
2727
const proxyCollection = parseDocument(SocketProxyExample);
2828

29+
const DOT_FOLDER_REGEX = new RegExp(/(?:^|[\/\\])\.\S/);
30+
2931
interface ComposeStateData {
3032
autoUpdate?: boolean
3133
pollUpdate?: boolean
@@ -132,6 +134,12 @@ const QuickstartCompose = (props: AIOProps) => {
132134
hostS.commentBefore = `# Same as mounted directory above`
133135
seq.add(hostS);
134136

137+
if(DOT_FOLDER_REGEX.test(hostPath)) {
138+
const dotS = new Scalar(`GLOB_DOT=true`);
139+
dotS.commentBefore = `# Forces glob to not ignore dot folders`
140+
seq.add(dotS);
141+
}
142+
135143
const stacksFromS = new Scalar(`STACKS_FROM=${composeState.stacksFrom}`);
136144
stacksFromS.commentBefore = '# Determines what sources to generate Stacks from'
137145
stacksFromS.comment = `# ${composeState.stacksFrom === 'dir' ? 'Generate stacks from subfolders in directory' : 'Generate stacks from compose projects'}`

src/builders/stack/gitStack.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export const buildGitStack = async (path: string, options: BuildGitStackOptions)
2525
projectName,
2626
composeFiles = [],
2727
writeEnv = false,
28+
allowGlobDot,
2829
} = options
2930

3031
let gitStackConfig: _PartialStackConfig = {}
@@ -52,7 +53,7 @@ export const buildGitStack = async (path: string, options: BuildGitStackOptions)
5253
}
5354

5455
if(gitData === undefined) {
55-
const parentGitPath = await findPathRecuriveParently(path, '.git');
56+
const parentGitPath = await findPathRecuriveParently(path, '.git', {dot: allowGlobDot});
5657
if (parentGitPath !== undefined) {
5758
const parentGitDir = dirname(parentGitPath)
5859
try {

src/builders/stack/stackBuilder.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ export class StackBuilder {
4848
ignoreFolderGlob,
4949
envFileGlob = DEFAULT_ENV_GLOB,
5050
composeGlob = DEFAULT_GLOB_COMPOSE,
51-
ignoreComposeGlob
51+
ignoreComposeGlob,
52+
allowGlobDot = false
5253
} = this.stackConfigOptions;
5354

5455
let folderPaths: string[] = [];
@@ -66,9 +67,9 @@ export class StackBuilder {
6667

6768
await this.parseComposeProjects();
6869

69-
const includeGlob = new Minimatch(composeGlob);
70-
const excludeGlob = ignoreComposeGlob === undefined ? undefined : new Minimatch(ignoreComposeGlob);
71-
const komodoGlob = new Minimatch(KOMODO_GLOB_IGNORE_COMPOSE);
70+
const includeGlob = new Minimatch(composeGlob, {dot: allowGlobDot});
71+
const excludeGlob = ignoreComposeGlob === undefined ? undefined : new Minimatch(ignoreComposeGlob, {dot: allowGlobDot});
72+
const komodoGlob = new Minimatch(KOMODO_GLOB_IGNORE_COMPOSE, {dot: allowGlobDot});
7273

7374
for (const c of this.composeCandidateStacks) {
7475
if (!c.workingDir.includes(this.dirData.host)) {
@@ -100,7 +101,7 @@ export class StackBuilder {
100101
this.logger.info(`Folder Ignore Glob: ${ignoreFolderGlob ?? 'N/A'}`);
101102

102103
await this.parseComposeProjects();
103-
const dirs = await findFolders(this.dirData.scan, folderGlob, ignoreFolderGlob)
104+
const dirs = await findFolders(this.dirData.scan, folderGlob, {ignore: ignoreFolderGlob, dot: allowGlobDot})
104105
folderPaths = dirs.map(x => joinPath(this.dirData.scan, x));
105106
this.logger.verbose(`Got ${folderPaths.length} folders in ${this.dirData.scan}:\n${formatIntoColumns(dirs, 3)}`);
106107
}

src/common/infrastructure/config/common.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ export interface CommonImportOptions {
1111
ignoreFolderGlob?: string
1212
composeGlob?: string
1313
ignoreComposeGlob?: string
14+
allowGlobDot?: boolean
1415
}

src/common/utils/io.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { accessSync, constants, promises } from "fs";
22
import pathUtil, { join, dirname } from "path";
3-
import { glob, GlobOptionsWithFileTypesUnset } from 'glob';
3+
import { glob, GlobOptionsWithFileTypesUnset, GlobOptionsWithFileTypesTrue } from 'glob';
44
import clone from 'clone';
55
import { DEFAULT_GLOB_FOLDER, DirectoryConfig, DirectoryConfigValues } from "../infrastructure/atomic.js";
66
import { parseBool } from "./utils.js";
7+
import { testMaybeRegex } from "@foxxmd/regex-buddy-core";
78

89
export async function writeFile(path: any, text: any) {
910
try {
@@ -80,7 +81,7 @@ export const findFilesRecurive = async (filePattern: string, fromDir: string, op
8081
}
8182
}
8283

83-
export const findPathRecuriveParently = async (fromDir: string, path: string) => {
84+
export const findPathRecuriveParently = async (fromDir: string, path: string, options: GlobOptionsWithFileTypesUnset = {}) => {
8485

8586
let currDirectory = fromDir;
8687
let parentDirectory = fromDir;
@@ -93,6 +94,7 @@ export const findPathRecuriveParently = async (fromDir: string, path: string) =>
9394

9495
const files = await glob(path, {
9596
cwd: parentDirectory,
97+
...options
9698
});
9799

98100
if(files.length > 0) {
@@ -157,13 +159,13 @@ export const readDirectories = async (path: string, options: ReadDirectoryOption
157159
}
158160
}
159161

160-
export const findFolders = async (fromDir: string, filePattern: string = DEFAULT_GLOB_FOLDER, ignore?: string): Promise<string[]> => {
162+
export const findFolders = async (fromDir: string, filePattern: string = DEFAULT_GLOB_FOLDER, options: Partial<GlobOptionsWithFileTypesTrue> = {}): Promise<string[]> => {
161163
try {
162164
const res = await glob(filePattern, {
163165
cwd: fromDir,
164166
nodir: false,
165167
withFileTypes: true,
166-
ignore
168+
...options,
167169
});
168170
return res.filter(x => x.isDirectory()).map(x => x.name);
169171
} catch (e) {
@@ -175,6 +177,9 @@ export const dirHasGitConfig = (paths: string[]): boolean => {
175177
return paths.some(x => x === '.git');
176178
}
177179

180+
const DOT_FOLDER_REGEX = new RegExp(/(?:^|[\/\\])\.\S/);
181+
export const pathHasDotFolder = (pathVal: string): boolean => DOT_FOLDER_REGEX.test(pathVal)
182+
178183
export const parseDirectoryConfig = async (dirConfig: DirectoryConfigValues = {}): Promise<[DirectoryConfigValues, DirectoryConfig]> => {
179184
const {
180185
mountVal = process.env.MOUNT_DIR,

src/index.ts

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { exportToFile } from './exporters/exportToFile.js';
1717
import { exportToSync } from './exporters/exportToApiSync.js';
1818
import { getDefaultKomodoApi } from './common/utils/komodo.js';
1919
import { StackBuilder } from './builders/stack/stackBuilder.js';
20-
import { parseDirectoryConfig } from './common/utils/io.js';
20+
import { parseDirectoryConfig, pathHasDotFolder } from './common/utils/io.js';
2121
import { DirectoryConfig, DirectoryConfigValues } from './common/infrastructure/atomic.js';
2222

2323
dayjs.extend(utc)
@@ -56,16 +56,6 @@ try {
5656

5757
getDefaultKomodoApi(logger);
5858

59-
let dirData: [DirectoryConfigValues, DirectoryConfig];
60-
try {
61-
dirData = await parseDirectoryConfig();
62-
logger.info(`Mount Dir : ${dirData[0].mountVal} -> Resolved: ${dirData[1].mount}`);
63-
logger.info(`Host Dir : ${dirData[0].hostVal} -> Resolved: ${dirData[1].host}`);
64-
logger.info(`Scan Dir : ${dirData[0].scanVal} -> Resolved: ${dirData[1].scan}`);
65-
} catch (e) {
66-
throw new Error('Could not parse required directories', {cause: e});
67-
}
68-
6959
const importOptions: CommonImportOptions = {
7060
server: process.env.SERVER_NAME,
7161
imageRegistryProvider: process.env.IMAGE_REGISTRY_PROVIDER,
@@ -74,11 +64,30 @@ try {
7464
pollForUpdate: isUndefinedOrEmptyString(process.env.POLL_FOR_UPDATE) ? undefined : parseBool(process.env.POLL_FOR_UPDATE),
7565
komodoEnvName: process.env.KOMODO_ENV_NAME,
7666
composeFileGlob: process.env.COMPOSE_FILE_GLOB,
67+
allowGlobDot: isUndefinedOrEmptyString(process.env.GLOB_DOT) ? undefined : parseBool(process.env.GLOB_DOT),
7768
envFileGlob: process.env.ENV_FILE_GLOB,
7869
folderGlob: isUndefinedOrEmptyString(process.env.FOLDER_GLOB) ? undefined : process.env.FOLDER_GLOB.trim(),
7970
ignoreFolderGlob: isUndefinedOrEmptyString(process.env.FOLDER_IGNORE_GLOB) ? undefined : process.env.FOLDER_IGNORE_GLOB.trim(),
8071
};
8172

73+
let dirData: [DirectoryConfigValues, DirectoryConfig];
74+
try {
75+
dirData = await parseDirectoryConfig(undefined);
76+
logger.info(`Mount Dir : ${dirData[0].mountVal} -> Resolved: ${dirData[1].mount}`);
77+
logger.info(`Host Dir : ${dirData[0].hostVal} -> Resolved: ${dirData[1].host}`);
78+
logger.info(`Scan Dir : ${dirData[0].scanVal} -> Resolved: ${dirData[1].scan}`);
79+
} catch (e) {
80+
throw new Error('Could not parse required directories', {cause: e});
81+
}
82+
83+
if(pathHasDotFolder(dirData[1].host) && importOptions.allowGlobDot !== true) {
84+
logger.warn(`It looks like your Host Dir has a dot folder in its path and the env GLOB_DOT is not true/set. Komodo Import may not be able to match your paths because of this. If results are not as expected try setting GLOB_DOT=true`);
85+
}
86+
if(pathHasDotFolder(dirData[1].scan) && dirData[1].host !== dirData[1].scan && importOptions.allowGlobDot !== true) {
87+
logger.warn(`It looks like your Scan Dir has a dot folder in its path and the env GLOB_DOT is not true/set. Komodo Import may not be able to match your paths because of this. If results are not as expected try setting GLOB_DOT=true`);
88+
}
89+
90+
8291
if (importOptions.server === undefined || importOptions.server.trim() === '') {
8392
logger.error('ENV SERVER_NAME must be set');
8493
process.exit(1);

tests/util.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ describe('#Utils', function () {
9999
await mkdir(path.join(process.cwd(), 'test_1'));
100100
await mkdir(path.join(process.cwd(), 'ignoreme', 'subfolder'), {recursive: true});
101101
await writeFile(path.join(process.cwd(), 'ignoreme', 'subfolder', 'test.txt'), '');
102-
const folders = await findFolders(process.cwd(), undefined, 'ignore*');
102+
const folders = await findFolders(process.cwd(), undefined, {ignore: 'ignore*'});
103103
expect(folders).to.deep.eq(['test_1']);
104104
}, { unsafeCleanup: true });
105105
});

0 commit comments

Comments
 (0)