@@ -9,6 +9,8 @@ import { env } from "~/env.server";
99import { depot as execDepot } from "@depot/cli" ;
1010import { FinalizeDeploymentService } from "./finalizeDeployment.server" ;
1111import { remoteBuildsEnabled } from "../remoteImageBuilder.server" ;
12+ import { getEcrAuthToken , isEcrRegistry } from "../getDeploymentImageRef.server" ;
13+ import { tryCatch } from "@trigger.dev/core" ;
1214
1315export class FinalizeDeploymentV2Service extends BaseService {
1416 public async call (
@@ -172,11 +174,27 @@ async function executePushToRegistry(
172174 { depot, registry, deployment } : ExecutePushToRegistryOptions ,
173175 writer ?: WritableStreamDefaultWriter
174176) : Promise < ExecutePushResult > {
175- // Step 1: We need to "login" to the digital ocean registry
176- const configDir = await ensureLoggedIntoDockerRegistry ( registry . host , {
177- username : registry . username ,
178- password : registry . password ,
179- } ) ;
177+ // 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+ ) ;
184+
185+ if ( loginError ) {
186+ logger . error ( "Failed to login to registry" , {
187+ deployment,
188+ registryHost : registry . host ,
189+ error : loginError . message ,
190+ } ) ;
191+
192+ return {
193+ ok : false as const ,
194+ error : "Failed to login to registry" ,
195+ logs : "" ,
196+ } ;
197+ }
180198
181199 const imageTag = deployment . imageReference ;
182200
@@ -244,12 +262,18 @@ async function executePushToRegistry(
244262
245263async function ensureLoggedIntoDockerRegistry (
246264 registryHost : string ,
247- auth : { username : string ; password : string }
265+ auth : { username : string ; password : string } | undefined = undefined
248266) {
249267 const tmpDir = await createTempDir ( ) ;
250- // Read the current docker config
251268 const dockerConfigPath = join ( tmpDir , "config.json" ) ;
252269
270+ // If this is an ECR registry, get fresh credentials
271+ if ( isEcrRegistry ( registryHost ) ) {
272+ auth = await getEcrAuthToken ( { registryHost, registryId : env . DEPLOY_REGISTRY_ID } ) ;
273+ } else if ( ! auth ) {
274+ throw new Error ( "Authentication required for non-ECR registry" ) ;
275+ }
276+
253277 await writeJSONFile ( dockerConfigPath , {
254278 auths : {
255279 [ registryHost ] : {
0 commit comments