(params: {
contextDir: string;
dockerfilePath: string;
repository: string;
tag: string;
buildArgs?: Record<string, string>;
parentSpan?: Span;
})
| 68 | } |
| 69 | |
| 70 | async function buildAndPushImage(params: { |
| 71 | contextDir: string; |
| 72 | dockerfilePath: string; |
| 73 | repository: string; |
| 74 | tag: string; |
| 75 | buildArgs?: Record<string, string>; |
| 76 | parentSpan?: Span; |
| 77 | }): Promise<string> { |
| 78 | const { contextDir, dockerfilePath, repository, tag, buildArgs, parentSpan } = |
| 79 | params; |
| 80 | const engine = selectContainerEngine(); |
| 81 | |
| 82 | return withSpan( |
| 83 | parentSpan, |
| 84 | 'container.build_and_push', |
| 85 | { |
| 86 | 'container.engine': engine.name, |
| 87 | 'container.registry': VCR_REGISTRY, |
| 88 | 'container.repository': repository, |
| 89 | }, |
| 90 | async buildSpan => { |
| 91 | const token = await withSpan(buildSpan, 'container.mint_oidc', {}, s => |
| 92 | resolveOidcTokenForBuild(s) |
| 93 | ); |
| 94 | |
| 95 | const claims = decodeOidcClaims(token); |
| 96 | debug(`registry token: ${tokenFingerprint(token)}`); |
| 97 | debugTokenClaims('OIDC token claims', token); |
| 98 | |
| 99 | const username = claims.owner_id; |
| 100 | if (!username) { |
| 101 | throw new Error( |
| 102 | 'VERCEL_OIDC_TOKEN is missing the `owner_id` (team id) claim required to ' + |
| 103 | 'authenticate to the container registry.' |
| 104 | ); |
| 105 | } |
| 106 | |
| 107 | const fullRepository = [claims.owner, claims.project, repository].join( |
| 108 | '/' |
| 109 | ); |
| 110 | const imageRef = `${VCR_REGISTRY}/${fullRepository}:${tag}`; |
| 111 | |
| 112 | buildSpan?.setAttributes({ |
| 113 | 'container.repository': fullRepository, |
| 114 | 'image.tag': tag, |
| 115 | 'image.ref': imageRef, |
| 116 | 'registry.username': username, |
| 117 | }); |
| 118 | |
| 119 | return engine.withRuntime(buildSpan, async () => { |
| 120 | await withSpan( |
| 121 | buildSpan, |
| 122 | 'container.ensure_toolchain_ready', |
| 123 | { 'container.engine': engine.name }, |
| 124 | s => engine.ensureReady(s) |
| 125 | ); |
| 126 | |
| 127 | await withSpan( |
no test coverage detected