summaryrefslogtreecommitdiff
path: root/worker/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'worker/scripts')
-rwxr-xr-xworker/scripts/checkout_ci.ts51
1 files changed, 27 insertions, 24 deletions
diff --git a/worker/scripts/checkout_ci.ts b/worker/scripts/checkout_ci.ts
index f1627c9..1892be8 100755
--- a/worker/scripts/checkout_ci.ts
+++ b/worker/scripts/checkout_ci.ts
@@ -86,28 +86,31 @@ await LogMetricTraceable.ofLogTraceable(_logJob)
return repoCiFileContents
.flatMap((fileText) => Either.fromFailable<Error, unknown>(() => JSON.parse(fileText)))
.flatMap((json) => {
- return eitherCiJob.flatMap((ciJob): IEither<Error, { cmd: Command; job: CheckoutCiJob }> => {
- if (!isCiWorkflow(json)) {
- const e = new Error("couldn't find any valid ci configuration (。•́︿•̀。), that's okay~");
- return Either.left(e);
- }
- return Either.right({
- cmd: getPipelineGenerationCommand(ciJob, json.workflow),
- job: ciJob,
- });
- });
+ return eitherCiJob.flatMap(
+ (ciJob): IEither<Error, { commands: Array<Command>; job: CheckoutCiJob }> => {
+ if (!isCiWorkflow(json)) {
+ const e = new Error("couldn't find any valid ci configuration (。•́︿•̀。), that's okay~");
+ return Either.left(e);
+ }
+ return Either.right({
+ commands: getPipelineGenerationCommand(ciJob, json.workflow),
+ job: ciJob,
+ });
+ },
+ );
});
})
.map(async (tEitherPipelineGenerationCommand) => {
- tEitherPipelineGenerationCommand.move(getDockerLoginReadonlyCommand());
- })
- .map(async (tEitherPipelineGenerationCommand) => {
const eitherJobCommand = await tEitherPipelineGenerationCommand.get();
- const eitherPipeline = await eitherJobCommand.flatMapAsync((jobCommand) =>
- tEitherPipelineGenerationCommand.move(jobCommand.cmd).map(getStdout).get(),
- );
- return eitherPipeline
- .flatMap(PipelineImpl.from)
+ const pipelineSerialized = await eitherJobCommand.flatMapAsync(({ commands }) => {
+ return Either.joinRightAsync(
+ commands,
+ (command) => tEitherPipelineGenerationCommand.move(command).map(getStdout).get(),
+ Either.right<Error, string>(''),
+ );
+ });
+ return pipelineSerialized
+ .flatMap((s) => PipelineImpl.from(s))
.flatMap((pipeline) => eitherJobCommand.mapRight(({ job }) => ({ job, pipeline })));
})
.peek(
@@ -149,17 +152,17 @@ function getSrcDirectoryForCiJob(job: CheckoutCiJob) {
return `${job.arguments.returnPath}/${job.arguments.run}/src`;
}
-function getDockerLoginReadonlyCommand(credentials = READONLY_CREDENTIALS, registry = OCI_REGISTRY): Command {
- return `docker login --username ${credentials.username} --password ${credentials.password} ${registry}`.split(' ');
-}
-
function getPipelineGenerationCommand(
job: CheckoutCiJob,
pipelineGeneratorPath: string,
+ credentials = READONLY_CREDENTIALS,
+ registry = OCI_REGISTRY,
image = PIPELINE_IMAGE,
runFlags = '--rm --network none --cap-drop ALL --security-opt no-new-privileges'.split(' '),
-): Command {
+): Array<Command> {
return [
+ `docker login --username ${credentials.username} --password ${credentials.password} ${registry}`.split(' '),
+ ].concat([
'docker',
'run',
...runFlags,
@@ -171,5 +174,5 @@ function getPipelineGenerationCommand(
`${getSrcDirectoryForCiJob(job)}/${pipelineGeneratorPath}:/pipeline_generator`,
image,
'/pipeline_generator',
- ];
+ ]);
}