Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,14 @@ cd veren

We assume you have already gone through the required configuration and added the necessary files as described in [@essentials](https://github.com/atithi4dev/veren/blob/main/Docs/GITHUB_SETUP.md) before starting the project.


**Start the services using Docker Compose:**
```bash
docker compose up --build
docker compose -f docker-compose.dev.yml up --build
```
Now you are ready to visit [api-guidelines](https://github.com/atithi4dev/veren/blob/main/Docs/API_DOCUMENTATION.md) to access the differnt routes and supported features.
> **Note:** The default command `docker compose up --build` will fail because there is no root-level `docker-compose.yml`. Make sure to specify the correct file as above.

Now you are ready to visit [api-guidelines](https://github.com/atithi4dev/veren/blob/main/Docs/API_DOCUMENTATION.md) to access the different routes and supported features.

## Architecture Overview -

Expand Down
6 changes: 6 additions & 0 deletions api-gateway/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
testMatch: ['**/tests/**/*.test.ts'],
moduleFileExtensions: ['ts', 'js', 'json', 'node'],
};
6 changes: 6 additions & 0 deletions api-gateway/jest.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export default {
preset: 'ts-jest',
testEnvironment: 'node',
testMatch: ['**/tests/**/*.test.ts'],
moduleFileExtensions: ['ts', 'js', 'json', 'node'],
};
12 changes: 11 additions & 1 deletion api-gateway/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"type": "module",
"scripts": {
"build": "tsc",
"start": "node dist/index.js"
"start": "node dist/index.js",
"test": "jest --config jest.config.mjs"
},
"dependencies": {
"@aws-sdk/client-ecr": "^3.987.0",
Expand Down Expand Up @@ -35,19 +36,28 @@
"nanoid": "^5.1.6",
"node-fetch": "^3.3.2",
"pg": "^8.16.3",
"swagger-jsdoc": "^6.2.8",
"swagger-ui-express": "^5.0.1",
"winston": "^3.17.0"
},
"devDependencies": {
"@types/cookie-parser": "^1.4.9",
"@types/cors": "^2.8.19",
"@types/express": "^4.17.23",
"@types/express-session": "^1.18.2",
"@types/jest": "^30.0.0",
"@types/mongoose": "^5.11.96",
"@types/morgan": "^1.9.10",
"@types/node": "^20.5.9",
"@types/node-fetch": "^2.6.13",
"@types/pg": "^8.15.5",
"@types/supertest": "^7.2.0",
"@types/swagger-jsdoc": "^6.0.4",
"@types/swagger-ui-express": "^4.1.8",
"jest": "^30.2.0",
"nodemon": "^3.1.10",
"supertest": "^7.2.2",
"ts-jest": "^29.4.6",
"ts-node": "^10.9.2",
"typescript": "^5.2.2"
}
Expand Down
4 changes: 4 additions & 0 deletions api-gateway/src/app.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@


import express from "express";
import cors from "cors";
import cookieParser from "cookie-parser";
import morganMiddleware from "./logger/indexLog.js";
import { errorHandler } from "./middlewares/error.middlewares.js";
import session from "express-session";
import MongoStore from "connect-mongo";
import swaggerUi from 'swagger-ui-express';
import swaggerJSDoc from 'swagger-jsdoc';

const app = express();

Expand Down
15 changes: 3 additions & 12 deletions api-gateway/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import app from "./app.js";
import dotenv from "dotenv";
import logger from "./logger/logger.js";
import { connectDB } from "./db/index.js";
import { pollQueue } from "./services/consumer.js";
import { startQueueWorker } from "./services/consumer.js";
import { purgeQueueOnStartup } from "./services/purgeQueue.js";

dotenv.config({ path: './.env' });
Expand All @@ -18,17 +18,8 @@ async function init() {
logger.info(`Server is running on port ${PORT}`);
});

// Start SQS polling concurrently
(async function pollLoop() {
logger.info("Polling SQS...");
while (true) {
try {
await pollQueue();
} catch (err) {
console.error("Polling error:", err);
}
}
})();
// Start BullMQ worker for backendDeployQueue
startQueueWorker();
}

init();
10 changes: 10 additions & 0 deletions api-gateway/src/routes/healthCheck.route.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
/**
* @openapi
* /api/v1/healthcheck:
* get:
* summary: Health check endpoint
* description: Returns a simple health status for the API.
* responses:
* 200:
* description: API is healthy
*/
import { Router } from "express";
import healthCheck from "../controllers/healthCheck.controller.js";

Expand Down
67 changes: 23 additions & 44 deletions api-gateway/src/services/consumer.ts
Original file line number Diff line number Diff line change
@@ -1,55 +1,34 @@
import {
SQSClient,
ReceiveMessageCommand,
DeleteMessageCommand,
} from "@aws-sdk/client-sqs";

// import { repoAnalysisSuccessHandler } from "../controllers/internalService.controller.js";

import dotenv from 'dotenv';
import { Worker } from 'bullmq';
import { Deployment, Project, publishEvent } from "@veren/domain";
import { backendDeployQueue } from "../Queue/backendDeploy-queue.js";
import ecrImageExistsCheck from "../utils/ecrCheck/ecrImageExistsCheck.js";
dotenv.config();

const sqs = new SQSClient({
region: "ap-south-1",
credentials: {
accessKeyId: process.env.AWS_ACCESS_KEY_ID!,
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY!,
},
});

const QUEUE_URL = process.env.SERVICE_QUEUE_URL!;

export async function pollQueue() {
const res = await sqs.send(
new ReceiveMessageCommand({
QueueUrl: QUEUE_URL,
MaxNumberOfMessages: 5,
WaitTimeSeconds: 5,
VisibilityTimeout: 60,
})
// Initialize BullMQ Worker for backendDeployQueue
export function startQueueWorker() {
const worker = new Worker(
'backendDeployQueue',
async job => {
try {
await handleEvent(job.data);
} catch (err) {
console.error("Worker job processing failed:", err);
throw err;
}
},
{
connection: backendDeployQueue.client.options.connection,
}
);

if (!res.Messages) return;

for (const msg of res.Messages) {
try {
const event = JSON.parse(msg.Body!);

await handleEvent(event);

await sqs.send(
new DeleteMessageCommand({
QueueUrl: QUEUE_URL,
ReceiptHandle: msg.ReceiptHandle!,
})
);
} catch (err) {
console.error("Processing failed:", err);
}
}
worker.on('completed', (job) => {
console.log(`Job ${job.id} has completed`);
});
worker.on('failed', (job, err) => {
console.error(`Job ${job?.id} has failed:`, err);
});
return worker;
}

async function handleEvent(event: any) {
Expand Down
9 changes: 9 additions & 0 deletions api-gateway/tests/healthcheck.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import request from 'supertest';
import app from '../src/app';

describe('Health Check API', () => {
it('should return 200 OK', async () => {
const res = await request(app).get('/api/v1/healthcheck');
expect(res.statusCode).toBe(200);
});
});
Loading