| 86 | // declared volume names. Sufficient for our generated compose file; not a full |
| 87 | // YAML parser. |
| 88 | function parseTopLevelVolumes(composeYaml: string): string[] { |
| 89 | const names: string[] = []; |
| 90 | let inBlock = false; |
| 91 | for (const rawLine of composeYaml.split('\n')) { |
| 92 | const line = rawLine.replace(/\r$/, ''); |
| 93 | if (/^volumes:\s*(#.*)?$/.test(line)) { |
| 94 | inBlock = true; |
| 95 | continue; |
| 96 | } |
| 97 | if (!inBlock) { |
| 98 | continue; |
| 99 | } |
| 100 | if (/^\s*$/.test(line) || /^\s+/.test(line)) { |
| 101 | const m = line.match(/^ {2}([A-Za-z0-9_.-]+):\s*(#.*)?$/); |
| 102 | if (m) { |
| 103 | names.push(m[1]); |
| 104 | } |
| 105 | continue; |
| 106 | } |
| 107 | // Any non-blank, non-indented line ends the top-level volumes block. |
| 108 | inBlock = false; |
| 109 | } |
| 110 | return names; |
| 111 | } |
| 112 | |
| 113 | // A published port from a compose `ports:` entry, with the host interface Docker |
| 114 | // would bind to. Container-only, range, and env-interpolated specs are skipped. |