diff options
Diffstat (limited to 'worker/scripts/build_docker_image.ts')
-rwxr-xr-x | worker/scripts/build_docker_image.ts | 49 |
1 files changed, 20 insertions, 29 deletions
diff --git a/worker/scripts/build_docker_image.ts b/worker/scripts/build_docker_image.ts index 228dfcc..b35031a 100755 --- a/worker/scripts/build_docker_image.ts +++ b/worker/scripts/build_docker_image.ts @@ -3,7 +3,6 @@ import { getRequiredEnvVars, getStdout, - LogLevel, LogTraceable, LogMetricTraceable, Metric, @@ -29,17 +28,18 @@ const eitherJob = getRequiredEnvVars([ ); const eitherVault = Bitwarden.getConfigFromEnvironment().mapRight((config) => new Bitwarden(config)); -const buildImageMetric = Metric.fromName('dockerImage.build'); -const loginMetric = Metric.fromName('dockerRegistry.login'); -const _logJob = LogTraceable.of(eitherJob).bimap((tEitherJob) => { - const trace = - 'build_docker_image.' + - tEitherJob.get().fold(({ isRight, value }) => (isRight ? value.arguments.buildTarget : '')); - return [tEitherJob.get(), trace]; +const buildImageMetric = Metric.fromName('dockerImage.build').asResult(); +const loginMetric = Metric.fromName('dockerRegistry.login').asResult(); +const _logJob = LogTraceable.of(eitherJob).flatMap((tEitherJob) => { + const trace = tEitherJob.get().fold( + () => 'NO_BUILD_TARGET', + ({ arguments: { buildTarget } }) => buildTarget, + ); + return tEitherJob.traceScope(() => `build_docker_image.${trace}`); }); await LogMetricTraceable.ofLogTraceable(_logJob) - .bimap(TraceUtil.withMetricTrace(buildImageMetric)) - .bimap(TraceUtil.withMetricTrace(loginMetric)) + .flatMap(TraceUtil.withMetricTrace(buildImageMetric)) + .flatMap(TraceUtil.withMetricTrace(loginMetric)) .peek((tEitherJob) => tEitherJob.trace.trace('starting docker image build job! (⑅˘꒳˘)')) .map((tEitherJob) => tEitherJob.get().flatMapAsync((job) => @@ -68,12 +68,7 @@ await LogMetricTraceable.ofLogTraceable(_logJob) }), ); }) - .peek(async (tEitherWithAuthdRegistry) => { - const eitherWithAuthdRegistry = await tEitherWithAuthdRegistry.get(); - return tEitherWithAuthdRegistry.trace.trace( - eitherWithAuthdRegistry.fold(({ isLeft }) => loginMetric[isLeft ? 'failure' : 'success']), - ); - }) + .peek(TraceUtil.promiseify(TraceUtil.traceResultingEither(loginMetric))) .map(async (tEitherWithAuthdRegistryBuildJob) => { const eitherWithAuthdRegistryBuildJob = await tEitherWithAuthdRegistryBuildJob.get(); tEitherWithAuthdRegistryBuildJob.trace.trace('finally building the image~ (◕ᴗ◕✿)'); @@ -92,19 +87,15 @@ await LogMetricTraceable.ofLogTraceable(_logJob) eitherWithAuthdRegistryBuildJob.mapRight((job) => ({ buildOutput, job })), ); }) - .peek(async (tEitherWithBuiltImage) => { - const eitherWithBuiltImage = await tEitherWithBuiltImage.get(); - eitherWithBuiltImage.fold(({ isLeft, value }) => { - tEitherWithBuiltImage.trace.trace(buildImageMetric[isLeft ? 'failure' : 'success']); - if (isLeft) { - tEitherWithBuiltImage.trace - .addTrace(LogLevel.ERROR) - .trace(`oh nyoo we couldn't buiwd the img :(( ${value}`); - return; - } - tEitherWithBuiltImage.trace.addTrace('buildOutput').trace(value.buildOutput); - }); - }) + .flatMapAsync(TraceUtil.promiseify(TraceUtil.traceResultingEither(buildImageMetric))) + .peek( + TraceUtil.promiseify((tBuilt) => + tBuilt.get().fold( + (err) => tBuilt.trace.trace(`oh nyoo we couldn't buiwd the img :(( ${err}`), + (ok) => tBuilt.trace.traceScope('buildOutput').trace(ok.buildOutput), + ), + ), + ) .map(async (tEitherWithBuiltImage) => { const eitherWithBuiltImage = await tEitherWithBuiltImage.get(); return eitherWithBuiltImage |