|
1 | | -import { BatchGetImageCommand, type BatchGetImageCommandOutput } from "@aws-sdk/client-ecr"; |
| 1 | +import { |
| 2 | + BatchGetImageCommand, |
| 3 | + type BatchGetImageCommandOutput, |
| 4 | + RepositoryNotFoundException, |
| 5 | +} from "@aws-sdk/client-ecr"; |
2 | 6 | import { tryCatch } from "@trigger.dev/core"; |
3 | 7 | import { logger } from "~/services/logger.server"; |
4 | 8 | import { |
@@ -81,28 +85,17 @@ const sendBatchGetImage: BatchGetImageSender = async ({ |
81 | 85 | imageIds, |
82 | 86 | }) => { |
83 | 87 | const ecr = await createEcrClient({ region, assumeRole }); |
84 | | - return ecr.send( |
85 | | - new BatchGetImageCommand({ |
86 | | - repositoryName, |
87 | | - registryId, |
88 | | - imageIds, |
89 | | - // We only care whether the manifest exists, not its contents. |
90 | | - acceptedMediaTypes: [ |
91 | | - "application/vnd.docker.distribution.manifest.v2+json", |
92 | | - "application/vnd.oci.image.manifest.v1+json", |
93 | | - "application/vnd.oci.image.index.v1+json", |
94 | | - "application/vnd.docker.distribution.manifest.list.v2+json", |
95 | | - ], |
96 | | - }) |
97 | | - ); |
| 88 | + // No acceptedMediaTypes: only the single-manifest types are valid enum values, and |
| 89 | + // we only care whether the image exists, not its manifest format. |
| 90 | + return ecr.send(new BatchGetImageCommand({ repositoryName, registryId, imageIds })); |
98 | 91 | }; |
99 | 92 |
|
100 | 93 | /** |
101 | 94 | * Pre-promotion backstop: check the deployment image actually exists in ECR. |
102 | 95 | * |
103 | | - * Returns "unknown" for non-ECR registries or any error we can't read as a |
104 | | - * definitive miss - callers treat "unknown" as "proceed", so a verifier failure |
105 | | - * never becomes a deploy outage. `_send` is a test seam. |
| 96 | + * "found"/"missing" are definitive (a nonexistent repo counts as missing). |
| 97 | + * "unknown" means we couldn't determine it - non-ECR registry, unparseable ref, or |
| 98 | + * an API error; the caller decides what to do with each. `_send` is a test seam. |
106 | 99 | */ |
107 | 100 | export async function ecrImageExists( |
108 | 101 | { |
@@ -152,6 +145,11 @@ export async function ecrImageExists( |
152 | 145 | ); |
153 | 146 |
|
154 | 147 | if (error) { |
| 148 | + // A missing repo is a definitive miss, not an ambiguous error. |
| 149 | + if (error instanceof RepositoryNotFoundException) { |
| 150 | + return "missing"; |
| 151 | + } |
| 152 | + |
155 | 153 | logger.error("Failed to verify deployment image in ECR", { |
156 | 154 | imageReference, |
157 | 155 | repositoryName: parsed.repositoryName, |
|
0 commit comments