Skip to content

Commit

Permalink
cicd
Browse files Browse the repository at this point in the history
  • Loading branch information
Kajanan02 committed Jun 11, 2024
1 parent 3c030e8 commit b946ed3
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 20 deletions.
14 changes: 11 additions & 3 deletions .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Login to Docker Hub
run: echo "${{ secrets.DOCKER_PASSWORD }}" | docker login -u "${{ secrets.DOCKER_USERNAME }}" --password-stdin

- name: Build Docker Image
run: docker build -t ${{ secrets.DOCKER_USERNAME }}/institute-management-backend .

- name: Publish Docker Image
run: docker push ${{ secrets.DOCKER_USERNAME }}/institute-management-backend:latest

Expand All @@ -24,7 +27,12 @@ jobs:
steps:
- name: Pull Docker Image
run: docker pull ${{ secrets.DOCKER_USERNAME }}/institute-management-backend:latest
- name: Delete old container
run: docker rm -f institute-management-backend

- name: Delete old container if exists
run: |
if [ $(docker ps -a -q -f name=institute-management-backend) ]; then
docker rm -f institute-management-backend
fi
- name: Run Docker Container
run: docker run -d -p 5000:5000 --name institute-management-backend -e MONGO_URI=${{ secrets.MONGO_URI }} ${{ secrets.DOCKER_USERNAME }}/institute-management-backend:latest
run: docker run -d -p 5000:5000 --name institute-management-backend -e MONGO_URI=${{ secrets.MONGO_URI }} -e NODE_ENV=production ${{ secrets.DOCKER_USERNAME }}/institute-management-backend:latest
18 changes: 9 additions & 9 deletions backend/controllers/paymentController.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@ import md5 from "crypto-js/md5";

app.get("/payment-hash", (req, res) => {

res.send(hash);
res.send("hash");
});

const payHereHash = asyncHandler(async (req, res) => {
const {amount, orderId} = req.body;
let merchantSecret = process.env.MERCHANT_SECRET;
let merchantId = process.env.MERCHANT_ID;
let hashedSecret = md5(merchantSecret).toString().toUpperCase();
let amountFormated = parseFloat( amount ).toLocaleString( 'en-us', { minimumFractionDigits : 2 } ).replaceAll(',', '');
let currency = 'LKR';
let hash = md5(merchantId + orderId + amountFormated + currency + hashedSecret).toString().toUpperCase();
// const {amount, orderId} = req.body;
// let merchantSecret = process.env.MERCHANT_SECRET;
// let merchantId = process.env.MERCHANT_ID;
// let hashedSecret = md5(merchantSecret).toString().toUpperCase();
// let amountFormated = parseFloat( amount ).toLocaleString( 'en-us', { minimumFractionDigits : 2 } ).replaceAll(',', '');
// let currency = 'LKR';
// let hash = md5(merchantId + orderId + amountFormated + currency + hashedSecret).toString().toUpperCase();

res.send(hash);
res.send("Hello");

})

Expand Down
4 changes: 3 additions & 1 deletion backend/middleware/authMiddleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ import jwt from "jsonwebtoken";
import asyncHandler from "express-async-handler";
import User from "../modals/userModal.js";

const JWT_SECRET = "secret";

const protect = asyncHandler(async (req, res, next) => {
let token = req.cookies.jwt;
console.log(token);
// console.log(token);
if (token) {
try {
const decoded = jwt.verify(token, process.env.JWT_SECRET);
const decoded = jwt.verify(token, JWT_SECRET);
console.log(decoded);
req.user = await User.findById(decoded.userId).select("-password");
next();
Expand Down
2 changes: 1 addition & 1 deletion backend/push-notification-firebase.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import admin from 'firebase-admin';
// const serviceAccount = require('./pushnotifydemo-33efb-firebase-adminsdk-m6im5-9a44a68765.json'); // Replace with the path to your service account key JSON file
import serviceAccount from "../pushnotifydemo-33efb-firebase-adminsdk-m6im5-9a44a68765.json" assert {type: "json"};

const serverKey = process.env.FIREBASE_SERVER_KEY; // Replace with your Firebase server key
// const serverKey = process.env.FIREBASE_SERVER_KEY; // Replace with your Firebase server key

admin.initializeApp({
credential: admin.credential.cert(serviceAccount)
Expand Down
10 changes: 5 additions & 5 deletions backend/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,11 @@ app.use(express.json());
app.use(cookieParser());


app.use(express.urlencoded({extended: true}))
app.get('/', (req, res) => {
res.send('Server is ready');
});

app.use(express.urlencoded({extended: true}))
app.use('/api/users', userRoutes);
app.use('/api/institute', studentRoutes);
app.use('/api/institute', marksRoutes);
Expand All @@ -45,11 +48,8 @@ app.use('/api', roomRoutes);
app.use('/api', careerRoutes);
app.use('/api', leaderBoardRoutes);
app.use(notFound);
app.use(errorHandler);

app.get('/', (req, res) => {
res.send('Server is ready');
});
app.use(errorHandler);

app.listen(port, () => {
console.log(`Server started at http://localhost:${port}`);
Expand Down
4 changes: 3 additions & 1 deletion backend/utils/generateToken.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import jwt from 'jsonwebtoken';

const JWT_SECRET = "secret";

const generateToken = (res, userId) => {
console.log(userId)
const token = jwt.sign({userId}, process.env.JWT_SECRET, {
const token = jwt.sign({userId}, JWT_SECRET, {
expiresIn: '30d'
})

Expand Down

0 comments on commit b946ed3

Please sign in to comment.