From b9ab4a4d1a64483a25f475c1018431c65111f990 Mon Sep 17 00:00:00 2001 From: Mauricio Siu <47042324+Siumauricio@users.noreply.github.com> Date: Sat, 8 Jun 2024 16:42:50 -0600 Subject: [PATCH] refactor: remove console log --- server/api/services/docker.ts | 16 ++------ server/api/services/project.ts | 9 ----- server/utils/builders/index.ts | 1 - server/utils/providers/docker.ts | 68 ++++++++++++++++---------------- 4 files changed, 38 insertions(+), 56 deletions(-) diff --git a/server/api/services/docker.ts b/server/api/services/docker.ts index 57f60c36..8c951e8d 100644 --- a/server/api/services/docker.ts +++ b/server/api/services/docker.ts @@ -46,9 +46,7 @@ export const getContainers = async () => { .filter((container) => !container.name.includes("dokploy")); return containers; - } catch (error) { - console.error(`Execution error: ${error}`); - } + } catch (error) {} }; export const getConfig = async (containerId: string) => { @@ -65,9 +63,7 @@ export const getConfig = async (containerId: string) => { const config = JSON.parse(stdout); return config; - } catch (error) { - console.error(`Execution error: ${error}`); - } + } catch (error) {} }; export const getContainersByAppNameMatch = async (appName: string) => { @@ -103,9 +99,7 @@ export const getContainersByAppNameMatch = async (appName: string) => { }); return containers || []; - } catch (error) { - console.error(`Execution error: ${error}`); - } + } catch (error) {} return []; }; @@ -144,9 +138,7 @@ export const getContainersByAppLabel = async (appName: string) => { }); return containers || []; - } catch (error) { - console.error(`Execution error: ${error}`); - } + } catch (error) {} return []; }; diff --git a/server/api/services/project.ts b/server/api/services/project.ts index 2ed1244c..56aecce5 100644 --- a/server/api/services/project.ts +++ b/server/api/services/project.ts @@ -121,12 +121,3 @@ export const validUniqueServerAppName = async (appName: string) => { return nonEmptyProjects.length === 0; }; -export const slugifyProjectName = (projectName: string): string => { - return projectName - .toLowerCase() - .replace(/[0-9]/g, "") - .replace(/[^a-z\s-]/g, "") - .replace(/\s+/g, "-") - .replace(/-+/g, "-") - .replace(/^-+|-+$/g, ""); -}; diff --git a/server/utils/builders/index.ts b/server/utils/builders/index.ts index e67ad9be..ce8cad39 100644 --- a/server/utils/builders/index.ts +++ b/server/utils/builders/index.ts @@ -148,7 +148,6 @@ export const mechanizeDockerContainer = async ( }, }); } catch (error) { - console.log(error); await docker.createService(settings); } }; diff --git a/server/utils/providers/docker.ts b/server/utils/providers/docker.ts index 997648d1..c77a6721 100644 --- a/server/utils/providers/docker.ts +++ b/server/utils/providers/docker.ts @@ -3,47 +3,47 @@ import { type ApplicationNested, mechanizeDockerContainer } from "../builders"; import { pullImage } from "../docker/utils"; interface RegistryAuth { - username: string; - password: string; - serveraddress: string; + username: string; + password: string; + serveraddress: string; } export const buildDocker = async ( - application: ApplicationNested, - logPath: string, + application: ApplicationNested, + logPath: string, ): Promise => { - const { buildType, dockerImage, username, password } = application; - const authConfig: Partial = { - username: username || "", - password: password || "", - }; + const { buildType, dockerImage, username, password } = application; + const authConfig: Partial = { + username: username || "", + password: password || "", + }; - const writeStream = createWriteStream(logPath, { flags: "a" }); + const writeStream = createWriteStream(logPath, { flags: "a" }); - writeStream.write(`\nBuild ${buildType}\n`); + writeStream.write(`\nBuild ${buildType}\n`); - writeStream.write(`Pulling ${dockerImage}: ✅\n`); + writeStream.write(`Pulling ${dockerImage}: ✅\n`); - try { - if (!dockerImage) { - throw new Error("Docker image not found"); - } + try { + if (!dockerImage) { + throw new Error("Docker image not found"); + } - await pullImage( - dockerImage, - (data) => { - if (writeStream.writable) { - writeStream.write(`${data.status}\n`); - } - }, - authConfig, - ); - await mechanizeDockerContainer(application); - writeStream.write("\nDocker Deployed: ✅\n"); - } catch (error) { - writeStream.write(`ERROR: ${error}: ❌`); - throw error; - } finally { - writeStream.end(); - } + await pullImage( + dockerImage, + (data) => { + if (writeStream.writable) { + writeStream.write(`${data.status}\n`); + } + }, + authConfig, + ); + await mechanizeDockerContainer(application); + writeStream.write("\nDocker Deployed: ✅\n"); + } catch (error) { + writeStream.write(`ERROR: ${error}: ❌`); + throw error; + } finally { + writeStream.end(); + } };