Skip to content

Commit ed6fdb0

Browse files
committed
added githubWorkflow
1 parent 28dfc13 commit ed6fdb0

File tree

5 files changed

+103
-33
lines changed

5 files changed

+103
-33
lines changed

.github/workflows/deploy.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: Continuous Deployment (Prod) (Backend)
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
jobs:
9+
build:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
# 1️⃣ Checkout repo code
14+
- name: Checkout code
15+
uses: actions/checkout@v3
16+
17+
# 2️⃣ Set up Docker Buildx
18+
- name: Set up Docker Buildx
19+
uses: docker/setup-buildx-action@v2
20+
21+
# 3️⃣ Docker login using GitHub Secrets
22+
- name: Log in to Docker Hub
23+
uses: docker/login-action@v2
24+
with:
25+
username: ${{ secrets.DOCKER_USERNAME }}
26+
password: ${{ secrets.DOCKER_PASSWORD }}
27+
28+
# 4️⃣ Create .env file dynamically from GitHub Secrets
29+
- name: Create .env file from GitHub Secrets
30+
run: |
31+
echo "DATABASE_URL=${{ secrets.DATABASE_URL }}" >> .env
32+
echo "JWT_SECRET=${{ secrets.JWT_SECRET }}" >> .env
33+
echo "PORT=${{ secrets.PORT }}" >> .env
34+
echo "NODE_ENV=${{ secrets.NODE_ENV }}" >> .env
35+
36+
# 5️⃣ Build and push Docker image with SHA tag
37+
- name: Build and push Docker image
38+
uses: docker/build-push-action@v5
39+
with:
40+
context: .
41+
file: Dockerfile
42+
push: true
43+
tags: pratik50/receiptsnap-backend:${{ github.sha }}
44+
- run: |
45+
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/ssh_key
46+
chmod 600 ~/ssh_key
47+
ssh -o StrictHostKeyChecking=no -i ~/ssh_key ubuntu@13.235.239.130 << 'EOF'
48+
sudo docker pull pratik50/receiptsnap-backend:${{ github.sha }}
49+
sudo docker rm -f user_backend || true
50+
sudo docker run --name user_backend -d -p 8080:8080 pratik50/receiptsnap-backend:${{ github.sha }}
51+
EOF

src/modules/file/DashboardController.ts

Lines changed: 0 additions & 31 deletions
This file was deleted.

src/modules/file/getAllFiles.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { Request, Response } from "express";
2+
import prisma from "../../prismaClient/client";
3+
4+
interface AuthRequest extends Request {
5+
userId: string
6+
}
7+
8+
export const getAllFiles = async (req: Request, res: Response) => {
9+
const { userId } = req as AuthRequest;
10+
11+
try {
12+
13+
const files = await prisma.file.findMany({
14+
where: {
15+
userId,
16+
}
17+
});
18+
19+
res.status(200).json({ files, folders: [] });
20+
21+
} catch (err) {
22+
console.error("Files fetching error:", err);
23+
res.status(500).json({ message: "Could not load files" });
24+
}
25+
}

src/modules/file/getAllFolders.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { Request, Response } from "express";
2+
import prisma from "../../prismaClient/client";
3+
4+
interface AuthRequest extends Request {
5+
userId: string
6+
}
7+
8+
export const getAllFolders = async (req: Request, res: Response) => {
9+
const { userId } = req as AuthRequest;
10+
11+
try {
12+
const folders = await prisma.folders.findMany({
13+
where: { userId },
14+
orderBy: { createdAt: 'desc' }
15+
});
16+
17+
res.status(200).json({ folders, files: [] });
18+
19+
} catch (err) {
20+
console.error("Folders fetching error:", err);
21+
res.status(500).json({ message: "Could not load folders" });
22+
}
23+
}

src/routes/file.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@ import { upload } from "../utils/multer";
33
import { AuthMiddleware } from "../middlewares/auth";
44
import { deleteFile } from "../modules/file/deleteFile";
55
import { uploadFile } from "../modules/file/uploadFile";
6-
import { getDashboardContent } from "../modules/file/DashboardController";
6+
import { getAllFiles } from "../modules/file/getAllFiles";
7+
import { getAllFolders } from "../modules/file/getAllFolders";
78

89
const fileRouter = express.Router();
910

1011
fileRouter.post("/upload", AuthMiddleware, upload.single("file"), uploadFile);
11-
fileRouter.get("/dashboard", AuthMiddleware, getDashboardContent);
12+
fileRouter.get("/getAllFiles", AuthMiddleware, getAllFiles);
1213
fileRouter.delete("/:id", AuthMiddleware, deleteFile);
14+
fileRouter.get("/getAllFolders", AuthMiddleware, getAllFolders);
1315

1416
export default fileRouter

0 commit comments

Comments
 (0)