From e78d354d0d1548c0cef15edc783eef1f43bd12e9 Mon Sep 17 00:00:00 2001 From: Mauricio Siu <47042324+Siumauricio@users.noreply.github.com> Date: Thu, 28 Nov 2024 23:17:21 -0600 Subject: [PATCH 1/4] fix: add missing server flag boolean --- apps/dokploy/pages/api/deploy/github.ts | 265 ++++++++++++------------ 1 file changed, 133 insertions(+), 132 deletions(-) diff --git a/apps/dokploy/pages/api/deploy/github.ts b/apps/dokploy/pages/api/deploy/github.ts index bdbc0293d..1d8c094af 100644 --- a/apps/dokploy/pages/api/deploy/github.ts +++ b/apps/dokploy/pages/api/deploy/github.ts @@ -10,137 +10,138 @@ import type { NextApiRequest, NextApiResponse } from "next"; import { extractCommitMessage, extractHash } from "./[refreshToken]"; export default async function handler( - req: NextApiRequest, - res: NextApiResponse, + req: NextApiRequest, + res: NextApiResponse ) { - const signature = req.headers["x-hub-signature-256"]; - const githubBody = req.body; - - if (!githubBody?.installation?.id) { - res.status(400).json({ message: "Github Installation not found" }); - return; - } - - const githubResult = await db.query.github.findFirst({ - where: eq(github.githubInstallationId, githubBody.installation.id), - }); - - if (!githubResult) { - res.status(400).json({ message: "Github Installation not found" }); - return; - } - - if (!githubResult.githubWebhookSecret) { - res.status(400).json({ message: "Github Webhook Secret not set" }); - return; - } - const webhooks = new Webhooks({ - secret: githubResult.githubWebhookSecret, - }); - - const verified = await webhooks.verify( - JSON.stringify(githubBody), - signature as string, - ); - - if (!verified) { - res.status(401).json({ message: "Unauthorized" }); - return; - } - - if (req.headers["x-github-event"] === "ping") { - res.status(200).json({ message: "Ping received, webhook is active" }); - return; - } - - if (req.headers["x-github-event"] !== "push") { - res.status(400).json({ message: "We only accept push events" }); - return; - } - - try { - const branchName = githubBody?.ref?.replace("refs/heads/", ""); - const repository = githubBody?.repository?.name; - const deploymentTitle = extractCommitMessage(req.headers, req.body); - const deploymentHash = extractHash(req.headers, req.body); - - const apps = await db.query.applications.findMany({ - where: and( - eq(applications.sourceType, "github"), - eq(applications.autoDeploy, true), - eq(applications.branch, branchName), - eq(applications.repository, repository), - ), - }); - - for (const app of apps) { - const jobData: DeploymentJob = { - applicationId: app.applicationId as string, - titleLog: deploymentTitle, - descriptionLog: `Hash: ${deploymentHash}`, - type: "deploy", - applicationType: "application", - server: !!app.serverId, - }; - - if (IS_CLOUD && app.serverId) { - jobData.serverId = app.serverId; - await deploy(jobData); - return true; - } - await myQueue.add( - "deployments", - { ...jobData }, - { - removeOnComplete: true, - removeOnFail: true, - }, - ); - } - - const composeApps = await db.query.compose.findMany({ - where: and( - eq(compose.sourceType, "github"), - eq(compose.autoDeploy, true), - eq(compose.branch, branchName), - eq(compose.repository, repository), - ), - }); - - for (const composeApp of composeApps) { - const jobData: DeploymentJob = { - composeId: composeApp.composeId as string, - titleLog: deploymentTitle, - type: "deploy", - applicationType: "compose", - descriptionLog: `Hash: ${deploymentHash}`, - }; - - if (IS_CLOUD && composeApp.serverId) { - jobData.serverId = composeApp.serverId; - await deploy(jobData); - return true; - } - - await myQueue.add( - "deployments", - { ...jobData }, - { - removeOnComplete: true, - removeOnFail: true, - }, - ); - } - - const totalApps = apps.length + composeApps.length; - const emptyApps = totalApps === 0; - - if (emptyApps) { - res.status(200).json({ message: "No apps to deploy" }); - return; - } - res.status(200).json({ message: `Deployed ${totalApps} apps` }); - } catch (error) { - res.status(400).json({ message: "Error To Deploy Application", error }); - } + const signature = req.headers["x-hub-signature-256"]; + const githubBody = req.body; + + if (!githubBody?.installation?.id) { + res.status(400).json({ message: "Github Installation not found" }); + return; + } + + const githubResult = await db.query.github.findFirst({ + where: eq(github.githubInstallationId, githubBody.installation.id), + }); + + if (!githubResult) { + res.status(400).json({ message: "Github Installation not found" }); + return; + } + + if (!githubResult.githubWebhookSecret) { + res.status(400).json({ message: "Github Webhook Secret not set" }); + return; + } + const webhooks = new Webhooks({ + secret: githubResult.githubWebhookSecret, + }); + + const verified = await webhooks.verify( + JSON.stringify(githubBody), + signature as string + ); + + if (!verified) { + res.status(401).json({ message: "Unauthorized" }); + return; + } + + if (req.headers["x-github-event"] === "ping") { + res.status(200).json({ message: "Ping received, webhook is active" }); + return; + } + + if (req.headers["x-github-event"] !== "push") { + res.status(400).json({ message: "We only accept push events" }); + return; + } + + try { + const branchName = githubBody?.ref?.replace("refs/heads/", ""); + const repository = githubBody?.repository?.name; + const deploymentTitle = extractCommitMessage(req.headers, req.body); + const deploymentHash = extractHash(req.headers, req.body); + + const apps = await db.query.applications.findMany({ + where: and( + eq(applications.sourceType, "github"), + eq(applications.autoDeploy, true), + eq(applications.branch, branchName), + eq(applications.repository, repository) + ), + }); + + for (const app of apps) { + const jobData: DeploymentJob = { + applicationId: app.applicationId as string, + titleLog: deploymentTitle, + descriptionLog: `Hash: ${deploymentHash}`, + type: "deploy", + applicationType: "application", + server: !!app.serverId, + }; + + if (IS_CLOUD && app.serverId) { + jobData.serverId = app.serverId; + await deploy(jobData); + return true; + } + await myQueue.add( + "deployments", + { ...jobData }, + { + removeOnComplete: true, + removeOnFail: true, + } + ); + } + + const composeApps = await db.query.compose.findMany({ + where: and( + eq(compose.sourceType, "github"), + eq(compose.autoDeploy, true), + eq(compose.branch, branchName), + eq(compose.repository, repository) + ), + }); + + for (const composeApp of composeApps) { + const jobData: DeploymentJob = { + composeId: composeApp.composeId as string, + titleLog: deploymentTitle, + type: "deploy", + applicationType: "compose", + descriptionLog: `Hash: ${deploymentHash}`, + server: !!composeApp.serverId, + }; + + if (IS_CLOUD && composeApp.serverId) { + jobData.serverId = composeApp.serverId; + await deploy(jobData); + return true; + } + + await myQueue.add( + "deployments", + { ...jobData }, + { + removeOnComplete: true, + removeOnFail: true, + } + ); + } + + const totalApps = apps.length + composeApps.length; + const emptyApps = totalApps === 0; + + if (emptyApps) { + res.status(200).json({ message: "No apps to deploy" }); + return; + } + res.status(200).json({ message: `Deployed ${totalApps} apps` }); + } catch (error) { + res.status(400).json({ message: "Error To Deploy Application", error }); + } } From 7400913646a3c3a987d4cf5eb64e0c3f284ae4c7 Mon Sep 17 00:00:00 2001 From: Mauricio Siu <47042324+Siumauricio@users.noreply.github.com> Date: Thu, 28 Nov 2024 23:19:27 -0600 Subject: [PATCH 2/4] fix: add missing server flag boolean --- lefthook.yml | 2 +- package.json | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/lefthook.yml b/lefthook.yml index bbc2d71a6..508f42872 100644 --- a/lefthook.yml +++ b/lefthook.yml @@ -42,4 +42,4 @@ commit-msg: pre-commit: commands: lint-staged: - run: "pnpm check && npx lint-staged" + run: "pnpm lint-staged" diff --git a/package.json b/package.json index 53ef55d03..4c3282c8c 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,6 @@ "server:build": "pnpm --filter=server run build", "docker:build:canary": "./apps/dokploy/docker/build.sh canary", "typecheck": "pnpm -r run typecheck", - "format": "prettier --write \"**/*.{ts,tsx,md}\"", "build": "pnpm -r run build", "format-and-lint": "biome check .", "check": "biome check --write --no-errors-on-unmatched --files-ignore-unknown=true", From 0cf21cf3f72ba46ac718bf58de84f5a6a6de502d Mon Sep 17 00:00:00 2001 From: Mauricio Siu <47042324+Siumauricio@users.noreply.github.com> Date: Thu, 28 Nov 2024 23:20:50 -0600 Subject: [PATCH 3/4] refactor: add missing flag --- lefthook.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lefthook.yml b/lefthook.yml index 508f42872..1a491cd8a 100644 --- a/lefthook.yml +++ b/lefthook.yml @@ -41,5 +41,5 @@ commit-msg: pre-commit: commands: - lint-staged: - run: "pnpm lint-staged" + check: + run: "pnpm check" From 9a35c85277141071ae2574e7353b35ae8f94f845 Mon Sep 17 00:00:00 2001 From: Mauricio Siu <47042324+Siumauricio@users.noreply.github.com> Date: Thu, 28 Nov 2024 23:29:24 -0600 Subject: [PATCH 4/4] refactor: upgrade biome --- .../generic/save-bitbucket-provider.tsx | 2 - .../general/generic/save-github-provider.tsx | 2 - .../general/generic/save-gitlab-provider.tsx | 2 - .../save-bitbucket-provider-compose.tsx | 2 - .../generic/save-github-provider-compose.tsx | 2 - .../generic/save-gitlab-provider-compose.tsx | 2 - .../dashboard/database/backups/add-backup.tsx | 1 - .../database/backups/update-backup.tsx | 1 - .../dashboard/mysql/volumes/show-volumes.tsx | 14 +- .../dashboard/project/add-template.tsx | 1 - .../settings/billing/show-billing.tsx | 21 +- .../cluster/registry/show-registry.tsx | 6 +- .../notifications/add-notification.tsx | 34 ++- .../notifications/update-notification.tsx | 34 ++- .../settings/servers/show-servers.tsx | 22 +- apps/dokploy/components/ui/input-otp.tsx | 2 +- apps/dokploy/styles/globals.css | 216 +++++++++--------- package.json | 2 +- pnpm-lock.yaml | 74 +++--- 19 files changed, 203 insertions(+), 237 deletions(-) diff --git a/apps/dokploy/components/dashboard/application/general/generic/save-bitbucket-provider.tsx b/apps/dokploy/components/dashboard/application/general/generic/save-bitbucket-provider.tsx index 28aaec464..d6dfa20e7 100644 --- a/apps/dokploy/components/dashboard/application/general/generic/save-bitbucket-provider.tsx +++ b/apps/dokploy/components/dashboard/application/general/generic/save-bitbucket-provider.tsx @@ -202,7 +202,6 @@ export const SaveBitbucketProvider = ({ applicationId }: Props) => {