Skip to content

Commit 8b684e1

Browse files
author
Deploy Bot
committed
fix(cli-v3): authenticate to Docker Hub to prevent rate limits (#2911)
1 parent 93aa053 commit 8b684e1

File tree

2 files changed

+50
-7
lines changed

2 files changed

+50
-7
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@trigger.dev/cli-v3": patch
3+
---
4+
5+
Fix: Native build server failed with Docker Hub rate limits. Added support for checking checking `DOCKER_USERNAME` and `DOCKER_PASSWORD` in environment variables and logging into Docker Hub before building. (#2911)

packages/cli-v3/src/deploy/buildImage.ts

Lines changed: 45 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,40 @@ async function localBuildImage(options: SelfHostedBuildImageOptions): Promise<Bu
473473

474474
const errors: string[] = [];
475475

476+
// Authenticate to Docker Hub if credentials are provided (fixes rate limit issues)
477+
let loggedInToDockerHub = false;
478+
if (process.env.DOCKER_USERNAME && process.env.DOCKER_PASSWORD) {
479+
logger.debug("Logging in to Docker Hub");
480+
const loginProcess = x(
481+
"docker",
482+
["login", "--username", process.env.DOCKER_USERNAME, "--password-stdin"],
483+
{
484+
nodeOptions: {
485+
cwd: options.cwd,
486+
},
487+
}
488+
);
489+
490+
loginProcess.process?.stdin?.write(process.env.DOCKER_PASSWORD);
491+
loginProcess.process?.stdin?.end();
492+
493+
for await (const line of loginProcess) {
494+
errors.push(line);
495+
logger.debug(line);
496+
}
497+
498+
if (loginProcess.exitCode !== 0) {
499+
return {
500+
ok: false as const,
501+
error: `Failed to login to Docker Hub`,
502+
logs: extractLogs(errors),
503+
};
504+
}
505+
506+
loggedInToDockerHub = true;
507+
options.onLog?.("Successfully logged in to Docker Hub");
508+
}
509+
476510
let cloudRegistryHost: string | undefined;
477511
if (push && options.authenticateToRegistry) {
478512
cloudRegistryHost =
@@ -550,13 +584,12 @@ async function localBuildImage(options: SelfHostedBuildImageOptions): Promise<Bu
550584
options.noCache ? "--no-cache" : undefined,
551585
...(useRegistryCache
552586
? [
553-
"--cache-to",
554-
`type=registry,mode=max,image-manifest=true,oci-mediatypes=true,ref=${projectCacheRef}${
555-
cacheCompression === "zstd" ? ",compression=zstd" : ""
556-
}`,
557-
"--cache-from",
558-
`type=registry,ref=${projectCacheRef}`,
559-
]
587+
"--cache-to",
588+
`type=registry,mode=max,image-manifest=true,oci-mediatypes=true,ref=${projectCacheRef}${cacheCompression === "zstd" ? ",compression=zstd" : ""
589+
}`,
590+
"--cache-from",
591+
`type=registry,ref=${projectCacheRef}`,
592+
]
560593
: []),
561594
"--output",
562595
outputOptions.join(","),
@@ -662,6 +695,11 @@ async function localBuildImage(options: SelfHostedBuildImageOptions): Promise<Bu
662695
await x("docker", ["logout", cloudRegistryHost]);
663696
}
664697

698+
if (loggedInToDockerHub) {
699+
logger.debug("Logging out from Docker Hub");
700+
await x("docker", ["logout"]);
701+
}
702+
665703
return {
666704
ok: true as const,
667705
imageSizeBytes,

0 commit comments

Comments
 (0)