Skip to content

Commit

Permalink
fix: mark repos soft delete (#276)
Browse files Browse the repository at this point in the history
* fix:
1. mark repo as soft deleted
2. update chart version
3. try one values file.

Signed-off-by: OMPRAKASH MISHRA <[email protected]>

* fix:
1. mark repo as soft deleted
2. update chart version
3. try one values file.

Signed-off-by: OMPRAKASH MISHRA <[email protected]>

* fix:
1. mark repo as soft deleted
2. update chart version
3. try one values file.

Signed-off-by: OMPRAKASH MISHRA <[email protected]>

* try different resources.

Signed-off-by: OMPRAKASH MISHRA <[email protected]>

* single values.yaml

Signed-off-by: OMPRAKASH MISHRA <[email protected]>

* adding more logs.

Signed-off-by: OMPRAKASH MISHRA <[email protected]>

* adding more logs.

Signed-off-by: OMPRAKASH MISHRA <[email protected]>

* update to latest version

Signed-off-by: OMPRAKASH MISHRA <[email protected]>

---------

Signed-off-by: OMPRAKASH MISHRA <[email protected]>
  • Loading branch information
mishraomp authored Oct 31, 2023
1 parent 253fc98 commit 8bc385c
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 282 deletions.
34 changes: 33 additions & 1 deletion .github/workflows/pr-open.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,39 @@ jobs:
# Deploy Helm Chart
cd charts/pubcode
helm dependency update
helm upgrade --install --wait --atomic pubcode-${{ github.event.number }} --values values-pr.yaml --set-string global.repository=${{ github.repository }} --set-string api.containers[0].tag="${{ github.sha }}" --set-string frontend.containers[0].tag="${{ github.sha }}" --set-string global.secrets.emailRecipients="${{ secrets.EMAIL_RECIPIENTS }}" --set-string global.secrets.chesTokenURL="${{ secrets.CHES_TOKEN_URL }}" --set-string global.secrets.chesClientID="${{ secrets.CHES_CLIENT_ID }}" --set-string global.secrets.chesClientSecret="${{ secrets.CHES_CLIENT_SECRET }}" --set-string global.secrets.chesAPIURL="${{ secrets.CHES_API_URL }}" --set-string global.secrets.databaseAdminPassword="${{ secrets.DB_PWD }}" --set-string global.env.VITE_SCHEMA_BRANCH=${{ github.event.pull_request.head.ref }} --set-string namespace="${{ vars.oc_namespace }}" --timeout 5m .
helm upgrade --install --wait --atomic pubcode-${{ github.event.number }} \
--set-string global.repository=${{ github.repository }} \
--set-string api.containers[0].tag="${{ github.sha }}" \
--set-string api.containers[0].resources.limits.cpu="250m" \
--set-string api.containers[0].resources.limits.memory="250Mi" \
--set-string api.containers[0].resources.requests.cpu="100m" \
--set-string api.containers[0].resources.requests.memory="150Mi" \
--set api.autoscaling.minReplicas=1 \
--set api.autoscaling.maxReplicas=1 \
--set frontend.autoscaling.minReplicas=1 \
--set frontend.autoscaling.maxReplicas=1 \
--set-string frontend.containers[0].tag="${{ github.sha }}" \
--set-string frontend.containers[0].resources.limits.cpu="200m" \
--set-string frontend.containers[0].resources.limits.memory="150Mi" \
--set-string frontend.containers[0].resources.requests.cpu="100m" \
--set-string frontend.containers[0].resources.requests.memory="50Mi" \
--set-string database.containers[0].resources.limits.cpu="500m" \
--set-string database.containers[0].resources.limits.memory="450Mi" \
--set-string database.containers[0].resources.requests.cpu="100m" \
--set-string database.containers[0].resources.requests.memory="150Mi" \
--set-string database.initContainers[0].resources.limits.cpu="500m" \
--set-string database.initContainers[0].resources.limits.memory="450Mi" \
--set-string database.initContainers[0].resources.requests.cpu="100m" \
--set-string database.initContainers[0].resources.requests.memory="150Mi" \
--set-string database.pvc.size="350Mi" \
--set-string global.secrets.emailRecipients="${{ secrets.EMAIL_RECIPIENTS }}" \
--set-string global.secrets.chesTokenURL="${{ secrets.CHES_TOKEN_URL }}" \
--set-string global.secrets.chesClientID="${{ secrets.CHES_CLIENT_ID }}" \
--set-string global.secrets.chesClientSecret="${{ secrets.CHES_CLIENT_SECRET }}" \
--set-string global.secrets.chesAPIURL="${{ secrets.CHES_API_URL }}" \
--set-string global.secrets.databaseAdminPassword="${{ secrets.DB_PWD }}" \
--set-string global.env.VITE_SCHEMA_BRANCH=${{ github.event.pull_request.head.ref }} \
--set-string namespace="${{ vars.oc_namespace }}" -f values.yaml --timeout 5m .

cypress-e2e:
name: Cypress end to end test
Expand Down
4 changes: 4 additions & 0 deletions api/src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,9 @@ app.get("/", (req, res, next) => {
});
app.use(/(\/api)?/, apiRouter);
apiRouter.use("/pub-code", pubcodeRouter);
app.use((req, res, next) => {
res.status(404).send(
"<h1>Not Found.</h1>");
});

module.exports = app;
15 changes: 8 additions & 7 deletions api/src/email/ches-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class ChesService {
});
return { data, status };
} catch (e) {
console.log(SERVICE, e);
console.error(SERVICE, e);
}
}

