1- import { ExternalBuildData , FinalizeDeploymentRequestBody } from "@trigger.dev/core/v3/schemas" ;
2- import { AuthenticatedEnvironment } from "~/services/apiAuth.server" ;
1+ import {
2+ ExternalBuildData ,
3+ type FinalizeDeploymentRequestBody ,
4+ } from "@trigger.dev/core/v3/schemas" ;
5+ import type { AuthenticatedEnvironment } from "~/services/apiAuth.server" ;
36import { logger } from "~/services/logger.server" ;
47import { BaseService , ServiceValidationError } from "./baseService.server" ;
58import { join } from "node:path" ;
@@ -11,6 +14,7 @@ import { FinalizeDeploymentService } from "./finalizeDeployment.server";
1114import { remoteBuildsEnabled } from "../remoteImageBuilder.server" ;
1215import { getEcrAuthToken , isEcrRegistry } from "../getDeploymentImageRef.server" ;
1316import { tryCatch } from "@trigger.dev/core" ;
17+ import { getRegistryConfig , type RegistryConfig } from "../registryConfig.server" ;
1418
1519export class FinalizeDeploymentV2Service extends BaseService {
1620 public async call (
@@ -37,6 +41,7 @@ export class FinalizeDeploymentV2Service extends BaseService {
3741 externalBuildData : true ,
3842 environment : true ,
3943 imageReference : true ,
44+ type : true ,
4045 worker : {
4146 select : {
4247 project : true ,
@@ -78,11 +83,10 @@ export class FinalizeDeploymentV2Service extends BaseService {
7883 throw new ServiceValidationError ( "External build data is invalid" ) ;
7984 }
8085
81- if (
82- ! env . DEPLOY_REGISTRY_HOST ||
83- ! env . DEPLOY_REGISTRY_USERNAME ||
84- ! env . DEPLOY_REGISTRY_PASSWORD
85- ) {
86+ const isV4Deployment = deployment . type === "MANAGED" ;
87+ const registryConfig = getRegistryConfig ( isV4Deployment ) ;
88+
89+ if ( ! registryConfig . host || ! registryConfig . username || ! registryConfig . password ) {
8690 throw new ServiceValidationError ( "Missing deployment registry credentials" ) ;
8791 }
8892
@@ -104,12 +108,7 @@ export class FinalizeDeploymentV2Service extends BaseService {
104108 orgToken : env . DEPOT_TOKEN ,
105109 projectId : externalBuildData . data . projectId ,
106110 } ,
107- registry : {
108- host : env . DEPLOY_REGISTRY_HOST ,
109- namespace : env . DEPLOY_REGISTRY_NAMESPACE ,
110- username : env . DEPLOY_REGISTRY_USERNAME ,
111- password : env . DEPLOY_REGISTRY_PASSWORD ,
112- } ,
111+ registry : registryConfig ,
113112 deployment : {
114113 version : deployment . version ,
115114 environmentSlug : deployment . environment . slug ,
@@ -144,12 +143,7 @@ type ExecutePushToRegistryOptions = {
144143 orgToken : string ;
145144 projectId : string ;
146145 } ;
147- registry : {
148- host : string ;
149- namespace : string ;
150- username : string ;
151- password : string ;
152- } ;
146+ registry : RegistryConfig ;
153147 deployment : {
154148 version : string ;
155149 environmentSlug : string ;
@@ -175,12 +169,7 @@ async function executePushToRegistry(
175169 writer ?: WritableStreamDefaultWriter
176170) : Promise < ExecutePushResult > {
177171 // Step 1: We need to "login" to the registry
178- const [ loginError , configDir ] = await tryCatch (
179- ensureLoggedIntoDockerRegistry ( registry . host , {
180- username : registry . username ,
181- password : registry . password ,
182- } )
183- ) ;
172+ const [ loginError , configDir ] = await tryCatch ( ensureLoggedIntoDockerRegistry ( registry ) ) ;
184173
185174 if ( loginError ) {
186175 logger . error ( "Failed to login to registry" , {
@@ -260,31 +249,35 @@ async function executePushToRegistry(
260249 }
261250}
262251
263- async function ensureLoggedIntoDockerRegistry (
264- registryHost : string ,
265- auth : { username : string ; password : string } | undefined = undefined
266- ) {
252+ async function ensureLoggedIntoDockerRegistry ( registryConfig : RegistryConfig ) {
267253 const tmpDir = await createTempDir ( ) ;
268254 const dockerConfigPath = join ( tmpDir , "config.json" ) ;
269255
256+ let auth : { username : string ; password : string } ;
257+
270258 // If this is an ECR registry, get fresh credentials
271- if ( isEcrRegistry ( registryHost ) ) {
259+ if ( isEcrRegistry ( registryConfig . host ) ) {
272260 auth = await getEcrAuthToken ( {
273- registryHost,
274- assumeRole : env . DEPLOY_REGISTRY_ECR_ASSUME_ROLE_ARN
261+ registryHost : registryConfig . host ,
262+ assumeRole : registryConfig . ecrAssumeRoleArn
275263 ? {
276- roleArn : env . DEPLOY_REGISTRY_ECR_ASSUME_ROLE_ARN ,
277- externalId : env . DEPLOY_REGISTRY_ECR_ASSUME_ROLE_EXTERNAL_ID ,
264+ roleArn : registryConfig . ecrAssumeRoleArn ,
265+ externalId : registryConfig . ecrAssumeRoleExternalId ,
278266 }
279267 : undefined ,
280268 } ) ;
281- } else if ( ! auth ) {
269+ } else if ( ! registryConfig . username || ! registryConfig . password ) {
282270 throw new Error ( "Authentication required for non-ECR registry" ) ;
271+ } else {
272+ auth = {
273+ username : registryConfig . username ,
274+ password : registryConfig . password ,
275+ } ;
283276 }
284277
285278 await writeJSONFile ( dockerConfigPath , {
286279 auths : {
287- [ registryHost ] : {
280+ [ registryConfig . host ] : {
288281 auth : Buffer . from ( `${ auth . username } :${ auth . password } ` ) . toString ( "base64" ) ,
289282 } ,
290283 } ,
0 commit comments