Merge pull request #3882 from aak-lear/fix/rollback-registry-auth

fix: add docker login before rollback and fix execAsyncRemote argument order
This commit is contained in:
Mauricio Siu
2026-03-04 22:11:04 -06:00
committed by GitHub
2 changed files with 28 additions and 3 deletions

View File

@@ -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,

View File

@@ -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>,
@@ -111,7 +111,7 @@ const deleteRollbackImage = async (image: string, serverId?: string | null) => {
const command = `docker image rm ${image} --force`; const command = `docker image rm ${image} --force`;
if (serverId) { if (serverId) {
await execAsyncRemote(command, serverId); await execAsyncRemote(serverId, command);
} else { } else {
await execAsync(command); await execAsync(command);
} }
@@ -171,6 +171,23 @@ export const rollback = async (rollbackId: string) => {
); );
}; };
const dockerLoginForRegistry = async (
registry: Registry,
serverId?: string | null,
) => {
const loginCommand = safeDockerLoginCommand(
registry.registryUrl,
registry.username,
registry.password,
);
if (serverId) {
await execAsyncRemote(serverId, loginCommand);
} else {
await execAsync(loginCommand);
}
};
const rollbackApplication = async ( const rollbackApplication = async (
appName: string, appName: string,
image: string, image: string,
@@ -188,6 +205,14 @@ const rollbackApplication = async (
throw new Error("Full context is required for rollback"); throw new Error("Full context is required for rollback");
} }
// Ensure Docker daemon is authenticated with the rollback registry
// before updating the swarm service. The authconfig in CreateServiceOptions
// alone is not sufficient — Docker Swarm also relies on the daemon's
// cached credentials (~/.docker/config.json) to distribute auth to nodes.
if (fullContext.rollbackRegistry) {
await dockerLoginForRegistry(fullContext.rollbackRegistry, serverId);
}
const docker = await getRemoteDocker(serverId); const docker = await getRemoteDocker(serverId);
// Use the same configuration as mechanizeDockerContainer // Use the same configuration as mechanizeDockerContainer