summaryrefslogtreecommitdiff
path: root/worker/scripts/checkout_ci.ts
diff options
context:
space:
mode:
Diffstat (limited to 'worker/scripts/checkout_ci.ts')
-rwxr-xr-xworker/scripts/checkout_ci.ts48
1 files changed, 13 insertions, 35 deletions
diff --git a/worker/scripts/checkout_ci.ts b/worker/scripts/checkout_ci.ts
index 65cbc2e..c4006e6 100755
--- a/worker/scripts/checkout_ci.ts
+++ b/worker/scripts/checkout_ci.ts
@@ -14,9 +14,9 @@ import {
IEither,
} from '@emprespresso/pengueno';
import { mkdir, readFile, rm } from 'fs/promises';
-import { join } from 'path';
+import path, { join } from 'path';
import { type CheckoutCiJob, type FetchCodeJob, Pipeline, PipelineImpl } from '@emprespresso/ci_model';
-import { executeJob, executePipeline } from '@emprespresso/ci_worker';
+import { executeJob, executePipeline, getPathOnHost } from '@emprespresso/ci_worker';
interface CiWorkflow {
workflow: string;
@@ -42,7 +42,7 @@ const READONLY_CREDENTIALS = { username: 'readonly', password: 'readonly' };
// -> checkout_ci (1000.uuidB)
const run = `${Date.now()}.${crypto.randomUUID().replaceAll('-', '')}`;
-const eitherJob = getRequiredEnvVars(['remote', 'refname', 'rev', 'executorLaminarPath']).mapRight(
+const eitherJob = getRequiredEnvVars(['remote', 'refname', 'rev']).mapRight(
(baseArgs) =>
<CheckoutCiJob>{
type: 'checkout_ci.js',
@@ -76,19 +76,13 @@ await LogMetricTraceable.ofLogTraceable(logTraceableJob)
mkdir(wd, { recursive: true })
.then(() => process.chdir(wd))
.then(() => tEitherJob.move(fetchPackageJob).map(executeJob).get())
- .then((e) =>
- e.fold(
- (err) => {
- throw err;
- },
- () => ciJob,
- ),
- ),
+ .then(() => ciJob),
);
}),
)
.map(async (tEitherCiJob) => {
const eitherCiJob = await tEitherCiJob.get();
+ const jobSrcOnHost = await eitherCiJob.flatMapAsync((job) => getPathOnHost(getSrcDirectoryForCiJob(job)));
const repoCiFileContents = await eitherCiJob.flatMapAsync((ciJob) =>
Either.fromFailableAsync<Error, string>(() =>
readFile(join(getSrcDirectoryForCiJob(ciJob), CI_WORKFLOW_FILE), 'utf-8'),
@@ -98,9 +92,13 @@ await LogMetricTraceable.ofLogTraceable(logTraceableJob)
.flatMap((fileText) =>
Either.fromFailable<Error, CiWorkflow>(() => JSON.parse(fileText)).filter((json) => isCiWorkflow(json)),
)
- .joinRight(eitherCiJob, (job: CheckoutCiJob, { workflow }) => ({
+ .joinRight(eitherCiJob, (job, { workflow }) => ({
job,
- commands: getPipelineGenerationCommand(job, workflow),
+ workflow,
+ }))
+ .joinRight(jobSrcOnHost, (src, { job, workflow }) => ({
+ job,
+ commands: getPipelineGenerationCommand(job, workflow, src),
}));
})
.map(
@@ -150,16 +148,6 @@ await LogMetricTraceable.ofLogTraceable(logTraceableJob)
() => afterJob,
);
})
- .map(
- TraceUtil.promiseify((e) =>
- e.get().fold(
- (err) => {
- throw err;
- },
- (ok) => ok,
- ),
- ),
- )
.get();
function getWorkingDirectoryForCiJob(job: CheckoutCiJob) {
@@ -170,20 +158,10 @@ function getSrcDirectoryForCiJob(job: CheckoutCiJob) {
return `${getWorkingDirectoryForCiJob(job)}/src`;
}
-function getSrcDirectoryForChildContainer(job: CheckoutCiJob) {
- // 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.
- return getSrcDirectoryForCiJob(job).replace('/var/lib/laminar', job.arguments.executorLaminarPath);
-}
-
function getPipelineGenerationCommand(
job: CheckoutCiJob,
pipelineGeneratorPath: string,
+ srcMount: string,
credentials = READONLY_CREDENTIALS,
registry = OCI_REGISTRY,
image = PIPELINE_IMAGE,
@@ -201,7 +179,7 @@ function getPipelineGenerationCommand(
'-e',
),
'-v',
- `${getSrcDirectoryForChildContainer(job)}:/src`,
+ `${srcMount}:/src`,
image,
`/src/${pipelineGeneratorPath}`,
],