From 9a828d4966749db732053fd3dc187a6e833d208a Mon Sep 17 00:00:00 2001 From: Mauricio Siu <47042324+Siumauricio@users.noreply.github.com> Date: Thu, 19 Sep 2024 22:25:25 -0600 Subject: [PATCH] refactor(linter): format files --- apps/dokploy/__test__/drop/drop.test.test.ts | 114 +++++++++++++++--- apps/dokploy/__test__/traefik/traefik.test.ts | 1 + .../dashboard/application/general/show.tsx | 2 +- .../dashboard/project/add-template.tsx | 32 ++--- apps/dokploy/server/api/routers/compose.ts | 2 +- .../dokploy/server/api/routers/destination.ts | 2 +- apps/dokploy/server/api/routers/settings.ts | 2 +- apps/dokploy/server/setup/registry-setup.ts | 2 +- apps/dokploy/server/utils/backups/utils.ts | 2 +- .../dokploy/server/utils/databases/mariadb.ts | 2 +- apps/dokploy/server/utils/databases/mongo.ts | 2 +- apps/dokploy/server/utils/databases/mysql.ts | 2 +- .../server/utils/databases/postgres.ts | 2 +- apps/dokploy/server/utils/databases/redis.ts | 2 +- apps/dokploy/server/utils/docker/utils.ts | 6 +- 15 files changed, 128 insertions(+), 47 deletions(-) diff --git a/apps/dokploy/__test__/drop/drop.test.test.ts b/apps/dokploy/__test__/drop/drop.test.test.ts index c341eba7..c411566a 100644 --- a/apps/dokploy/__test__/drop/drop.test.test.ts +++ b/apps/dokploy/__test__/drop/drop.test.test.ts @@ -1,6 +1,8 @@ import fs from "node:fs/promises"; import path from "node:path"; import { paths } from "@/server/constants"; +const { APPLICATIONS_PATH } = paths(); +import type { ApplicationNested } from "@/server/utils/builders"; import { unzipDrop } from "@/server/utils/builders/drop"; import AdmZip from "adm-zip"; import { afterAll, beforeAll, describe, expect, it, vi } from "vitest"; @@ -10,12 +12,85 @@ if (typeof window === "undefined") { globalThis.File = undici.File as any; globalThis.FileList = undici.FileList as any; } -const { APPLICATIONS_PATH } = paths(); + +const baseApp: ApplicationNested = { + applicationId: "", + applicationStatus: "done", + appName: "", + autoDeploy: true, + serverId: "", + branch: null, + dockerBuildStage: "", + buildArgs: null, + buildPath: "/", + gitlabPathNamespace: "", + buildType: "nixpacks", + bitbucketBranch: "", + bitbucketBuildPath: "", + bitbucketId: "", + bitbucketRepository: "", + bitbucketOwner: "", + githubId: "", + gitlabProjectId: 0, + gitlabBranch: "", + gitlabBuildPath: "", + gitlabId: "", + gitlabRepository: "", + gitlabOwner: "", + command: null, + cpuLimit: null, + cpuReservation: null, + createdAt: "", + customGitBranch: "", + customGitBuildPath: "", + customGitSSHKeyId: null, + customGitUrl: "", + description: "", + dockerfile: null, + dockerImage: null, + dropBuildPath: null, + enabled: null, + env: null, + healthCheckSwarm: null, + labelsSwarm: null, + memoryLimit: null, + memoryReservation: null, + modeSwarm: null, + mounts: [], + name: "", + networkSwarm: null, + owner: null, + password: null, + placementSwarm: null, + ports: [], + projectId: "", + publishDirectory: null, + redirects: [], + refreshToken: "", + registry: null, + registryId: null, + replicas: 1, + repository: null, + restartPolicySwarm: null, + rollbackConfigSwarm: null, + security: [], + sourceType: "git", + subtitle: null, + title: null, + updateConfigSwarm: null, + username: null, + dockerContextPath: null, +}; +// vi.mock("@/server/constants", () => ({ - APPLICATIONS_PATH: "./__test__/drop/zips/output", + paths: () => ({ + APPLICATIONS_PATH: "./__test__/drop/zips/output", + }), + // APPLICATIONS_PATH: "./__test__/drop/zips/output", })); describe("unzipDrop using real zip files", () => { + // const { APPLICATIONS_PATH } = paths(); beforeAll(async () => { await fs.rm(APPLICATIONS_PATH, { recursive: true, force: true }); }); @@ -25,39 +100,42 @@ describe("unzipDrop using real zip files", () => { }); it("should correctly extract a zip with a single root folder", async () => { - const appName = "single-file"; - const outputPath = path.join(APPLICATIONS_PATH, appName, "code"); + baseApp.appName = "single-file"; + // const appName = "single-file"; + const outputPath = path.join(APPLICATIONS_PATH, baseApp.appName, "code"); const zip = new AdmZip("./__test__/drop/zips/single-file.zip"); const zipBuffer = zip.toBuffer(); const file = new File([zipBuffer], "single.zip"); - await unzipDrop(file, appName); + await unzipDrop(file, baseApp); const files = await fs.readdir(outputPath, { withFileTypes: true }); expect(files.some((f) => f.name === "test.txt")).toBe(true); }); it("should correctly extract a zip with a single root folder and a subfolder", async () => { - const appName = "folderwithfile"; - const outputPath = path.join(APPLICATIONS_PATH, appName, "code"); + baseApp.appName = "folderwithfile"; + // const appName = "folderwithfile"; + const outputPath = path.join(APPLICATIONS_PATH, baseApp.appName, "code"); const zip = new AdmZip("./__test__/drop/zips/folder-with-file.zip"); const zipBuffer = zip.toBuffer(); const file = new File([zipBuffer], "single.zip"); - await unzipDrop(file, appName); + await unzipDrop(file, baseApp); const files = await fs.readdir(outputPath, { withFileTypes: true }); expect(files.some((f) => f.name === "folder1.txt")).toBe(true); }); it("should correctly extract a zip with multiple root folders", async () => { - const appName = "two-folders"; - const outputPath = path.join(APPLICATIONS_PATH, appName, "code"); + baseApp.appName = "two-folders"; + // const appName = "two-folders"; + const outputPath = path.join(APPLICATIONS_PATH, baseApp.appName, "code"); const zip = new AdmZip("./__test__/drop/zips/two-folders.zip"); const zipBuffer = zip.toBuffer(); const file = new File([zipBuffer], "single.zip"); - await unzipDrop(file, appName); + await unzipDrop(file, baseApp); const files = await fs.readdir(outputPath, { withFileTypes: true }); @@ -66,13 +144,14 @@ describe("unzipDrop using real zip files", () => { }); it("should correctly extract a zip with a single root with a file", async () => { - const appName = "nested"; - const outputPath = path.join(APPLICATIONS_PATH, appName, "code"); + baseApp.appName = "nested"; + // const appName = "nested"; + const outputPath = path.join(APPLICATIONS_PATH, baseApp.appName, "code"); const zip = new AdmZip("./__test__/drop/zips/nested.zip"); const zipBuffer = zip.toBuffer(); const file = new File([zipBuffer], "single.zip"); - await unzipDrop(file, appName); + await unzipDrop(file, baseApp); const files = await fs.readdir(outputPath, { withFileTypes: true }); @@ -82,13 +161,14 @@ describe("unzipDrop using real zip files", () => { }); it("should correctly extract a zip with a single root with a folder", async () => { - const appName = "folder-with-sibling-file"; - const outputPath = path.join(APPLICATIONS_PATH, appName, "code"); + baseApp.appName = "folder-with-sibling-file"; + // const appName = "folder-with-sibling-file"; + const outputPath = path.join(APPLICATIONS_PATH, baseApp.appName, "code"); const zip = new AdmZip("./__test__/drop/zips/folder-with-sibling-file.zip"); const zipBuffer = zip.toBuffer(); const file = new File([zipBuffer], "single.zip"); - await unzipDrop(file, appName); + await unzipDrop(file, baseApp); const files = await fs.readdir(outputPath, { withFileTypes: true }); diff --git a/apps/dokploy/__test__/traefik/traefik.test.ts b/apps/dokploy/__test__/traefik/traefik.test.ts index 7ca9f169..222f8fd7 100644 --- a/apps/dokploy/__test__/traefik/traefik.test.ts +++ b/apps/dokploy/__test__/traefik/traefik.test.ts @@ -9,6 +9,7 @@ const baseApp: ApplicationNested = { applicationStatus: "done", appName: "", autoDeploy: true, + serverId: "", branch: null, dockerBuildStage: "", buildArgs: null, diff --git a/apps/dokploy/components/dashboard/application/general/show.tsx b/apps/dokploy/components/dashboard/application/general/show.tsx index 75b0ba33..de93309f 100644 --- a/apps/dokploy/components/dashboard/application/general/show.tsx +++ b/apps/dokploy/components/dashboard/application/general/show.tsx @@ -1,5 +1,6 @@ import { ShowBuildChooseForm } from "@/components/dashboard/application/build/show"; import { ShowProviderForm } from "@/components/dashboard/application/general/generic/show"; +import { Badge } from "@/components/ui/badge"; import { Button } from "@/components/ui/button"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { Toggle } from "@/components/ui/toggle"; @@ -13,7 +14,6 @@ import { StartApplication } from "../start-application"; import { StopApplication } from "../stop-application"; import { DeployApplication } from "./deploy-application"; import { ResetApplication } from "./reset-application"; -import { Badge } from "@/components/ui/badge"; interface Props { applicationId: string; } diff --git a/apps/dokploy/components/dashboard/project/add-template.tsx b/apps/dokploy/components/dashboard/project/add-template.tsx index 0f84316a..4122d0d6 100644 --- a/apps/dokploy/components/dashboard/project/add-template.tsx +++ b/apps/dokploy/components/dashboard/project/add-template.tsx @@ -19,6 +19,22 @@ import { CommandInput, CommandItem, } from "@/components/ui/command"; +import { + Dialog, + DialogContent, + DialogDescription, + DialogHeader, + DialogTitle, + DialogTrigger, +} from "@/components/ui/dialog"; +import { DropdownMenuItem } from "@/components/ui/dropdown-menu"; +import { Input } from "@/components/ui/input"; +import { Label } from "@/components/ui/label"; +import { + Popover, + PopoverContent, + PopoverTrigger, +} from "@/components/ui/popover"; import { Select, SelectContent, @@ -34,21 +50,6 @@ import { TooltipProvider, TooltipTrigger, } from "@/components/ui/tooltip"; -import { - Dialog, - DialogContent, - DialogDescription, - DialogHeader, - DialogTitle, - DialogTrigger, -} from "@/components/ui/dialog"; -import { DropdownMenuItem } from "@/components/ui/dropdown-menu"; -import { Input } from "@/components/ui/input"; -import { - Popover, - PopoverContent, - PopoverTrigger, -} from "@/components/ui/popover"; import { cn } from "@/lib/utils"; import { api } from "@/utils/api"; import { ScrollArea } from "@radix-ui/react-scroll-area"; @@ -65,7 +66,6 @@ import { import Link from "next/link"; import { useState } from "react"; import { toast } from "sonner"; -import { Label } from "@/components/ui/label"; interface Props { projectId: string; } diff --git a/apps/dokploy/server/api/routers/compose.ts b/apps/dokploy/server/api/routers/compose.ts index 4892bc3a..6a98f109 100644 --- a/apps/dokploy/server/api/routers/compose.ts +++ b/apps/dokploy/server/api/routers/compose.ts @@ -48,9 +48,9 @@ import { removeDeploymentsByComposeId } from "../services/deployment"; import { createDomain, findDomainsByComposeId } from "../services/domain"; import { createMount } from "../services/mount"; import { findProjectById } from "../services/project"; +import { findServerById } from "../services/server"; import { addNewService, checkServiceAccess } from "../services/user"; import { createTRPCRouter, protectedProcedure } from "../trpc"; -import { findServerById } from "../services/server"; export const composeRouter = createTRPCRouter({ create: protectedProcedure diff --git a/apps/dokploy/server/api/routers/destination.ts b/apps/dokploy/server/api/routers/destination.ts index 86b6d316..6fcfa99b 100644 --- a/apps/dokploy/server/api/routers/destination.ts +++ b/apps/dokploy/server/api/routers/destination.ts @@ -10,6 +10,7 @@ import { apiRemoveDestination, apiUpdateDestination, } from "@/server/db/schema"; +import { execAsync } from "@/server/utils/process/execAsync"; import { TRPCError } from "@trpc/server"; import { findAdmin } from "../services/admin"; import { @@ -18,7 +19,6 @@ import { removeDestinationById, updateDestinationById, } from "../services/destination"; -import { execAsync } from "@/server/utils/process/execAsync"; export const destinationRouter = createTRPCRouter({ create: adminProcedure diff --git a/apps/dokploy/server/api/routers/settings.ts b/apps/dokploy/server/api/routers/settings.ts index 30f4579f..f47edab5 100644 --- a/apps/dokploy/server/api/routers/settings.ts +++ b/apps/dokploy/server/api/routers/settings.ts @@ -1,3 +1,4 @@ +import { paths } from "@/server/constants"; import { apiAssignDomain, apiEnableDashboard, @@ -53,7 +54,6 @@ import { } from "../services/settings"; import { canAccessToTraefikFiles } from "../services/user"; import { adminProcedure, createTRPCRouter, protectedProcedure } from "../trpc"; -import { paths } from "@/server/constants"; export const settingsRouter = createTRPCRouter({ reloadServer: adminProcedure.mutation(async () => { diff --git a/apps/dokploy/server/setup/registry-setup.ts b/apps/dokploy/server/setup/registry-setup.ts index e286270a..8b18b108 100644 --- a/apps/dokploy/server/setup/registry-setup.ts +++ b/apps/dokploy/server/setup/registry-setup.ts @@ -1,6 +1,6 @@ import type { CreateServiceOptions } from "dockerode"; import { generateRandomPassword } from "../auth/random-password"; -import { paths, docker } from "../constants"; +import { docker, paths } from "../constants"; import { pullImage } from "../utils/docker/utils"; import { execAsync } from "../utils/process/execAsync"; diff --git a/apps/dokploy/server/utils/backups/utils.ts b/apps/dokploy/server/utils/backups/utils.ts index d477fce7..41ba1535 100644 --- a/apps/dokploy/server/utils/backups/utils.ts +++ b/apps/dokploy/server/utils/backups/utils.ts @@ -2,9 +2,9 @@ import type { BackupSchedule } from "@/server/api/services/backup"; import type { Destination } from "@/server/api/services/destination"; import { scheduleJob, scheduledJobs } from "node-schedule"; import { runMariadbBackup } from "./mariadb"; +import { runMongoBackup } from "./mongo"; import { runMySqlBackup } from "./mysql"; import { runPostgresBackup } from "./postgres"; -import { runMongoBackup } from "./mongo"; export const scheduleBackup = (backup: BackupSchedule) => { const { schedule, backupId, databaseType, postgres, mysql, mongo, mariadb } = diff --git a/apps/dokploy/server/utils/databases/mariadb.ts b/apps/dokploy/server/utils/databases/mariadb.ts index d0ee6f84..9465d47e 100644 --- a/apps/dokploy/server/utils/databases/mariadb.ts +++ b/apps/dokploy/server/utils/databases/mariadb.ts @@ -1,3 +1,4 @@ +import type { InferResultType } from "@/server/types/with"; import type { CreateServiceOptions } from "dockerode"; import { calculateResources, @@ -7,7 +8,6 @@ import { prepareEnvironmentVariables, } from "../docker/utils"; import { getRemoteDocker } from "../servers/remote-docker"; -import type { InferResultType } from "@/server/types/with"; export type MariadbNested = InferResultType<"mariadb", { mounts: true }>; export const buildMariadb = async (mariadb: MariadbNested) => { diff --git a/apps/dokploy/server/utils/databases/mongo.ts b/apps/dokploy/server/utils/databases/mongo.ts index 5e2e2bf5..6b02da86 100644 --- a/apps/dokploy/server/utils/databases/mongo.ts +++ b/apps/dokploy/server/utils/databases/mongo.ts @@ -1,3 +1,4 @@ +import type { InferResultType } from "@/server/types/with"; import type { CreateServiceOptions } from "dockerode"; import { calculateResources, @@ -7,7 +8,6 @@ import { prepareEnvironmentVariables, } from "../docker/utils"; import { getRemoteDocker } from "../servers/remote-docker"; -import type { InferResultType } from "@/server/types/with"; export type MongoNested = InferResultType<"mongo", { mounts: true }>; diff --git a/apps/dokploy/server/utils/databases/mysql.ts b/apps/dokploy/server/utils/databases/mysql.ts index b0619af0..3ad266b7 100644 --- a/apps/dokploy/server/utils/databases/mysql.ts +++ b/apps/dokploy/server/utils/databases/mysql.ts @@ -1,3 +1,4 @@ +import type { InferResultType } from "@/server/types/with"; import type { CreateServiceOptions } from "dockerode"; import { calculateResources, @@ -7,7 +8,6 @@ import { prepareEnvironmentVariables, } from "../docker/utils"; import { getRemoteDocker } from "../servers/remote-docker"; -import type { InferResultType } from "@/server/types/with"; export type MysqlNested = InferResultType<"mysql", { mounts: true }>; diff --git a/apps/dokploy/server/utils/databases/postgres.ts b/apps/dokploy/server/utils/databases/postgres.ts index cbd6aae8..f7984fbe 100644 --- a/apps/dokploy/server/utils/databases/postgres.ts +++ b/apps/dokploy/server/utils/databases/postgres.ts @@ -1,3 +1,4 @@ +import type { InferResultType } from "@/server/types/with"; import type { CreateServiceOptions } from "dockerode"; import { calculateResources, @@ -7,7 +8,6 @@ import { prepareEnvironmentVariables, } from "../docker/utils"; import { getRemoteDocker } from "../servers/remote-docker"; -import type { InferResultType } from "@/server/types/with"; export type PostgresNested = InferResultType<"postgres", { mounts: true }>; export const buildPostgres = async (postgres: PostgresNested) => { diff --git a/apps/dokploy/server/utils/databases/redis.ts b/apps/dokploy/server/utils/databases/redis.ts index fd1d7d5d..62d972a7 100644 --- a/apps/dokploy/server/utils/databases/redis.ts +++ b/apps/dokploy/server/utils/databases/redis.ts @@ -1,3 +1,4 @@ +import type { InferResultType } from "@/server/types/with"; import type { CreateServiceOptions } from "dockerode"; import { calculateResources, @@ -7,7 +8,6 @@ import { prepareEnvironmentVariables, } from "../docker/utils"; import { getRemoteDocker } from "../servers/remote-docker"; -import type { InferResultType } from "@/server/types/with"; export type RedisNested = InferResultType<"redis", { mounts: true }>; export const buildRedis = async (redis: RedisNested) => { diff --git a/apps/dokploy/server/utils/docker/utils.ts b/apps/dokploy/server/utils/docker/utils.ts index 1d798013..e4e8ca17 100644 --- a/apps/dokploy/server/utils/docker/utils.ts +++ b/apps/dokploy/server/utils/docker/utils.ts @@ -5,13 +5,13 @@ import { docker, paths } from "@/server/constants"; import type { ContainerInfo, ResourceRequirements } from "dockerode"; import { parse } from "dotenv"; import type { ApplicationNested } from "../builders"; -import { execAsync, execAsyncRemote } from "../process/execAsync"; -import { getRemoteDocker } from "../servers/remote-docker"; -import type { MongoNested } from "../databases/mongo"; import type { MariadbNested } from "../databases/mariadb"; +import type { MongoNested } from "../databases/mongo"; import type { MysqlNested } from "../databases/mysql"; import type { PostgresNested } from "../databases/postgres"; import type { RedisNested } from "../databases/redis"; +import { execAsync, execAsyncRemote } from "../process/execAsync"; +import { getRemoteDocker } from "../servers/remote-docker"; interface RegistryAuth { username: string;