Skip to content

Commit 0a17676

Browse files
committed
use deploy shortcode instead of new nanoid
1 parent cd07aae commit 0a17676

File tree

3 files changed

+19
-12
lines changed

3 files changed

+19
-12
lines changed

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@ import { tryCatch } from "@trigger.dev/core";
1212
import { logger } from "~/services/logger.server";
1313
import { type RegistryConfig } from "./registryConfig.server";
1414
import type { EnvironmentType } from "@trigger.dev/core/v3";
15-
import { customAlphabet } from "nanoid";
16-
17-
const nanoid = customAlphabet("1234567890abcdefghijklmnopqrstuvwxyz", 8);
1815

1916
// Optional configuration for cross-account access
2017
export type AssumeRoleConfig = {
@@ -106,20 +103,21 @@ export async function getDeploymentImageRef({
106103
projectRef,
107104
nextVersion,
108105
environmentType,
106+
deploymentShortCode,
109107
}: {
110108
registry: RegistryConfig;
111109
projectRef: string;
112110
nextVersion: string;
113111
environmentType: EnvironmentType;
112+
deploymentShortCode: string;
114113
}): Promise<{
115114
imageRef: string;
116115
isEcr: boolean;
117116
repoCreated: boolean;
118117
}> {
119118
const repositoryName = `${registry.namespace}/${projectRef}`;
120119
const envType = environmentType.toLowerCase();
121-
const randomSuffix = nanoid();
122-
const imageRef = `${registry.host}/${repositoryName}:${nextVersion}.${envType}.${randomSuffix}`;
120+
const imageRef = `${registry.host}/${repositoryName}:${nextVersion}.${envType}.${deploymentShortCode}`;
123121

124122
if (!isEcrRegistry(registry.host)) {
125123
return {

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,15 @@ export class InitializeDeploymentService extends BaseService {
7373
const isV4Deployment = payload.type === "MANAGED";
7474
const registryConfig = getRegistryConfig(isV4Deployment);
7575

76+
const deploymentShortCode = nanoid(8);
77+
7678
const [imageRefError, imageRefResult] = await tryCatch(
7779
getDeploymentImageRef({
7880
registry: registryConfig,
7981
projectRef: environment.project.externalRef,
8082
nextVersion,
8183
environmentType: environment.type,
84+
deploymentShortCode,
8285
})
8386
);
8487

@@ -111,7 +114,7 @@ export class InitializeDeploymentService extends BaseService {
111114
data: {
112115
friendlyId: generateFriendlyId("deployment"),
113116
contentHash: payload.contentHash,
114-
shortCode: nanoid(8),
117+
shortCode: deploymentShortCode,
115118
version: nextVersion,
116119
status: "BUILDING",
117120
environmentId: environment.id,

apps/webapp/test/getDeploymentImageRef.test.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,15 @@ describe("getDeploymentImageRef", () => {
7070
projectRef: testProjectRef,
7171
nextVersion: "20250630.1",
7272
environmentType: "DEVELOPMENT",
73+
deploymentShortCode: "test1234",
7374
});
7475

7576
// Check the image ref structure and that it contains expected parts
7677
expect(imageRef.imageRef).toMatch(
7778
new RegExp(
7879
`^${escapeHostForRegex(
7980
"registry.example.com"
80-
)}/${testNamespace}/${testProjectRef}:20250630\\.1\\.development\\.[a-z0-9]{8}$`
81+
)}/${testNamespace}/${testProjectRef}:20250630\\.1\\.development\\.test1234$`
8182
)
8283
);
8384
expect(imageRef.isEcr).toBe(false);
@@ -99,13 +100,14 @@ describe("getDeploymentImageRef", () => {
99100
projectRef: testProjectRef2,
100101
nextVersion: "20250630.1",
101102
environmentType: "DEVELOPMENT",
103+
deploymentShortCode: "test1234",
102104
});
103105

104106
expect(imageRef1.imageRef).toMatch(
105107
new RegExp(
106108
`^${escapeHostForRegex(
107109
testHost
108-
)}/${testNamespace}/${testProjectRef2}:20250630\\.1\\.development\\.[a-z0-9]{8}$`
110+
)}/${testNamespace}/${testProjectRef2}:20250630\\.1\\.development\\.test1234$`
109111
)
110112
);
111113
expect(imageRef1.isEcr).toBe(true);
@@ -124,13 +126,14 @@ describe("getDeploymentImageRef", () => {
124126
projectRef: testProjectRef2,
125127
nextVersion: "20250630.2",
126128
environmentType: "DEVELOPMENT",
129+
deploymentShortCode: "test1234",
127130
});
128131

129132
expect(imageRef2.imageRef).toMatch(
130133
new RegExp(
131134
`^${escapeHostForRegex(
132135
testHost
133-
)}/${testNamespace}/${testProjectRef2}:20250630\\.2\\.development\\.[a-z0-9]{8}$`
136+
)}/${testNamespace}/${testProjectRef2}:20250630\\.2\\.development\\.test1234$`
134137
)
135138
);
136139
expect(imageRef2.isEcr).toBe(true);
@@ -153,13 +156,14 @@ describe("getDeploymentImageRef", () => {
153156
projectRef: testProjectRef,
154157
nextVersion: "20250630.2",
155158
environmentType: "PRODUCTION",
159+
deploymentShortCode: "test1234",
156160
});
157161

158162
expect(imageRef.imageRef).toMatch(
159163
new RegExp(
160164
`^${escapeHostForRegex(
161165
testHost
162-
)}/${testNamespace}/${testProjectRef}:20250630\\.2\\.production\\.[a-z0-9]{8}$`
166+
)}/${testNamespace}/${testProjectRef}:20250630\\.2\\.production\\.test1234$`
163167
)
164168
);
165169
expect(imageRef.isEcr).toBe(true);
@@ -183,6 +187,7 @@ describe("getDeploymentImageRef", () => {
183187
projectRef: testProjectRef,
184188
nextVersion: sameVersion,
185189
environmentType: sameEnvironmentType,
190+
deploymentShortCode: "test1234",
186191
});
187192

188193
const secondImageRef = await getDeploymentImageRef({
@@ -198,21 +203,22 @@ describe("getDeploymentImageRef", () => {
198203
projectRef: testProjectRef,
199204
nextVersion: sameVersion,
200205
environmentType: sameEnvironmentType,
206+
deploymentShortCode: "test4321",
201207
});
202208

203209
// Even with the same environment type and version, the image refs should be different due to random suffix
204210
expect(firstImageRef.imageRef).toMatch(
205211
new RegExp(
206212
`^${escapeHostForRegex(
207213
"registry.example.com"
208-
)}/${testNamespace}/${testProjectRef}:${sameVersion}\\.preview\\.[a-z0-9]{8}$`
214+
)}/${testNamespace}/${testProjectRef}:${sameVersion}\\.preview\\.test1234$`
209215
)
210216
);
211217
expect(secondImageRef.imageRef).toMatch(
212218
new RegExp(
213219
`^${escapeHostForRegex(
214220
"registry.example.com"
215-
)}/${testNamespace}/${testProjectRef}:${sameVersion}\\.preview\\.[a-z0-9]{8}$`
221+
)}/${testNamespace}/${testProjectRef}:${sameVersion}\\.preview\\.test4321$`
216222
)
217223
);
218224
expect(firstImageRef.imageRef).not.toBe(secondImageRef.imageRef);

0 commit comments

Comments
 (0)