Merge branch 'feat/lambda-ecr-push' into feat/lambda-arm64-deps

This commit is contained in:
Miguel Angel Simon Sierra
2026-10-22 13:02:26 -04:00
2 changed files with 38 additions and 3 deletions
@@ -61,11 +61,16 @@ class FakeEcr {
DescribeRepositoriesCommand(input: { repositoryNames: string[] }): unknown {
return {
repositories: input.repositoryNames.map((name) => ({
repositoryArn: `arn:aws:ecr:r:1:repository/${name}`,
repositoryUri: this.repositories.get(name),
})),
};
}
ListTagsForResourceCommand(input: { resourceArn: string }): unknown {
return { tags: this.repositoryTags.get(input.resourceArn.split("/").pop() ?? "") ?? [] };
}
BatchCheckLayerAvailabilityCommand(input: { layerDigests: string[] }): unknown {
if (input.layerDigests.length > 100) throw awsError("InvalidParameterException");
const stored = (d: string) => this.blobs.has(d) && !this.hiddenFromCheck.has(d);
@@ -344,4 +349,19 @@ describe("ensureEcrRepository", () => {
expect(repositoryUri).toBe(`${REGISTRY}/hyperframes-render`);
expect(ecr.calls).toEqual(["CreateRepositoryCommand", "DescribeRepositoriesCommand"]);
});
it("adopts an existing repository only when it carries the tags", async () => {
const ecr = new FakeEcr();
const tags = [{ Key: "hyperframes:stack", Value: "s" }];
await ensureEcrRepository({ ecr: asEcr(ecr), repositoryName: "s-video", tags });
const again = await ensureEcrRepository({ ecr: asEcr(ecr), repositoryName: "s-video", tags });
expect(again.repositoryUri).toBe(`${REGISTRY}/s-video`);
ecr.repositories.set("other-video", `${REGISTRY}/other-video`);
ecr.repositoryTags.set("other-video", [{ Key: "hyperframes:stack", Value: "other" }]);
await expect(
ensureEcrRepository({ ecr: asEcr(ecr), repositoryName: "other-video", tags }),
).rejects.toThrow("other-video already exists without hyperframes:stack=s");
});
});
+18 -3
View File
@@ -12,6 +12,7 @@ import {
DescribeRepositoriesCommand,
ECRClient,
InitiateLayerUploadCommand,
ListTagsForResourceCommand,
PutImageCommand,
type Repository,
type Tag,
@@ -37,11 +38,11 @@ export interface EnsureEcrRepositoryOptions {
ecr?: ECRClient;
region?: string;
repositoryName: string;
/** Applied only when the repository is created; an existing repository keeps its tags. */
/** Set on create. An existing repository is adopted only if it already carries every one. */
tags?: Tag[];
}
/** Create the repository, or look it up when it already exists. */
/** Create the repository, or adopt an existing one that carries `tags`. */
export async function ensureEcrRepository(
opts: EnsureEcrRepositoryOptions,
): Promise<{ repositoryUri: string }> {
@@ -56,7 +57,21 @@ export async function ensureEcrRepository(
const found = await ecr.send(
new DescribeRepositoriesCommand({ repositoryNames: [repositoryName] }),
);
return { repositoryUri: repositoryUriOf(found.repositories?.[0], repositoryName) };
const repository = found.repositories?.[0];
if (tags?.length) {
const listed = await ecr.send(
new ListTagsForResourceCommand({ resourceArn: repository?.repositoryArn }),
);
const has = new Map((listed.tags ?? []).map((tag) => [tag.Key, tag.Value]));
const missing = tags.filter((tag) => has.get(tag.Key) !== tag.Value);
if (missing.length > 0) {
const wanted = missing.map((tag) => `${tag.Key}=${tag.Value}`).join(", ");
throw new Error(
`[ensureEcrRepository] ${repositoryName} already exists without ${wanted}; refusing to adopt a repository this caller did not create`,
);
}
}
return { repositoryUri: repositoryUriOf(repository, repositoryName) };
}
function repositoryUriOf(repository: Repository | undefined, repositoryName: string): string {