Skip to content

Commit ba68d19

Browse files
committed
track if repo created and fix test
1 parent e65875d commit ba68d19

File tree

3 files changed

+57
-18
lines changed

3 files changed

+57
-18
lines changed

apps/webapp/app/v3/getDeploymentImageRef.server.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ export async function getDeploymentImageRef({
113113
}): Promise<{
114114
imageRef: string;
115115
isEcr: boolean;
116+
repoCreated: boolean;
116117
}> {
117118
const repositoryName = `${namespace}/${projectRef}`;
118119
const imageRef = `${host}/${repositoryName}:${nextVersion}.${environmentSlug}`;
@@ -121,10 +122,11 @@ export async function getDeploymentImageRef({
121122
return {
122123
imageRef,
123124
isEcr: false,
125+
repoCreated: false,
124126
};
125127
}
126128

127-
const [ecrRepoError] = await tryCatch(
129+
const [ecrRepoError, ecrData] = await tryCatch(
128130
ensureEcrRepositoryExists({
129131
repositoryName,
130132
registryHost: host,
@@ -145,6 +147,7 @@ export async function getDeploymentImageRef({
145147
return {
146148
imageRef,
147149
isEcr: true,
150+
repoCreated: ecrData.repoCreated,
148151
};
149152
}
150153

@@ -157,7 +160,7 @@ export function isEcrRegistry(registryHost: string) {
157160
}
158161
}
159162

160-
function parseRegistryTags(tags: string): Tag[] {
163+
export function parseRegistryTags(tags: string): Tag[] {
161164
if (!tags) {
162165
return [];
163166
}
@@ -297,7 +300,7 @@ async function ensureEcrRepositoryExists({
297300
registryHost: string;
298301
registryTags?: string;
299302
assumeRole?: AssumeRoleConfig;
300-
}): Promise<Repository> {
303+
}): Promise<{ repo: Repository; repoCreated: boolean }> {
301304
const { region, accountId } = parseEcrRegistryDomain(registryHost);
302305

303306
const [getRepoError, existingRepo] = await tryCatch(
@@ -311,7 +314,10 @@ async function ensureEcrRepositoryExists({
311314

312315
if (existingRepo) {
313316
logger.debug("ECR repository already exists", { repositoryName, region, existingRepo });
314-
return existingRepo;
317+
return {
318+
repo: existingRepo,
319+
repoCreated: false,
320+
};
315321
}
316322

317323
const [createRepoError, newRepo] = await tryCatch(
@@ -330,7 +336,10 @@ async function ensureEcrRepositoryExists({
330336
);
331337
}
332338

333-
return newRepo;
339+
return {
340+
repo: newRepo,
341+
repoCreated: true,
342+
};
334343
}
335344

336345
export async function getEcrAuthToken({

apps/webapp/app/v3/services/initializeDeployment.server.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ export class InitializeDeploymentService extends BaseService {
9696
throw new ServiceValidationError("Failed to get deployment image ref");
9797
}
9898

99-
const { imageRef, isEcr } = imageRefResult;
99+
const { imageRef, isEcr, repoCreated } = imageRefResult;
100100

101101
logger.debug("Creating deployment", {
102102
environmentId: environment.id,
@@ -106,6 +106,7 @@ export class InitializeDeploymentService extends BaseService {
106106
type: payload.type,
107107
imageRef,
108108
isEcr,
109+
repoCreated,
109110
});
110111

111112
const deployment = await this._prisma.workerDeployment.create({

apps/webapp/test/getDeploymentImageRef.test.ts

Lines changed: 41 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
getDeploymentImageRef,
55
getEcrAuthToken,
66
parseEcrRegistryDomain,
7+
parseRegistryTags,
78
} from "../app/v3/getDeploymentImageRef.server";
89
import { DeleteRepositoryCommand } from "@aws-sdk/client-ecr";
910

@@ -12,6 +13,7 @@ describe.skipIf(process.env.RUN_REGISTRY_TESTS !== "1")("getDeploymentImageRef",
1213
process.env.DEPLOY_REGISTRY_HOST || "123456789012.dkr.ecr.us-east-1.amazonaws.com";
1314
const testNamespace = process.env.DEPLOY_REGISTRY_NAMESPACE || "test-namespace";
1415
const testProjectRef = "proj_test_" + Math.random().toString(36).substring(7);
16+
const testProjectRef2 = testProjectRef + "_2";
1517

1618
const registryTags = process.env.DEPLOY_REGISTRY_ECR_TAGS || "test=test,test2=test2";
1719
const roleArn = process.env.DEPLOY_REGISTRY_ECR_ASSUME_ROLE_ARN;
@@ -30,13 +32,23 @@ describe.skipIf(process.env.RUN_REGISTRY_TESTS !== "1")("getDeploymentImageRef",
3032
try {
3133
const { region, accountId } = parseEcrRegistryDomain(testHost);
3234
const ecr = await createEcrClient({ region, assumeRole });
33-
await ecr.send(
34-
new DeleteRepositoryCommand({
35-
repositoryName: `${testNamespace}/${testProjectRef}`,
36-
registryId: accountId,
37-
force: true,
38-
})
39-
);
35+
36+
await Promise.all([
37+
ecr.send(
38+
new DeleteRepositoryCommand({
39+
repositoryName: `${testNamespace}/${testProjectRef}`,
40+
registryId: accountId,
41+
force: true,
42+
})
43+
),
44+
ecr.send(
45+
new DeleteRepositoryCommand({
46+
repositoryName: `${testNamespace}/${testProjectRef2}`,
47+
registryId: accountId,
48+
force: true,
49+
})
50+
),
51+
]);
4052
} catch (error) {
4153
console.warn("Failed to delete test repository:", error);
4254
}
@@ -60,20 +72,37 @@ describe.skipIf(process.env.RUN_REGISTRY_TESTS !== "1")("getDeploymentImageRef",
6072
});
6173

6274
it("should create ECR repository and return correct image ref", async () => {
63-
const imageRef = await getDeploymentImageRef({
75+
const imageRef1 = await getDeploymentImageRef({
6476
host: testHost,
6577
namespace: testNamespace,
66-
projectRef: testProjectRef,
78+
projectRef: testProjectRef2,
6779
nextVersion: "20250630.1",
6880
environmentSlug: "test",
6981
registryTags,
7082
assumeRole,
7183
});
7284

73-
expect(imageRef.imageRef).toBe(
74-
`${testHost}/${testNamespace}/${testProjectRef}:20250630.1.test`
85+
expect(imageRef1.imageRef).toBe(
86+
`${testHost}/${testNamespace}/${testProjectRef2}:20250630.1.test`
7587
);
76-
expect(imageRef.isEcr).toBe(true);
88+
expect(imageRef1.isEcr).toBe(true);
89+
expect(imageRef1.repoCreated).toBe(true);
90+
91+
const imageRef2 = await getDeploymentImageRef({
92+
host: testHost,
93+
namespace: testNamespace,
94+
projectRef: testProjectRef2,
95+
nextVersion: "20250630.2",
96+
environmentSlug: "test",
97+
registryTags,
98+
assumeRole,
99+
});
100+
101+
expect(imageRef2.imageRef).toBe(
102+
`${testHost}/${testNamespace}/${testProjectRef2}:20250630.2.test`
103+
);
104+
expect(imageRef2.isEcr).toBe(true);
105+
expect(imageRef2.repoCreated).toBe(false);
77106
});
78107

79108
it("should reuse existing ECR repository", async () => {

0 commit comments

Comments
 (0)