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) => {
});
emptyCustomCodeDatabase();
// clearDocker();
const server = http.createServer(app);
......
......@@ -366,5 +366,4 @@ module.exports = {
pauseDockerContainer,
unpauseDockerContainer,
dockerCleanUp,
killDockerContainer,
};
......@@ -51,10 +51,8 @@ const addCustomCodeToJson = async (newElement) => {
const dataFilePath = path.resolve(__dirname, "../../customCodeDatabase.json");
try {
const data = await fs.readFile(dataFilePath, "utf-8");
let jsonArray;
jsonArray = JSON.parse(data);
const existingFilter = jsonArray.find(
const customCodes = await getCustomCodes();
const existingFilter = customCodes.find(
(element) => element.id === newElement.id
);
if (existingFilter) {
......@@ -64,12 +62,12 @@ const addCustomCodeToJson = async (newElement) => {
existingFilter.code = newElement.code;
existingFilter.isDeployed = false;
} else {
jsonArray.push(newElement);
customCodes.push(newElement);
}
await fs.writeFile(
dataFilePath,
JSON.stringify(jsonArray, null, 2),
JSON.stringify(customCodes, null, 2),
"utf8"
);
console.log("Neues Element erfolgreich hinzugefügt.");
......@@ -82,14 +80,12 @@ const addCustomCodeToJson = async (newElement) => {
const setIsDeployed = async (id) => {
const dataFilePath = path.resolve(__dirname, "../../customCodeDatabase.json");
try {
const data = await fs.readFile(dataFilePath, "utf-8");
let jsonArray;
jsonArray = JSON.parse(data);
let elementToChange = jsonArray.find((element) => element.id === id);
const customCodes = await getCustomCodes();
let elementToChange = customCodes.find((element) => element.id === id);
elementToChange.isDeployed = true;
await fs.writeFile(
dataFilePath,
JSON.stringify(jsonArray, null, 2),
JSON.stringify(customCodes, null, 2),
"utf8"
);
} catch (err) {
......@@ -157,10 +153,26 @@ const restartArchitecture = async () => {
await deployArchitecture();
};
const clearDocker = () => {
// Docker Container
// Docker Files
// Docker Network
const clearArchitecture = async () => {
try {
const dataFilePath = path.resolve(
__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 = {
......@@ -170,7 +182,7 @@ module.exports = {
addCustomCodeToJson,
getCustomCodes,
deployArchitecture,
clearDocker,
clearArchitecture,
stopArchitecture,
restartArchitecture,
};
......@@ -3,8 +3,8 @@ const {
deployArchitecture,
stopArchitecture,
restartArchitecture,
clearArchitecture,
} = require("../functions/helperFunctions");
const { dockerCleanUp } = require("../docker/dockerManager");
const deployRouter = express.Router();
......@@ -38,9 +38,9 @@ deployRouter.post("/restart", async (req, res) => {
}
});
deployRouter.get("/clearDocker", async (rey, res) => {
deployRouter.get("/clearArchitecture", async (rey, res) => {
try {
await dockerCleanUp();
await clearArchitecture();
res.status(200).json({ message: "Docker leeren erfoglreich" });
} catch (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