summaryrefslogtreecommitdiff
path: root/worker/fs.ts
diff options
context:
space:
mode:
authorElizabeth Hunt <me@liz.coffee>2025-07-20 17:21:38 -0700
committerElizabeth Hunt <me@liz.coffee>2025-07-20 18:31:57 -0700
commitbfdef4064b4a172a2027f3813ab88f38728d61c0 (patch)
tree94babba33cd28aaacad39b49936b803486784a73 /worker/fs.ts
parent9e220eca4545982df83ffcaa66a9b050a3d6f24e (diff)
downloadci-bfdef4064b4a172a2027f3813ab88f38728d61c0.tar.gz
ci-bfdef4064b4a172a2027f3813ab88f38728d61c0.zip
Fixes
Diffstat (limited to 'worker/fs.ts')
-rw-r--r--worker/fs.ts29
1 files changed, 29 insertions, 0 deletions
diff --git a/worker/fs.ts b/worker/fs.ts
new file mode 100644
index 0000000..2c02b34
--- /dev/null
+++ b/worker/fs.ts
@@ -0,0 +1,29 @@
+import { Either, getStdout, IEither, LogMetricTraceable } from '@emprespresso/pengueno';
+import { readFileSync } from 'node:fs';
+
+// the container which runs the pipeline synthesizer (A) might be spawned by another container
+// (B) ((which should be the one running this job)) by talking to the host's docker daemon
+// (mounting /var/run/docker.sock) and executing the {@link getPipelineGenerationCommand}.
+//
+// so mounting {@link getSrcDirectoryForCiJob} has no meaning as it doesn't exist on the host;
+// here we replace the path in (B) with the actual volume source on the host, where the src
+// exists.
+export async function getPathOnHost(path: string, home = '/var/lib/laminar'): Promise<IEither<Error, string>> {
+ const container = await Either.fromFailable<Error, string>(() =>
+ readFileSync('/etc/hostname', 'utf-8'),
+ ).flatMapAsync((hostname) =>
+ LogMetricTraceable.of(`docker inspect ${hostname}`.split(' '))
+ .map((tCmd) => getStdout(tCmd))
+ .get(),
+ );
+ if (container.left().present()) {
+ return Either.right(path);
+ }
+ return container
+ .flatMap((inspect) => Either.fromFailable(() => JSON.parse(inspect)))
+ .mapRight(
+ ([container]) =>
+ container.Mounts.find(({ Destination }: { Destination: string }) => Destination === home).Source,
+ )
+ .mapRight((source) => path.replace(home, source));
+}