mirror of
https://github.com/andwati/dokploy.git
synced 2026-11-20 19:18:45 +00:00
Merge pull request #2089 from Dokploy/2080-invalid-name-when-trying-to-deploy-an-app-with-dockerfile-to-ghcrio
fix(upload): refactor registry tag construction for image uploads
This commit is contained in:
@@ -1,5 +1,4 @@
|
|||||||
import { createWriteStream } from "node:fs";
|
import { createWriteStream } from "node:fs";
|
||||||
import { join } from "node:path";
|
|
||||||
import type { InferResultType } from "@dokploy/server/types/with";
|
import type { InferResultType } from "@dokploy/server/types/with";
|
||||||
import type { CreateServiceOptions } from "dockerode";
|
import type { CreateServiceOptions } from "dockerode";
|
||||||
import { uploadImage, uploadImageRemoteCommand } from "../cluster/upload";
|
import { uploadImage, uploadImageRemoteCommand } from "../cluster/upload";
|
||||||
@@ -211,16 +210,20 @@ export const mechanizeDockerContainer = async (
|
|||||||
|
|
||||||
const getImageName = (application: ApplicationNested) => {
|
const getImageName = (application: ApplicationNested) => {
|
||||||
const { appName, sourceType, dockerImage, registry } = application;
|
const { appName, sourceType, dockerImage, registry } = application;
|
||||||
|
const imageName = `${appName}:latest`;
|
||||||
if (sourceType === "docker") {
|
if (sourceType === "docker") {
|
||||||
return dockerImage || "ERROR-NO-IMAGE-PROVIDED";
|
return dockerImage || "ERROR-NO-IMAGE-PROVIDED";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (registry) {
|
if (registry) {
|
||||||
return join(registry.registryUrl, registry.imagePrefix || "", appName);
|
const { registryUrl, imagePrefix, username } = registry;
|
||||||
|
const registryTag = imagePrefix
|
||||||
|
? `${registryUrl}/${imagePrefix}/${imageName}`
|
||||||
|
: `${registryUrl}/${username}/${imageName}`;
|
||||||
|
return registryTag;
|
||||||
}
|
}
|
||||||
|
|
||||||
return `${appName}:latest`;
|
return imageName;
|
||||||
};
|
};
|
||||||
|
|
||||||
const getAuthConfig = (application: ApplicationNested) => {
|
const getAuthConfig = (application: ApplicationNested) => {
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import type { WriteStream } from "node:fs";
|
import type { WriteStream } from "node:fs";
|
||||||
import path, { join } from "node:path";
|
|
||||||
import type { ApplicationNested } from "../builders";
|
import type { ApplicationNested } from "../builders";
|
||||||
import { spawnAsync } from "../process/spawnAsync";
|
import { spawnAsync } from "../process/spawnAsync";
|
||||||
|
|
||||||
@@ -13,19 +12,22 @@ export const uploadImage = async (
|
|||||||
throw new Error("Registry not found");
|
throw new Error("Registry not found");
|
||||||
}
|
}
|
||||||
|
|
||||||
const { registryUrl, imagePrefix } = registry;
|
const { registryUrl, imagePrefix, username } = registry;
|
||||||
const { appName } = application;
|
const { appName } = application;
|
||||||
const imageName = `${appName}:latest`;
|
const imageName = `${appName}:latest`;
|
||||||
|
|
||||||
const finalURL = registryUrl;
|
const finalURL = registryUrl;
|
||||||
|
|
||||||
const registryTag = path
|
// Build registry tag in correct format: registry.com/owner/image:tag
|
||||||
.join(registryUrl, join(imagePrefix || "", imageName))
|
// For ghcr.io: ghcr.io/username/image:tag
|
||||||
.replace(/\/+/g, "/");
|
// For docker.io: docker.io/username/image:tag
|
||||||
|
const registryTag = imagePrefix
|
||||||
|
? `${registryUrl}/${imagePrefix}/${imageName}`
|
||||||
|
: `${registryUrl}/${username}/${imageName}`;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
writeStream.write(
|
writeStream.write(
|
||||||
`📦 [Enabled Registry] Uploading image to ${registry.registryType} | ${imageName} | ${finalURL}\n`,
|
`📦 [Enabled Registry] Uploading image to ${registry.registryType} | ${imageName} | ${finalURL} | ${registryTag}\n`,
|
||||||
);
|
);
|
||||||
const loginCommand = spawnAsync(
|
const loginCommand = spawnAsync(
|
||||||
"docker",
|
"docker",
|
||||||
@@ -67,15 +69,16 @@ export const uploadImageRemoteCommand = (
|
|||||||
throw new Error("Registry not found");
|
throw new Error("Registry not found");
|
||||||
}
|
}
|
||||||
|
|
||||||
const { registryUrl, imagePrefix } = registry;
|
const { registryUrl, imagePrefix, username } = registry;
|
||||||
const { appName } = application;
|
const { appName } = application;
|
||||||
const imageName = `${appName}:latest`;
|
const imageName = `${appName}:latest`;
|
||||||
|
|
||||||
const finalURL = registryUrl;
|
const finalURL = registryUrl;
|
||||||
|
|
||||||
const registryTag = path
|
// Build registry tag in correct format: registry.com/owner/image:tag
|
||||||
.join(registryUrl, join(imagePrefix || "", imageName))
|
const registryTag = imagePrefix
|
||||||
.replace(/\/+/g, "/");
|
? `${registryUrl}/${imagePrefix}/${imageName}`
|
||||||
|
: `${registryUrl}/${username}/${imageName}`;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const command = `
|
const command = `
|
||||||
|
|||||||
Reference in New Issue
Block a user