From bfdef4064b4a172a2027f3813ab88f38728d61c0 Mon Sep 17 00:00:00 2001 From: Elizabeth Hunt Date: Sun, 20 Jul 2025 17:21:38 -0700 Subject: Fixes --- worker/fs.ts | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 worker/fs.ts (limited to 'worker/fs.ts') 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> { + const container = await Either.fromFailable(() => + 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)); +} -- cgit v1.2.3-70-g09d2