Skip to content
Snippets Groups Projects
Commit e1d2ed9d authored by Robin Leber's avatar Robin Leber
Browse files

FIX: Clear Architecture

parent a915fb2d
No related branches found
No related tags found
No related merge requests found
...@@ -22,7 +22,6 @@ app.get("/", (req, res) => { ...@@ -22,7 +22,6 @@ app.get("/", (req, res) => {
}); });
emptyCustomCodeDatabase(); emptyCustomCodeDatabase();
// clearDocker();
const server = http.createServer(app); const server = http.createServer(app);
......
...@@ -366,5 +366,4 @@ module.exports = { ...@@ -366,5 +366,4 @@ module.exports = {
pauseDockerContainer, pauseDockerContainer,
unpauseDockerContainer, unpauseDockerContainer,
dockerCleanUp, dockerCleanUp,
killDockerContainer,
}; };
...@@ -51,10 +51,8 @@ const addCustomCodeToJson = async (newElement) => { ...@@ -51,10 +51,8 @@ const addCustomCodeToJson = async (newElement) => {
const dataFilePath = path.resolve(__dirname, "../../customCodeDatabase.json"); const dataFilePath = path.resolve(__dirname, "../../customCodeDatabase.json");
try { try {
const data = await fs.readFile(dataFilePath, "utf-8"); const customCodes = await getCustomCodes();
let jsonArray; const existingFilter = customCodes.find(
jsonArray = JSON.parse(data);
const existingFilter = jsonArray.find(
(element) => element.id === newElement.id (element) => element.id === newElement.id
); );
if (existingFilter) { if (existingFilter) {
...@@ -64,12 +62,12 @@ const addCustomCodeToJson = async (newElement) => { ...@@ -64,12 +62,12 @@ const addCustomCodeToJson = async (newElement) => {
existingFilter.code = newElement.code; existingFilter.code = newElement.code;
existingFilter.isDeployed = false; existingFilter.isDeployed = false;
} else { } else {
jsonArray.push(newElement); customCodes.push(newElement);
} }
await fs.writeFile( await fs.writeFile(
dataFilePath, dataFilePath,
JSON.stringify(jsonArray, null, 2), JSON.stringify(customCodes, null, 2),
"utf8" "utf8"
); );
console.log("Neues Element erfolgreich hinzugefügt."); console.log("Neues Element erfolgreich hinzugefügt.");
...@@ -82,14 +80,12 @@ const addCustomCodeToJson = async (newElement) => { ...@@ -82,14 +80,12 @@ const addCustomCodeToJson = async (newElement) => {
const setIsDeployed = async (id) => { const setIsDeployed = async (id) => {
const dataFilePath = path.resolve(__dirname, "../../customCodeDatabase.json"); const dataFilePath = path.resolve(__dirname, "../../customCodeDatabase.json");
try { try {
const data = await fs.readFile(dataFilePath, "utf-8"); const customCodes = await getCustomCodes();
let jsonArray; let elementToChange = customCodes.find((element) => element.id === id);
jsonArray = JSON.parse(data);
let elementToChange = jsonArray.find((element) => element.id === id);
elementToChange.isDeployed = true; elementToChange.isDeployed = true;
await fs.writeFile( await fs.writeFile(
dataFilePath, dataFilePath,
JSON.stringify(jsonArray, null, 2), JSON.stringify(customCodes, null, 2),
"utf8" "utf8"
); );
} catch (err) { } catch (err) {
...@@ -157,10 +153,26 @@ const restartArchitecture = async () => { ...@@ -157,10 +153,26 @@ const restartArchitecture = async () => {
await deployArchitecture(); await deployArchitecture();
}; };
const clearDocker = () => { const clearArchitecture = async () => {
// Docker Container try {
// Docker Files const dataFilePath = path.resolve(
// Docker Network __dirname,
"../../customCodeDatabase.json"
);
const customCodes = await getCustomCodes();
for (const customCode of customCodes) {
if (customCode.isDeployed) {
await killDockerContainer(customCode.id);
await removeDockerContainer(customCode.id);
await removeDockerImage(customCode.id);
}
}
await fs.writeFile(dataFilePath, "[]", "utf8");
console.log("Docker erfolgreich geleert, JSON erfolgreich geleert");
} catch (err) {
console.error(err);
throw err;
}
}; };
module.exports = { module.exports = {
...@@ -170,7 +182,7 @@ module.exports = { ...@@ -170,7 +182,7 @@ module.exports = {
addCustomCodeToJson, addCustomCodeToJson,
getCustomCodes, getCustomCodes,
deployArchitecture, deployArchitecture,
clearDocker, clearArchitecture,
stopArchitecture, stopArchitecture,
restartArchitecture, restartArchitecture,
}; };
...@@ -3,8 +3,8 @@ const { ...@@ -3,8 +3,8 @@ const {
deployArchitecture, deployArchitecture,
stopArchitecture, stopArchitecture,
restartArchitecture, restartArchitecture,
clearArchitecture,
} = require("../functions/helperFunctions"); } = require("../functions/helperFunctions");
const { dockerCleanUp } = require("../docker/dockerManager");
const deployRouter = express.Router(); const deployRouter = express.Router();
...@@ -38,9 +38,9 @@ deployRouter.post("/restart", async (req, res) => { ...@@ -38,9 +38,9 @@ deployRouter.post("/restart", async (req, res) => {
} }
}); });
deployRouter.get("/clearDocker", async (rey, res) => { deployRouter.get("/clearArchitecture", async (rey, res) => {
try { try {
await dockerCleanUp(); await clearArchitecture();
res.status(200).json({ message: "Docker leeren erfoglreich" }); res.status(200).json({ message: "Docker leeren erfoglreich" });
} catch (e) { } catch (e) {
console.error(e); console.error(e);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment