diff --git a/packages/server/src/services/registry.ts b/packages/server/src/services/registry.ts index ec8db8fa8..d30e178bb 100644 --- a/packages/server/src/services/registry.ts +++ b/packages/server/src/services/registry.ts @@ -15,7 +15,7 @@ function shEscape(s: string | undefined): string { return `'${s.replace(/'/g, `'\\''`)}'`; } -function safeDockerLoginCommand( +export function safeDockerLoginCommand( registry: string | undefined, user: string | undefined, pass: string | undefined, diff --git a/packages/server/src/utils/cluster/upload.ts b/packages/server/src/utils/cluster/upload.ts index aa014a05c..386beeb57 100644 --- a/packages/server/src/utils/cluster/upload.ts +++ b/packages/server/src/utils/cluster/upload.ts @@ -1,5 +1,6 @@ import { findAllDeploymentsByApplicationId } from "@dokploy/server/services/deployment"; import type { Registry } from "@dokploy/server/services/registry"; +import { safeDockerLoginCommand } from "@dokploy/server/services/registry"; import { createRollback } from "@dokploy/server/services/rollbacks"; import type { ApplicationNested } from "../builders"; @@ -115,10 +116,16 @@ const getRegistryCommands = ( imageName: string, registryTag: string, ): string => { + const loginCommand = safeDockerLoginCommand( + registry.registryUrl, + registry.username, + registry.password, + ); + return ` echo "📦 [Enabled Registry] Uploading image to '${registry.registryType}' | '${registryTag}'" ; -echo "${registry.password}" | docker login ${registry.registryUrl} -u '${registry.username}' --password-stdin || { - echo "❌ DockerHub Failed" ; +${loginCommand} || { + echo "❌ Registry Login Failed" ; exit 1; } echo "✅ Registry Login Success" ; diff --git a/packages/server/src/utils/providers/docker.ts b/packages/server/src/utils/providers/docker.ts index 06f962dc7..cd04f6a98 100644 --- a/packages/server/src/utils/providers/docker.ts +++ b/packages/server/src/utils/providers/docker.ts @@ -1,3 +1,4 @@ +import { safeDockerLoginCommand } from "@dokploy/server/services/registry"; import type { ApplicationNested } from "../builders"; export const buildRemoteDocker = async (application: ApplicationNested) => { @@ -12,8 +13,14 @@ echo "Pulling ${dockerImage}"; `; if (username && password) { + const loginCommand = safeDockerLoginCommand( + registryUrl || "", + username, + password, + ); + command += ` -if ! echo "${password}" | docker login --username "${username}" --password-stdin "${registryUrl || ""}" 2>&1; then +if ! ${loginCommand} 2>&1; then echo "❌ Login failed"; exit 1; fi