conductor

CI task system
git clone git://git.finwo.net/app/conductor
Log | Files | Refs | README | LICENSE

source.js (1388B)


      1 // src/worker/source.js - getting the tree into the task container
      2 //
      3 // The conductor serves a tarball of the exact commit a task was created
      4 // for. The worker never sees a repository, holds no credentials for one,
      5 // and cannot reach any ref other than the one it was given work for.
      6 //
      7 // The tarball goes straight from the conductor into the container: it is
      8 // decompressed in flight and handed to docker cp, so it is never written
      9 // to the worker's disk and never sits in a directory shared with the
     10 // container. That is what lets a worker run with no mounts at all.
     11 //
     12 // docker creates the destination as it extracts, including any missing
     13 // parents, so the tree can be delivered to a path the image has never
     14 // heard of without preparing anything first.
     15 
     16 import { Readable } from 'node:stream';
     17 import { createGunzip } from 'node:zlib';
     18 
     19 export async function sourceIntoContainer({ client, runtime, task, container, workdir }) {
     20   const url = task.endpoints?.source;
     21   if (!url) throw new Error('the task carries no source endpoint');
     22 
     23   const body = await client.source(url);
     24   const stream = body instanceof Readable ? body : Readable.fromWeb(body);
     25 
     26   // Decompressed on this side, because docker cp takes a plain tar and
     27   // the container has no shell of its own to unpack anything with.
     28   await runtime.copyStreamIn(container, stream.pipe(createGunzip()), workdir);
     29 }