MCPcopy
hub / github.com/louislam/dockge / getStackList

Method getStackList

backend/stack.ts:265–332  ·  view source on GitHub ↗
(server : DockgeServer, useCacheForManaged = false)

Source from the content-addressed store, hash-verified

263 }
264
265 static async getStackList(server : DockgeServer, useCacheForManaged = false) : Promise<Map<string, Stack>> {
266 let stacksDir = server.stacksDir;
267 let stackList : Map<string, Stack>;
268
269 // Use cached stack list?
270 if (useCacheForManaged && this.managedStackList.size > 0) {
271 stackList = this.managedStackList;
272 } else {
273 stackList = new Map<string, Stack>();
274
275 // Scan the stacks directory, and get the stack list
276 let filenameList = await fsAsync.readdir(stacksDir);
277
278 for (let filename of filenameList) {
279 try {
280 // Check if it is a directory
281 let stat = await fsAsync.stat(path.join(stacksDir, filename));
282 if (!stat.isDirectory()) {
283 continue;
284 }
285 // If no compose file exists, skip it
286 if (!await Stack.composeFileExists(stacksDir, filename)) {
287 continue;
288 }
289 let stack = await this.getStack(server, filename);
290 stack._status = CREATED_FILE;
291 stackList.set(filename, stack);
292 } catch (e) {
293 if (e instanceof Error) {
294 log.warn("getStackList", `Failed to get stack ${filename}, error: ${e.message}`);
295 }
296 }
297 }
298
299 // Cache by copying
300 this.managedStackList = new Map(stackList);
301 }
302
303 // Get status from docker compose ls
304 let res = await childProcessAsync.spawn("docker", [ "compose", "ls", "--all", "--format", "json" ], {
305 encoding: "utf-8",
306 });
307
308 if (!res.stdout) {
309 return stackList;
310 }
311
312 let composeList = JSON.parse(res.stdout.toString());
313
314 for (let composeStack of composeList) {
315 let stack = stackList.get(composeStack.Name);
316
317 // This stack probably is not managed by Dockge, but we still want to show it
318 if (!stack) {
319 // Skip the dockge stack if it is not managed by Dockge
320 if (composeStack.Name === "dockge") {
321 continue;
322 }

Callers 2

getStackMethod · 0.95
sendStackListMethod · 0.80

Calls 7

getStackMethod · 0.95
statusConvertMethod · 0.95
joinMethod · 0.80
composeFileExistsMethod · 0.80
setMethod · 0.80
warnMethod · 0.80
getMethod · 0.80

Tested by

no test coverage detected