refactor: remove console log

This commit is contained in:
Mauricio Siu
2024-06-08 16:42:50 -06:00
parent 83153471b8
commit b9ab4a4d1a
4 changed files with 38 additions and 56 deletions

View File

@@ -46,9 +46,7 @@ export const getContainers = async () => {
.filter((container) => !container.name.includes("dokploy")); .filter((container) => !container.name.includes("dokploy"));
return containers; return containers;
} catch (error) { } catch (error) {}
console.error(`Execution error: ${error}`);
}
}; };
export const getConfig = async (containerId: string) => { export const getConfig = async (containerId: string) => {
@@ -65,9 +63,7 @@ export const getConfig = async (containerId: string) => {
const config = JSON.parse(stdout); const config = JSON.parse(stdout);
return config; return config;
} catch (error) { } catch (error) {}
console.error(`Execution error: ${error}`);
}
}; };
export const getContainersByAppNameMatch = async (appName: string) => { export const getContainersByAppNameMatch = async (appName: string) => {
@@ -103,9 +99,7 @@ export const getContainersByAppNameMatch = async (appName: string) => {
}); });
return containers || []; return containers || [];
} catch (error) { } catch (error) {}
console.error(`Execution error: ${error}`);
}
return []; return [];
}; };
@@ -144,9 +138,7 @@ export const getContainersByAppLabel = async (appName: string) => {
}); });
return containers || []; return containers || [];
} catch (error) { } catch (error) {}
console.error(`Execution error: ${error}`);
}
return []; return [];
}; };

View File

@@ -121,12 +121,3 @@ export const validUniqueServerAppName = async (appName: string) => {
return nonEmptyProjects.length === 0; 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, "");
};

View File

@@ -148,7 +148,6 @@ export const mechanizeDockerContainer = async (
}, },
}); });
} catch (error) { } catch (error) {
console.log(error);
await docker.createService(settings); await docker.createService(settings);
} }
}; };

View File

@@ -3,47 +3,47 @@ import { type ApplicationNested, mechanizeDockerContainer } from "../builders";
import { pullImage } from "../docker/utils"; import { pullImage } from "../docker/utils";
interface RegistryAuth { interface RegistryAuth {
username: string; username: string;
password: string; password: string;
serveraddress: string; serveraddress: string;
} }
export const buildDocker = async ( export const buildDocker = async (
application: ApplicationNested, application: ApplicationNested,
logPath: string, logPath: string,
): Promise<void> => { ): Promise<void> => {
const { buildType, dockerImage, username, password } = application; const { buildType, dockerImage, username, password } = application;
const authConfig: Partial<RegistryAuth> = { const authConfig: Partial<RegistryAuth> = {
username: username || "", username: username || "",
password: password || "", 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 { try {
if (!dockerImage) { if (!dockerImage) {
throw new Error("Docker image not found"); throw new Error("Docker image not found");
} }
await pullImage( await pullImage(
dockerImage, dockerImage,
(data) => { (data) => {
if (writeStream.writable) { if (writeStream.writable) {
writeStream.write(`${data.status}\n`); writeStream.write(`${data.status}\n`);
} }
}, },
authConfig, authConfig,
); );
await mechanizeDockerContainer(application); await mechanizeDockerContainer(application);
writeStream.write("\nDocker Deployed: ✅\n"); writeStream.write("\nDocker Deployed: ✅\n");
} catch (error) { } catch (error) {
writeStream.write(`ERROR: ${error}: ❌`); writeStream.write(`ERROR: ${error}: ❌`);
throw error; throw error;
} finally { } finally {
writeStream.end(); writeStream.end();
} }
}; };