diff options
author | Elizabeth Hunt <me@liz.coffee> | 2025-07-20 16:03:44 -0700 |
---|---|---|
committer | Elizabeth Hunt <me@liz.coffee> | 2025-07-20 16:17:48 -0700 |
commit | 9e220eca4545982df83ffcaa66a9b050a3d6f24e (patch) | |
tree | a735fed0f50dec0083dac9284f45db73af1afea8 /worker/scripts/build_docker_image.ts | |
parent | 2e10e9172f8528868b70886335dbbe20f932f702 (diff) | |
download | ci-9e220eca4545982df83ffcaa66a9b050a3d6f24e.tar.gz ci-9e220eca4545982df83ffcaa66a9b050a3d6f24e.zip |
Fixes silent failures
Diffstat (limited to 'worker/scripts/build_docker_image.ts')
-rwxr-xr-x | worker/scripts/build_docker_image.ts | 73 |
1 files changed, 48 insertions, 25 deletions
diff --git a/worker/scripts/build_docker_image.ts b/worker/scripts/build_docker_image.ts index 1783e7c..f29bd61 100755 --- a/worker/scripts/build_docker_image.ts +++ b/worker/scripts/build_docker_image.ts @@ -11,8 +11,9 @@ import { } from '@emprespresso/pengueno'; import type { BuildDockerImageJob, BuildDockerImageJobProps } from '@emprespresso/ci_model'; import { Bitwarden, type LoginItem } from '@emprespresso/ci_worker'; +import path from 'path'; -const eitherJob = getRequiredEnvVars([ +const job = getRequiredEnvVars([ 'registry', 'namespace', 'repository', @@ -20,36 +21,39 @@ const eitherJob = getRequiredEnvVars([ 'context', 'dockerfile', 'buildTarget', -]).mapRight( - (baseArgs) => - <BuildDockerImageJob>{ - type: 'build_docker_image.js', - arguments: baseArgs, +]) + .mapRight( + (baseArgs) => + <BuildDockerImageJob>{ + type: 'build_docker_image.js', + arguments: baseArgs, + }, + ) + .fold( + (err) => { + throw err; }, -); + (x) => x, + ); const eitherVault = Bitwarden.getConfigFromEnvironment().mapRight((config) => new Bitwarden(config)); 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}`); +const _logJob = LogTraceable.of(job).flatMap((tJob) => { + const trace = tJob.get().arguments.buildTarget; + return tJob.traceScope(() => `build_docker_image.${trace}`); }); await LogMetricTraceable.ofLogTraceable(_logJob) .flatMap(TraceUtil.withMetricTrace(buildImageMetric)) .flatMap(TraceUtil.withMetricTrace(loginMetric)) - .peek((tEitherJob) => tEitherJob.trace.trace('starting docker image build job! (⑅˘꒳˘)')) - .map((tEitherJob) => - tEitherJob.get().flatMapAsync((job) => - eitherVault.flatMapAsync(async (vault) => { - const eitherKey = await vault.unlock(tEitherJob); - return eitherKey.mapRight((key) => ({ job, key, vault })); - }), - ), + .peek((tJob) => tJob.trace.trace('starting docker image build job! (⑅˘꒳˘)')) + .map((tJob) => + eitherVault.flatMapAsync(async (vault) => { + const job = tJob.get(); + const eitherKey = await vault.unlock(tJob); + return eitherKey.mapRight((key) => ({ job, key, vault })); + }), ) .map(async (tEitherJobVault) => { tEitherJobVault.trace.trace('logging into the wegistwy uwu~'); @@ -85,9 +89,10 @@ await LogMetricTraceable.ofLogTraceable(_logJob) ) .get(), ); - return eitherBuiltImage.flatMap((buildOutput) => - eitherWithAuthdRegistryBuildJob.mapRight((job) => ({ buildOutput, job })), - ); + return eitherBuiltImage.joinRight(eitherWithAuthdRegistryBuildJob, (job, buildOutput) => ({ + job, + buildOutput, + })); }) .flatMapAsync(TraceUtil.promiseify(TraceUtil.traceResultingEither(buildImageMetric))) .peek( @@ -104,6 +109,13 @@ await LogMetricTraceable.ofLogTraceable(_logJob) .mapRight(({ job }) => tEitherWithBuiltImage.move(getPushCommand(job.arguments.imageTag))) .flatMapAsync((tPushCommand) => getStdout(tPushCommand)); }) + .map(async (tEitherJob) => { + const eitherJob = await tEitherJob.get(); + return eitherJob.fold( + (e) => Promise.reject(e), + () => Promise.resolve(0), + ); + }) .get(); function getDockerLoginCommand(username: string, registry: string): Command { @@ -111,7 +123,18 @@ function getDockerLoginCommand(username: string, registry: string): Command { } function getBuildCommand({ buildTarget, imageTag, dockerfile, context }: BuildDockerImageJobProps): Command { - return ['docker', 'build', '--target', buildTarget, '-t', imageTag, '-f', dockerfile, context]; + return [ + 'cat', + path.join(context, dockerfile), + '|', + 'docker', + 'build', + '--target', + buildTarget, + '-t', + imageTag, + '-', + ]; } function getPushCommand(tag: string): Command { |