From 0f63fdac4e53243905093c50dfb02d8d40696bd2 Mon Sep 17 00:00:00 2001 From: Mauricio Siu Date: Tue, 9 Dec 2025 23:07:44 -0600 Subject: [PATCH] refactor(deploy): streamline webhook image validation logic - Simplified the validation process for webhook image and Docker tag by consolidating checks and maintaining backward compatibility. - If webhook image information is not provided, the system now defaults to using the configured image, preserving previous behavior. --- .../pages/api/deploy/[refreshToken].ts | 57 ++++++++----------- 1 file changed, 25 insertions(+), 32 deletions(-) diff --git a/apps/dokploy/pages/api/deploy/[refreshToken].ts b/apps/dokploy/pages/api/deploy/[refreshToken].ts index 2ab607736..78e026257 100644 --- a/apps/dokploy/pages/api/deploy/[refreshToken].ts +++ b/apps/dokploy/pages/api/deploy/[refreshToken].ts @@ -81,41 +81,34 @@ export default async function handler( return; } - if (!webhookImageName) { - res.status(301).json({ - message: "Webhook Docker Image Name Not Found", - }); - return; - } + // If webhook provides image information, validate it matches the configured image + // If webhook doesn't provide image information, fall back to using the configured image (backward compatibility) + if (webhookImageName) { + // Validate image name matches + if (webhookImageName !== applicationImageName) { + res.status(301).json({ + message: `Application Image Name (${applicationImageName}) doesn't match request event payload Image Name (${webhookImageName}).`, + }); + return; + } - // Validate image name matches - if (webhookImageName !== applicationImageName) { - res.status(301).json({ - message: `Application Image Name (${applicationImageName}) doesn't match request event payload Image Name (${webhookImageName}).`, - }); - return; - } + if (!applicationDockerTag) { + res.status(301).json({ + message: "Application Docker Tag Not Found", + }); + return; + } - if (!applicationDockerTag) { - res.status(301).json({ - message: "Application Docker Tag Not Found", - }); - return; - } - - if (!webhookDockerTag) { - res.status(301).json({ - message: "Webhook Docker Tag Not Found", - }); - return; - } - - if (webhookDockerTag !== applicationDockerTag) { - res.status(301).json({ - message: `Application Image Tag (${applicationDockerTag}) doesn't match request event payload Image Tag (${webhookDockerTag}).`, - }); - return; + if (webhookDockerTag) { + if (webhookDockerTag !== applicationDockerTag) { + res.status(301).json({ + message: `Application Image Tag (${applicationDockerTag}) doesn't match request event payload Image Tag (${webhookDockerTag}).`, + }); + return; + } + } } + // If webhook doesn't provide image info, we'll use the configured image (old behavior) } else if (sourceType === "github") { const normalizedCommits = req.body?.commits?.flatMap( (commit: any) => commit.modified,