mirror of
https://github.com/andwati/dokploy.git
synced 2026-11-12 06:55:19 +00:00
refactor: reuse safeDockerLoginCommand from registry.ts instead of duplicating shEscape
This commit is contained in:
@@ -16,7 +16,7 @@ function shEscape(s: string | undefined): string {
|
|||||||
return `'${s.replace(/'/g, `'\\''`)}'`;
|
return `'${s.replace(/'/g, `'\\''`)}'`;
|
||||||
}
|
}
|
||||||
|
|
||||||
function safeDockerLoginCommand(
|
export function safeDockerLoginCommand(
|
||||||
registry: string | undefined,
|
registry: string | undefined,
|
||||||
user: string | undefined,
|
user: string | undefined,
|
||||||
pass: string | undefined,
|
pass: string | undefined,
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ import { findDeploymentById } from "./deployment";
|
|||||||
import type { Mount } from "./mount";
|
import type { Mount } from "./mount";
|
||||||
import type { Port } from "./port";
|
import type { Port } from "./port";
|
||||||
import type { Project } from "./project";
|
import type { Project } from "./project";
|
||||||
import type { Registry } from "./registry";
|
import { type Registry, safeDockerLoginCommand } from "./registry";
|
||||||
|
|
||||||
export const createRollback = async (
|
export const createRollback = async (
|
||||||
input: z.infer<typeof createRollbackSchema>,
|
input: z.infer<typeof createRollbackSchema>,
|
||||||
@@ -175,10 +175,11 @@ const dockerLoginForRegistry = async (
|
|||||||
registry: Registry,
|
registry: Registry,
|
||||||
serverId?: string | null,
|
serverId?: string | null,
|
||||||
) => {
|
) => {
|
||||||
const escapedRegistry = shEscape(registry.registryUrl);
|
const loginCommand = safeDockerLoginCommand(
|
||||||
const escapedUser = shEscape(registry.username);
|
registry.registryUrl,
|
||||||
const escapedPassword = shEscape(registry.password);
|
registry.username,
|
||||||
const loginCommand = `printf %s ${escapedPassword} | docker login ${escapedRegistry} -u ${escapedUser} --password-stdin`;
|
registry.password,
|
||||||
|
);
|
||||||
|
|
||||||
if (serverId) {
|
if (serverId) {
|
||||||
await execAsyncRemote(serverId, loginCommand);
|
await execAsyncRemote(serverId, loginCommand);
|
||||||
@@ -187,11 +188,6 @@ const dockerLoginForRegistry = async (
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
function shEscape(s: string | undefined): string {
|
|
||||||
if (!s) return "''";
|
|
||||||
return `'${s.replace(/'/g, `'\\''`)}'`;
|
|
||||||
}
|
|
||||||
|
|
||||||
const rollbackApplication = async (
|
const rollbackApplication = async (
|
||||||
appName: string,
|
appName: string,
|
||||||
image: string,
|
image: string,
|
||||||
|
|||||||
Reference in New Issue
Block a user