diff --git a/packages/server/src/utils/builders/index.ts b/packages/server/src/utils/builders/index.ts index 1cdc9787c..ce10413ac 100644 --- a/packages/server/src/utils/builders/index.ts +++ b/packages/server/src/utils/builders/index.ts @@ -211,21 +211,21 @@ const getImageName = (application: ApplicationNested) => { } if (registry) { - return join(registry.imagePrefix || "", appName); + return join(registry.registryUrl, registry.imagePrefix || "", appName); } return `${appName}:latest`; }; const getAuthConfig = (application: ApplicationNested) => { - const { registry, username, password, sourceType } = application; + const { registry, username, password, sourceType, registryUrl } = application; if (sourceType === "docker") { if (username && password) { return { password, username, - serveraddress: "https://index.docker.io/v1/", + serveraddress: registryUrl || "", }; } } else if (registry) { diff --git a/packages/server/src/utils/cluster/upload.ts b/packages/server/src/utils/cluster/upload.ts index 22c9881c6..980ace67c 100644 --- a/packages/server/src/utils/cluster/upload.ts +++ b/packages/server/src/utils/cluster/upload.ts @@ -1,5 +1,5 @@ import type { WriteStream } from "node:fs"; -import { join } from "node:path"; +import path, { join } from "node:path"; import type { ApplicationNested } from "../builders"; import { spawnAsync } from "../process/spawnAsync"; @@ -13,27 +13,32 @@ export const uploadImage = async ( throw new Error("Registry not found"); } - const { registryUrl, imagePrefix, registryType } = registry; + const { registryUrl, imagePrefix } = registry; const { appName } = application; const imageName = `${appName}:latest`; const finalURL = registryUrl; - const registryTag = join(imagePrefix || "", imageName); + const registryTag = path + .join(registryUrl, join(imagePrefix || "", imageName)) + .replace(/\/+/g, "/"); try { writeStream.write( - `📦 [Enabled Registry] Uploading image to ${registry.registryType} | ${registryTag} | ${finalURL}\n`, + `📦 [Enabled Registry] Uploading image to ${registry.registryType} | ${imageName} | ${finalURL}\n`, ); - await spawnAsync( + const loginCommand = spawnAsync( "docker", - ["login", finalURL, "-u", registry.username, "-p", registry.password], + ["login", finalURL, "-u", registry.username, "--password-stdin"], (data) => { if (writeStream.writable) { writeStream.write(data); } }, ); + loginCommand.child?.stdin?.write(registry.password); + loginCommand.child?.stdin?.end(); + await loginCommand; await spawnAsync("docker", ["tag", imageName, registryTag], (data) => { if (writeStream.writable) { @@ -68,22 +73,23 @@ export const uploadImageRemoteCommand = ( const finalURL = registryUrl; - const registryTag = join(imagePrefix || "", imageName); + const registryTag = path + .join(registryUrl, join(imagePrefix || "", imageName)) + .replace(/\/+/g, "/"); try { const command = ` echo "📦 [Enabled Registry] Uploading image to '${registry.registryType}' | '${registryTag}'" >> ${logPath}; - docker login ${finalURL} -u ${registry.username} -p ${registry.password} >> ${logPath} 2>> ${logPath} || { + echo "${registry.password}" | docker login ${finalURL} -u ${registry.username} --password-stdin >> ${logPath} 2>> ${logPath} || { echo "❌ DockerHub Failed" >> ${logPath}; exit 1; } - echo "✅ DockerHub Login Success" >> ${logPath}; + echo "✅ Registry Login Success" >> ${logPath}; docker tag ${imageName} ${registryTag} >> ${logPath} 2>> ${logPath} || { echo "❌ Error tagging image" >> ${logPath}; exit 1; } - echo "✅ Image Tagged" >> ${logPath}; - + echo "✅ Image Tagged" >> ${logPath}; docker push ${registryTag} 2>> ${logPath} || { echo "❌ Error pushing image" >> ${logPath}; exit 1; @@ -92,7 +98,6 @@ export const uploadImageRemoteCommand = ( `; return command; } catch (error) { - console.log(error); throw error; } }; diff --git a/packages/server/src/utils/providers/docker.ts b/packages/server/src/utils/providers/docker.ts index 7245dc511..88c457767 100644 --- a/packages/server/src/utils/providers/docker.ts +++ b/packages/server/src/utils/providers/docker.ts @@ -53,7 +53,7 @@ export const buildRemoteDocker = async ( application: ApplicationNested, logPath: string, ) => { - const { sourceType, dockerImage, username, password } = application; + const { registryUrl, dockerImage, username, password } = application; try { if (!dockerImage) { @@ -65,7 +65,7 @@ echo "Pulling ${dockerImage}" >> ${logPath}; if (username && password) { command += ` -if ! docker login --username ${username} --password ${password} https://index.docker.io/v1/ >> ${logPath} 2>&1; then +if ! echo "${password}" | docker login --username "${username}" --password-stdin "${registryUrl || ""}" >> ${logPath} 2>&1; then echo "❌ Login failed" >> ${logPath}; exit 1; fi