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,10 +83,13 @@ export class FinalizeDeploymentV2Service extends BaseService {
7883 throw new ServiceValidationError ( "External build data is invalid" ) ;
7984 }
8085
86+ const isV4Deployment = deployment . type === "MANAGED" ;
87+ const registryConfig = getRegistryConfig ( isV4Deployment ) ;
88+
89+ // For non-ECR registries, username and password are required upfront
8190 if (
82- ! env . DEPLOY_REGISTRY_HOST ||
83- ! env . DEPLOY_REGISTRY_USERNAME ||
84- ! env . DEPLOY_REGISTRY_PASSWORD
91+ ! isEcrRegistry ( registryConfig . host ) &&
92+ ( ! registryConfig . username || ! registryConfig . password )
8593 ) {
8694 throw new ServiceValidationError ( "Missing deployment registry credentials" ) ;
8795 }
@@ -104,12 +112,7 @@ export class FinalizeDeploymentV2Service extends BaseService {
104112 orgToken : env . DEPOT_TOKEN ,
105113 projectId : externalBuildData . data . projectId ,
106114 } ,
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- } ,
115+ registry : registryConfig ,
113116 deployment : {
114117 version : deployment . version ,
115118 environmentSlug : deployment . environment . slug ,
@@ -144,12 +147,7 @@ type ExecutePushToRegistryOptions = {
144147 orgToken : string ;
145148 projectId : string ;
146149 } ;
147- registry : {
148- host : string ;
149- namespace : string ;
150- username : string ;
151- password : string ;
152- } ;
150+ registry : RegistryConfig ;
153151 deployment : {
154152 version : string ;
155153 environmentSlug : string ;
@@ -175,12 +173,7 @@ async function executePushToRegistry(
175173 writer ?: WritableStreamDefaultWriter
176174) : Promise < ExecutePushResult > {
177175 // 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- ) ;
176+ const [ loginError , configDir ] = await tryCatch ( ensureLoggedIntoDockerRegistry ( registry ) ) ;
184177
185178 if ( loginError ) {
186179 logger . error ( "Failed to login to registry" , {
@@ -260,31 +253,35 @@ async function executePushToRegistry(
260253 }
261254}
262255
263- async function ensureLoggedIntoDockerRegistry (
264- registryHost : string ,
265- auth : { username : string ; password : string } | undefined = undefined
266- ) {
256+ async function ensureLoggedIntoDockerRegistry ( registryConfig : RegistryConfig ) {
267257 const tmpDir = await createTempDir ( ) ;
268258 const dockerConfigPath = join ( tmpDir , "config.json" ) ;
269259
260+ let auth : { username : string ; password : string } ;
261+
270262 // If this is an ECR registry, get fresh credentials
271- if ( isEcrRegistry ( registryHost ) ) {
263+ if ( isEcrRegistry ( registryConfig . host ) ) {
272264 auth = await getEcrAuthToken ( {
273- registryHost,
274- assumeRole : env . DEPLOY_REGISTRY_ECR_ASSUME_ROLE_ARN
265+ registryHost : registryConfig . host ,
266+ assumeRole : registryConfig . ecrAssumeRoleArn
275267 ? {
276- roleArn : env . DEPLOY_REGISTRY_ECR_ASSUME_ROLE_ARN ,
277- externalId : env . DEPLOY_REGISTRY_ECR_ASSUME_ROLE_EXTERNAL_ID ,
268+ roleArn : registryConfig . ecrAssumeRoleArn ,
269+ externalId : registryConfig . ecrAssumeRoleExternalId ,
278270 }
279271 : undefined ,
280272 } ) ;
281- } else if ( ! auth ) {
273+ } else if ( ! registryConfig . username || ! registryConfig . password ) {
282274 throw new Error ( "Authentication required for non-ECR registry" ) ;
275+ } else {
276+ auth = {
277+ username : registryConfig . username ,
278+ password : registryConfig . password ,
279+ } ;
283280 }
284281
285282 await writeJSONFile ( dockerConfigPath , {
286283 auths : {
287- [ registryHost ] : {
284+ [ registryConfig . host ] : {
288285 auth : Buffer . from ( `${ auth . username } :${ auth . password } ` ) . toString ( "base64" ) ,
289286 } ,
290287 } ,
0 commit comments