Expand All @@ -52,7 +52,7 @@ class ChesService {
return { data, status };
}
} catch (e) {
console.log(SERVICE, e);
console.error(SERVICE, e);
}
}

Expand Down Expand Up @@ -81,7 +81,7 @@ class ChesService {
return { data, status };
}
} catch (e) {
console.log(SERVICE, e);
console.error(SERVICE, e);
}
}

Expand All @@ -100,7 +100,8 @@ class ChesService {
);
return { data, status };
} catch (e) {
console.log(SERVICE, e?.config?.data?.errors);
console.error(e);
console.error(SERVICE, e?.config?.data?.errors);
}
}

Expand All @@ -119,7 +120,7 @@ class ChesService {
);
return { data, status };
} catch (e) {
console.log(SERVICE, e);
console.error(SERVICE, e);
}
}

Expand All @@ -138,7 +139,7 @@ class ChesService {
);
return { data, status };
} catch (e) {
console.log(SERVICE, e);
console.error(SERVICE, e);
}
}

Expand Down Expand Up @@ -167,7 +168,7 @@ class ChesService {
return { data, status };
}
} catch (e) {
console.log(SERVICE, e);
console.error(SERVICE, e);
}
}

Expand Down
14 changes: 11 additions & 3 deletions api/src/routes/pubcode-router.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const express = require("express");
const router = express.Router();
const { bulkLoad, readAll, findById, health } = require("../services/pub-code-service");
const { bulkLoad, readAll, findById, health, softDeleteRepo } = require("../services/pub-code-service");

router.get("/ip/trace", (request, response) => response.send(request.ip));
router.get("/health", health);
Expand All @@ -11,8 +11,16 @@ router.post("/bulk-load", (req, res, next) => {
res.status(401).json({ message: "Unauthorized" });
}
}, bulkLoad);

/**
* This method allows for patching the objects with soft
*/
router.delete("/:repo_name", (req, res, next) => {
if (req.header("X-API-KEY") && req.header("X-API-KEY") === process.env.API_KEY) {
next();
} else {
res.status(401).json({ message: "Unauthorized" });
}
}, softDeleteRepo);
router.get("/", readAll);
router.get("/:id", findById);

module.exports = router;
18 changes: 17 additions & 1 deletion api/src/services/pub-code-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,26 @@ const health = async (req, res) => {
res.status(500).json(error);
}
};
const softDeleteRepo = async (req, res) => {
try {
let pubcodeEntityFromDB = await pubcodeEntity.findOne({ repo_name: req.params.repo_name }).exec();
if (!pubcodeEntityFromDB) {
res.status(404).json({ message: "Repo Not Found" });
} else {
await pubcodeEntity.updateOne({ _id: pubcodeEntityFromDB["_id"] }, { is_deleted: true }).exec();
pubcodeEntityFromDB = await pubcodeEntity.findOne({ repo_name: req.params.repo_name }).exec();
console.info(pubcodeEntityFromDB);
res.status(200).json({ message: "Repo Marked as soft deleted." });
}
} catch (e) {
console.error(e);
}

};
module.exports = {
bulkLoad,
readAll,
findById,
health
health,
softDeleteRepo
};
6 changes: 3 additions & 3 deletions charts/pubcode/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,18 @@ dependencies:

- name: component
condition: api.enabled
version: 0.0.11
version: 0.0.14
repository: https://bcgov.github.io/helm-service/
alias: api

- name: component
condition: frontend.enabled
version: 0.0.11
version: 0.0.14
repository: https://bcgov.github.io/helm-service/
alias: frontend

- name: component
condition: database.enabled
version: 0.0.11
version: 0.0.14
repository: https://bcgov.github.io/helm-service/
alias: database
Loading

0 comments on commit 8bc385c

Please sign in to comment.