From 1961f3c1755b2b783a572cae33045d91e77247a6 Mon Sep 17 00:00:00 2001 From: Nicole Lim Date: Sun, 10 Nov 2024 17:44:34 +0800 Subject: [PATCH 1/5] Add build script --- backend/code-execution-service/Dockerfile | 14 +- backend/code-execution-service/package.json | 5 +- .../code-execution-service/{ => src}/app.ts | 2 +- .../{ => src}/server.ts | 0 backend/code-execution-service/tsconfig.json | 14 +- backend/collab-service/Dockerfile | 14 +- backend/collab-service/package.json | 3 +- backend/collab-service/src/app.ts | 2 +- .../src/middlewares/basicAccessControl.ts | 2 +- backend/collab-service/src/server.ts | 8 +- backend/collab-service/tsconfig.json | 14 +- backend/communication-service/Dockerfile | 16 +- backend/communication-service/package.json | 3 +- backend/communication-service/tsconfig.json | 14 +- backend/matching-service/Dockerfile | 14 +- backend/matching-service/package.json | 3 +- backend/matching-service/src/app.ts | 2 +- backend/matching-service/src/server.ts | 8 +- backend/matching-service/tsconfig.json | 12 +- backend/qn-history-service/Dockerfile | 14 +- backend/qn-history-service/package.json | 3 +- backend/qn-history-service/src/app.ts | 2 +- .../controllers/questionHistoryController.ts | 6 +- backend/qn-history-service/src/server.ts | 4 +- backend/qn-history-service/tsconfig.json | 26 +- backend/question-service/Dockerfile | 14 +- backend/question-service/package.json | 3 +- backend/question-service/src/app.ts | 2 +- .../src/controllers/questionController.ts | 10 +- .../src/routes/questionRoutes.ts | 4 +- backend/question-service/src/server.ts | 4 +- backend/question-service/tsconfig.json | 14 +- backend/user-service/Dockerfile | 14 +- backend/user-service/package.json | 5 +- backend/user-service/src/server.ts | 8 +- backend/user-service/tsconfig.json | 14 +- docker-compose-prod.yml | 266 ++++++++++++++++++ docker-compose-test.yml | 40 ++- docker-compose.yml | 40 ++- frontend/Dockerfile | 16 +- .../src/components/Navbar/Navbar.test.tsx | 3 + ...etailstest.tsx => ProfileDetails.test.tsx} | 0 42 files changed, 548 insertions(+), 114 deletions(-) rename backend/code-execution-service/{ => src}/app.ts (92%) rename backend/code-execution-service/{ => src}/server.ts (100%) create mode 100644 docker-compose-prod.yml rename frontend/src/components/ProfileDetails/{ProfileDetailstest.tsx => ProfileDetails.test.tsx} (100%) diff --git a/backend/code-execution-service/Dockerfile b/backend/code-execution-service/Dockerfile index 3e6037c84b..257d6f6fbb 100644 --- a/backend/code-execution-service/Dockerfile +++ b/backend/code-execution-service/Dockerfile @@ -1,4 +1,4 @@ -FROM node:20-alpine +FROM node:20-alpine AS base WORKDIR /code-execution-service @@ -10,4 +10,16 @@ COPY . . EXPOSE 3004 +# DEV + +FROM base AS dev + CMD ["npm", "run", "dev"] + +# PROD + +FROM base AS prod + +RUN npm run build + +CMD ["npm", "start"] diff --git a/backend/code-execution-service/package.json b/backend/code-execution-service/package.json index 984729f9e0..29661dde80 100644 --- a/backend/code-execution-service/package.json +++ b/backend/code-execution-service/package.json @@ -4,8 +4,9 @@ "main": "server.ts", "type": "module", "scripts": { - "start": "tsx server.ts", - "dev": "tsx watch server.ts", + "start": "tsx dist/server.js", + "dev": "tsx watch src/server.ts", + "build": "tsc", "test": "cross-env NODE_ENV=test && jest", "test:watch": "cross-env NODE_ENV=test && jest --watch", "lint": "eslint ." diff --git a/backend/code-execution-service/app.ts b/backend/code-execution-service/src/app.ts similarity index 92% rename from backend/code-execution-service/app.ts rename to backend/code-execution-service/src/app.ts index 59942f969e..16d941bd6b 100644 --- a/backend/code-execution-service/app.ts +++ b/backend/code-execution-service/src/app.ts @@ -5,7 +5,7 @@ import yaml from "yaml"; import swaggerUi from "swagger-ui-express"; import cors from "cors"; -import codeExecutionRoutes from "./src/routes/codeExecutionRoutes.ts"; +import codeExecutionRoutes from "./routes/codeExecutionRoutes"; dotenv.config(); diff --git a/backend/code-execution-service/server.ts b/backend/code-execution-service/src/server.ts similarity index 100% rename from backend/code-execution-service/server.ts rename to backend/code-execution-service/src/server.ts diff --git a/backend/code-execution-service/tsconfig.json b/backend/code-execution-service/tsconfig.json index 830b218c6e..ce40ce2979 100644 --- a/backend/code-execution-service/tsconfig.json +++ b/backend/code-execution-service/tsconfig.json @@ -11,7 +11,7 @@ // "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */ /* Language and Environment */ - "target": "ES2017" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */, + "target": "es2016" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */, // "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */ // "jsx": "preserve", /* Specify what JSX code is generated. */ // "experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */ @@ -26,7 +26,7 @@ /* Modules */ "module": "ESNext" /* Specify what module code is generated. */, - // "rootDir": "./", /* Specify the root folder within your source files. */ + "rootDir": "./src" /* Specify the root folder within your source files. */, "moduleResolution": "Node" /* Specify how TypeScript looks up a file from a given module specifier. */, // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */ // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */ @@ -35,7 +35,7 @@ // "types": [], /* Specify type package names to be included without being referenced in a source file. */ // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ // "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */ - "allowImportingTsExtensions": true /* Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. */, + // "allowImportingTsExtensions": true /* Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. */, // "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */ // "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */ // "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */ @@ -55,9 +55,9 @@ // "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */ // "sourceMap": true, /* Create source map files for emitted JavaScript files. */ // "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */ - "noEmit": true /* Disable emitting files from a compilation. */, + // "noEmit": true, /* Disable emitting files from a compilation. */ // "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */ - // "outDir": "./", /* Specify an output folder for all emitted files. */ + "outDir": "./dist" /* Specify an output folder for all emitted files. */, // "removeComments": true, /* Disable emitting comments. */ // "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */ // "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */ @@ -106,5 +106,7 @@ /* Completeness */ // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */ "skipLibCheck": true /* Skip type checking all .d.ts files. */ - } + }, + "include": ["src/**/*"], + "exclude": ["node_modules", "dist"] } diff --git a/backend/collab-service/Dockerfile b/backend/collab-service/Dockerfile index 9f34638d16..b632086800 100644 --- a/backend/collab-service/Dockerfile +++ b/backend/collab-service/Dockerfile @@ -1,4 +1,4 @@ -FROM node:20-alpine +FROM node:20-alpine AS base WORKDIR /collab-service @@ -10,4 +10,16 @@ COPY . . EXPOSE 3003 +# DEV + +FROM base AS dev + CMD ["npm", "run", "dev"] + +# PROD + +FROM base AS prod + +RUN npm run build + +CMD ["npm", "start"] diff --git a/backend/collab-service/package.json b/backend/collab-service/package.json index 5529171a82..48960907f5 100644 --- a/backend/collab-service/package.json +++ b/backend/collab-service/package.json @@ -4,8 +4,9 @@ "main": "server.ts", "type": "module", "scripts": { - "start": "tsx src/server.ts", + "start": "tsx src/server.js", "dev": "tsx watch src/server.ts", + "build": "tsc", "test": "cross-env NODE_ENV=test && jest", "test:watch": "cross-env NODE_ENV=test && jest --watch", "lint": "eslint ." diff --git a/backend/collab-service/src/app.ts b/backend/collab-service/src/app.ts index 9aaff3af65..d42956da58 100644 --- a/backend/collab-service/src/app.ts +++ b/backend/collab-service/src/app.ts @@ -5,7 +5,7 @@ import yaml from "yaml"; import swaggerUi from "swagger-ui-express"; import cors from "cors"; -import collabRoutes from "./routes/collabRoutes.ts"; +import collabRoutes from "./routes/collabRoutes"; dotenv.config(); diff --git a/backend/collab-service/src/middlewares/basicAccessControl.ts b/backend/collab-service/src/middlewares/basicAccessControl.ts index 727ee6783e..15088e9a86 100644 --- a/backend/collab-service/src/middlewares/basicAccessControl.ts +++ b/backend/collab-service/src/middlewares/basicAccessControl.ts @@ -1,5 +1,5 @@ import { ExtendedError, Socket } from "socket.io"; -import { verifyToken } from "../api/userService.ts"; +import { verifyToken } from "../api/userService"; export const verifyUserToken = ( socket: Socket, diff --git a/backend/collab-service/src/server.ts b/backend/collab-service/src/server.ts index 1a00c9c42c..0730768241 100644 --- a/backend/collab-service/src/server.ts +++ b/backend/collab-service/src/server.ts @@ -1,9 +1,9 @@ import http from "http"; -import app, { allowedOrigins } from "./app.ts"; -import { handleWebsocketCollabEvents } from "./handlers/websocketHandler.ts"; +import app, { allowedOrigins } from "./app"; +import { handleWebsocketCollabEvents } from "./handlers/websocketHandler"; import { Server, Socket } from "socket.io"; -import { connectRedis } from "./config/redis.ts"; -import { verifyUserToken } from "./middlewares/basicAccessControl.ts"; +import { connectRedis } from "./config/redis"; +import { verifyUserToken } from "./middlewares/basicAccessControl"; const server = http.createServer(app); diff --git a/backend/collab-service/tsconfig.json b/backend/collab-service/tsconfig.json index 830b218c6e..ce40ce2979 100644 --- a/backend/collab-service/tsconfig.json +++ b/backend/collab-service/tsconfig.json @@ -11,7 +11,7 @@ // "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */ /* Language and Environment */ - "target": "ES2017" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */, + "target": "es2016" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */, // "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */ // "jsx": "preserve", /* Specify what JSX code is generated. */ // "experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */ @@ -26,7 +26,7 @@ /* Modules */ "module": "ESNext" /* Specify what module code is generated. */, - // "rootDir": "./", /* Specify the root folder within your source files. */ + "rootDir": "./src" /* Specify the root folder within your source files. */, "moduleResolution": "Node" /* Specify how TypeScript looks up a file from a given module specifier. */, // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */ // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */ @@ -35,7 +35,7 @@ // "types": [], /* Specify type package names to be included without being referenced in a source file. */ // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ // "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */ - "allowImportingTsExtensions": true /* Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. */, + // "allowImportingTsExtensions": true /* Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. */, // "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */ // "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */ // "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */ @@ -55,9 +55,9 @@ // "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */ // "sourceMap": true, /* Create source map files for emitted JavaScript files. */ // "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */ - "noEmit": true /* Disable emitting files from a compilation. */, + // "noEmit": true, /* Disable emitting files from a compilation. */ // "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */ - // "outDir": "./", /* Specify an output folder for all emitted files. */ + "outDir": "./dist" /* Specify an output folder for all emitted files. */, // "removeComments": true, /* Disable emitting comments. */ // "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */ // "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */ @@ -106,5 +106,7 @@ /* Completeness */ // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */ "skipLibCheck": true /* Skip type checking all .d.ts files. */ - } + }, + "include": ["src/**/*"], + "exclude": ["node_modules", "dist"] } diff --git a/backend/communication-service/Dockerfile b/backend/communication-service/Dockerfile index e38cd4dca4..a52d6a4e1b 100644 --- a/backend/communication-service/Dockerfile +++ b/backend/communication-service/Dockerfile @@ -1,4 +1,4 @@ -FROM node:20-alpine +FROM node:20-alpine AS base WORKDIR /communication-service @@ -10,4 +10,16 @@ COPY . . EXPOSE 3005 -CMD ["npm", "run", "dev"] \ No newline at end of file +# DEV + +FROM base AS dev + +CMD ["npm", "run", "dev"] + +# PROD + +FROM base AS prod + +RUN npm run build + +CMD ["npm", "start"] \ No newline at end of file diff --git a/backend/communication-service/package.json b/backend/communication-service/package.json index 08fcfb3a6b..322a5b23a4 100644 --- a/backend/communication-service/package.json +++ b/backend/communication-service/package.json @@ -4,8 +4,9 @@ "main": "server.ts", "type": "module", "scripts": { - "start": "tsx src/server.ts", + "start": "tsx src/server.js", "dev": "tsx watch src/server.ts", + "build": "tsc", "test": "cross-env NODE_ENV=test && jest", "test:watch": "cross-env NODE_ENV=test && jest --watch", "lint": "eslint ." diff --git a/backend/communication-service/tsconfig.json b/backend/communication-service/tsconfig.json index 34059b779a..ce40ce2979 100644 --- a/backend/communication-service/tsconfig.json +++ b/backend/communication-service/tsconfig.json @@ -11,7 +11,7 @@ // "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */ /* Language and Environment */ - "target": "es2017" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */, + "target": "es2016" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */, // "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */ // "jsx": "preserve", /* Specify what JSX code is generated. */ // "experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */ @@ -26,7 +26,7 @@ /* Modules */ "module": "ESNext" /* Specify what module code is generated. */, - // "rootDir": "./", /* Specify the root folder within your source files. */ + "rootDir": "./src" /* Specify the root folder within your source files. */, "moduleResolution": "Node" /* Specify how TypeScript looks up a file from a given module specifier. */, // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */ // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */ @@ -35,7 +35,7 @@ // "types": [], /* Specify type package names to be included without being referenced in a source file. */ // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ // "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */ - "allowImportingTsExtensions": true /* Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. */, + // "allowImportingTsExtensions": true /* Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. */, // "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */ // "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */ // "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */ @@ -55,9 +55,9 @@ // "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */ // "sourceMap": true, /* Create source map files for emitted JavaScript files. */ // "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */ - "noEmit": true /* Disable emitting files from a compilation. */, + // "noEmit": true, /* Disable emitting files from a compilation. */ // "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */ - // "outDir": "./", /* Specify an output folder for all emitted files. */ + "outDir": "./dist" /* Specify an output folder for all emitted files. */, // "removeComments": true, /* Disable emitting comments. */ // "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */ // "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */ @@ -106,5 +106,7 @@ /* Completeness */ // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */ "skipLibCheck": true /* Skip type checking all .d.ts files. */ - } + }, + "include": ["src/**/*"], + "exclude": ["node_modules", "dist"] } diff --git a/backend/matching-service/Dockerfile b/backend/matching-service/Dockerfile index 55b971d60b..9666970ca2 100644 --- a/backend/matching-service/Dockerfile +++ b/backend/matching-service/Dockerfile @@ -1,4 +1,4 @@ -FROM node:20-alpine +FROM node:20-alpine AS base WORKDIR /matching-service @@ -10,4 +10,16 @@ COPY . . EXPOSE 3002 +# DEV + +FROM base AS dev + CMD ["npm", "run", "dev"] + +# PROD + +FROM base AS prod + +RUN npm run build + +CMD ["npm", "start"] diff --git a/backend/matching-service/package.json b/backend/matching-service/package.json index 7b681d8bfe..93685e7420 100644 --- a/backend/matching-service/package.json +++ b/backend/matching-service/package.json @@ -4,8 +4,9 @@ "main": "server.ts", "type": "module", "scripts": { - "start": "tsx src/server.ts", + "start": "tsx dist/server.js", "dev": "tsx watch src/server.ts", + "build": "tsc", "test": "cross-env NODE_ENV=test && jest", "test:watch": "cross-env NODE_ENV=test && jest --watch", "lint": "eslint ." diff --git a/backend/matching-service/src/app.ts b/backend/matching-service/src/app.ts index 8eb5924f6b..134f551ab0 100644 --- a/backend/matching-service/src/app.ts +++ b/backend/matching-service/src/app.ts @@ -5,7 +5,7 @@ import yaml from "yaml"; import fs from "fs"; import cors from "cors"; -import matchingRoutes from "./routes/matchingRoutes.ts"; +import matchingRoutes from "./routes/matchingRoutes"; dotenv.config(); diff --git a/backend/matching-service/src/server.ts b/backend/matching-service/src/server.ts index beb189dc0b..a53d9fdd12 100644 --- a/backend/matching-service/src/server.ts +++ b/backend/matching-service/src/server.ts @@ -1,9 +1,9 @@ import http from "http"; -import app, { allowedOrigins } from "./app.ts"; -import { handleWebsocketMatchEvents } from "./handlers/websocketHandler.ts"; +import app, { allowedOrigins } from "./app"; +import { handleWebsocketMatchEvents } from "./handlers/websocketHandler"; import { Server } from "socket.io"; -import { connectToRabbitMq } from "./config/rabbitmq.ts"; -import { verifyUserToken } from "./middlewares/basicAccessControl.ts"; +import { connectToRabbitMq } from "./config/rabbitmq"; +import { verifyUserToken } from "./middlewares/basicAccessControl"; const server = http.createServer(app); diff --git a/backend/matching-service/tsconfig.json b/backend/matching-service/tsconfig.json index ea143d1bd8..ce40ce2979 100644 --- a/backend/matching-service/tsconfig.json +++ b/backend/matching-service/tsconfig.json @@ -26,7 +26,7 @@ /* Modules */ "module": "ESNext" /* Specify what module code is generated. */, - // "rootDir": "./", /* Specify the root folder within your source files. */ + "rootDir": "./src" /* Specify the root folder within your source files. */, "moduleResolution": "Node" /* Specify how TypeScript looks up a file from a given module specifier. */, // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */ // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */ @@ -35,7 +35,7 @@ // "types": [], /* Specify type package names to be included without being referenced in a source file. */ // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ // "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */ - "allowImportingTsExtensions": true /* Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. */, + // "allowImportingTsExtensions": true /* Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. */, // "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */ // "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */ // "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */ @@ -55,9 +55,9 @@ // "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */ // "sourceMap": true, /* Create source map files for emitted JavaScript files. */ // "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */ - "noEmit": true /* Disable emitting files from a compilation. */, + // "noEmit": true, /* Disable emitting files from a compilation. */ // "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */ - // "outDir": "./", /* Specify an output folder for all emitted files. */ + "outDir": "./dist" /* Specify an output folder for all emitted files. */, // "removeComments": true, /* Disable emitting comments. */ // "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */ // "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */ @@ -106,5 +106,7 @@ /* Completeness */ // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */ "skipLibCheck": true /* Skip type checking all .d.ts files. */ - } + }, + "include": ["src/**/*"], + "exclude": ["node_modules", "dist"] } diff --git a/backend/qn-history-service/Dockerfile b/backend/qn-history-service/Dockerfile index 269bc6c1d7..190cee47e7 100644 --- a/backend/qn-history-service/Dockerfile +++ b/backend/qn-history-service/Dockerfile @@ -1,4 +1,4 @@ -FROM node:20-alpine +FROM node:20-alpine AS base WORKDIR /qn-history-service @@ -10,4 +10,16 @@ COPY . . EXPOSE 3006 +# DEV + +FROM base AS dev + CMD ["npm", "run", "dev"] + +# PROD + +FROM base AS prod + +RUN npm run build + +CMD ["npm", "start"] diff --git a/backend/qn-history-service/package.json b/backend/qn-history-service/package.json index 6bbc94c2b9..ce050aa20b 100644 --- a/backend/qn-history-service/package.json +++ b/backend/qn-history-service/package.json @@ -4,8 +4,9 @@ "main": "server.ts", "type": "module", "scripts": { - "start": "tsx src/server.ts", + "start": "tsx dist/server.js", "dev": "tsx watch src/server.ts", + "build": "tsc", "test": "cross-env NODE_ENV=test && jest", "test:watch": "cross-env NODE_ENV=test && jest --watch", "lint": "eslint ." diff --git a/backend/qn-history-service/src/app.ts b/backend/qn-history-service/src/app.ts index 2dabadcf4f..b4004a8f14 100644 --- a/backend/qn-history-service/src/app.ts +++ b/backend/qn-history-service/src/app.ts @@ -5,7 +5,7 @@ import yaml from "yaml"; import swaggerUi from "swagger-ui-express"; import cors from "cors"; -import qnHistoryRoutes from "./routes/questionHistoryRoutes.ts"; +import qnHistoryRoutes from "./routes/questionHistoryRoutes"; dotenv.config(); diff --git a/backend/qn-history-service/src/controllers/questionHistoryController.ts b/backend/qn-history-service/src/controllers/questionHistoryController.ts index f33344179c..69e07a2ddb 100644 --- a/backend/qn-history-service/src/controllers/questionHistoryController.ts +++ b/backend/qn-history-service/src/controllers/questionHistoryController.ts @@ -1,5 +1,5 @@ import { Request, Response } from "express"; -import QnHistory, { IQnHistory } from "../models/QnHistory.ts"; +import QnHistory, { IQnHistory } from "../models/QnHistory"; import { MONGO_OBJ_ID_FORMAT, MONGO_OBJ_ID_MALFORMED_MESSAGE, @@ -10,8 +10,8 @@ import { QN_HIST_NOT_FOUND_MESSAGE, QN_HIST_RETRIEVED_MESSAGE, SERVER_ERROR_MESSAGE, -} from "../utils/constants.ts"; -import { QnHistListParams } from "../utils/types.ts"; +} from "../utils/constants"; +import { QnHistListParams } from "../utils/types"; export const createQnHistory = async ( req: Request, diff --git a/backend/qn-history-service/src/server.ts b/backend/qn-history-service/src/server.ts index e42531d31d..9b68e4f536 100644 --- a/backend/qn-history-service/src/server.ts +++ b/backend/qn-history-service/src/server.ts @@ -1,5 +1,5 @@ -import app from "./app.ts"; -import connectDB from "./config/db.ts"; +import app from "./app"; +import connectDB from "./config/db"; const PORT = process.env.SERVICE_PORT || 3006; diff --git a/backend/qn-history-service/tsconfig.json b/backend/qn-history-service/tsconfig.json index 2d10546bb3..ce40ce2979 100644 --- a/backend/qn-history-service/tsconfig.json +++ b/backend/qn-history-service/tsconfig.json @@ -11,7 +11,7 @@ // "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */ /* Language and Environment */ - "target": "es2016", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */ + "target": "es2016" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */, // "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */ // "jsx": "preserve", /* Specify what JSX code is generated. */ // "experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */ @@ -25,9 +25,9 @@ // "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */ /* Modules */ - "module": "ESNext", /* Specify what module code is generated. */ - // "rootDir": "./", /* Specify the root folder within your source files. */ - "moduleResolution": "Node", /* Specify how TypeScript looks up a file from a given module specifier. */ + "module": "ESNext" /* Specify what module code is generated. */, + "rootDir": "./src" /* Specify the root folder within your source files. */, + "moduleResolution": "Node" /* Specify how TypeScript looks up a file from a given module specifier. */, // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */ // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */ // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */ @@ -35,7 +35,7 @@ // "types": [], /* Specify type package names to be included without being referenced in a source file. */ // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ // "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */ - "allowImportingTsExtensions": true, /* Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. */ + // "allowImportingTsExtensions": true /* Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. */, // "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */ // "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */ // "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */ @@ -55,9 +55,9 @@ // "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */ // "sourceMap": true, /* Create source map files for emitted JavaScript files. */ // "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */ - "noEmit": true, /* Disable emitting files from a compilation. */ + // "noEmit": true, /* Disable emitting files from a compilation. */ // "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */ - // "outDir": "./", /* Specify an output folder for all emitted files. */ + "outDir": "./dist" /* Specify an output folder for all emitted files. */, // "removeComments": true, /* Disable emitting comments. */ // "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */ // "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */ @@ -77,12 +77,12 @@ // "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */ // "isolatedDeclarations": true, /* Require sufficient annotation on exports so other tools can trivially generate declaration files. */ // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */ - "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */ + "esModuleInterop": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */, // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */ - "forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */ + "forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */, /* Type Checking */ - "strict": true, /* Enable all strict type-checking options. */ + "strict": true /* Enable all strict type-checking options. */, // "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */ // "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */ // "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */ @@ -105,6 +105,8 @@ /* Completeness */ // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */ - "skipLibCheck": true /* Skip type checking all .d.ts files. */ - } + "skipLibCheck": true /* Skip type checking all .d.ts files. */ + }, + "include": ["src/**/*"], + "exclude": ["node_modules", "dist"] } diff --git a/backend/question-service/Dockerfile b/backend/question-service/Dockerfile index 958ead0382..22090cbcc7 100644 --- a/backend/question-service/Dockerfile +++ b/backend/question-service/Dockerfile @@ -1,4 +1,4 @@ -FROM node:20-alpine +FROM node:20-alpine AS base WORKDIR /question-service @@ -10,4 +10,16 @@ COPY . . EXPOSE 3000 +# DEV + +FROM base AS dev + CMD ["npm", "run", "dev"] + +# PROD + +FROM base AS prod + +RUN npm run build + +CMD ["npm", "start"] \ No newline at end of file diff --git a/backend/question-service/package.json b/backend/question-service/package.json index 16bd165501..2733cd2ece 100644 --- a/backend/question-service/package.json +++ b/backend/question-service/package.json @@ -5,7 +5,8 @@ "type": "module", "scripts": { "seed": "tsx src/scripts/seed.ts", - "start": "tsx src/server.ts", + "start": "tsx dist/server.js", + "build": "tsc", "dev": "tsx watch src/server.ts", "test": "cross-env NODE_ENV=test && jest", "test:watch": "cross-env NODE_ENV=test && jest --watch", diff --git a/backend/question-service/src/app.ts b/backend/question-service/src/app.ts index 86066cbe45..d8c368f7d4 100644 --- a/backend/question-service/src/app.ts +++ b/backend/question-service/src/app.ts @@ -5,7 +5,7 @@ import yaml from "yaml"; import fs from "fs"; import cors from "cors"; -import questionRoutes from "./routes/questionRoutes.ts"; +import questionRoutes from "./routes/questionRoutes"; dotenv.config(); diff --git a/backend/question-service/src/controllers/questionController.ts b/backend/question-service/src/controllers/questionController.ts index da9dab9bd6..7309ab1072 100644 --- a/backend/question-service/src/controllers/questionController.ts +++ b/backend/question-service/src/controllers/questionController.ts @@ -1,10 +1,10 @@ import { Request, Response } from "express"; -import Question, { IQuestion } from "../models/Question.ts"; +import Question, { IQuestion } from "../models/Question"; import { checkIsExistingQuestion, getFileContent, sortAlphabetically, -} from "../utils/utils.ts"; +} from "../utils/utils"; import { DUPLICATE_QUESTION_MESSAGE, QN_DESC_EXCEED_CHAR_LIMIT_MESSAGE, @@ -19,11 +19,11 @@ import { CATEGORIES_RETRIEVED_MESSAGE, MONGO_OBJ_ID_FORMAT, MONGO_OBJ_ID_MALFORMED_MESSAGE, -} from "../utils/constants.ts"; +} from "../utils/constants"; -import { upload, uploadTestcaseFiles } from "../config/multer.ts"; +import { upload, uploadTestcaseFiles } from "../config/multer"; import { uploadFileToFirebase } from "../utils/utils"; -import { QnListSearchFilterParams, RandomQnCriteria } from "../utils/types.ts"; +import { QnListSearchFilterParams, RandomQnCriteria } from "../utils/types"; const FIREBASE_TESTCASE_FILES_FOLDER_NAME = "testcaseFiles/"; diff --git a/backend/question-service/src/routes/questionRoutes.ts b/backend/question-service/src/routes/questionRoutes.ts index b2d5f1c949..35c1ac39b3 100644 --- a/backend/question-service/src/routes/questionRoutes.ts +++ b/backend/question-service/src/routes/questionRoutes.ts @@ -9,8 +9,8 @@ import { readCategories, readRandomQuestion, createFileLink, -} from "../controllers/questionController.ts"; -import { verifyAdminToken } from "../middlewares/basicAccessControl.ts"; +} from "../controllers/questionController"; +import { verifyAdminToken } from "../middlewares/basicAccessControl"; const router = express.Router(); diff --git a/backend/question-service/src/server.ts b/backend/question-service/src/server.ts index 513945f03e..704d923fdc 100644 --- a/backend/question-service/src/server.ts +++ b/backend/question-service/src/server.ts @@ -1,5 +1,5 @@ -import app from "./app.ts"; -import connectDB from "./config/db.ts"; +import app from "./app"; +import connectDB from "./config/db"; const PORT = process.env.SERVICE_PORT || 3000; diff --git a/backend/question-service/tsconfig.json b/backend/question-service/tsconfig.json index 26e7f89381..b7501d7a18 100644 --- a/backend/question-service/tsconfig.json +++ b/backend/question-service/tsconfig.json @@ -26,7 +26,7 @@ /* Modules */ "module": "ESNext" /* Specify what module code is generated. */, - // "rootDir": "./", /* Specify the root folder within your source files. */ + "rootDir": "./src" /* Specify the root folder within your source files. */, "moduleResolution": "Node" /* Specify how TypeScript looks up a file from a given module specifier. */, // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */ // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */ @@ -35,12 +35,12 @@ // "types": [], /* Specify type package names to be included without being referenced in a source file. */ // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ // "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */ - "allowImportingTsExtensions": true /* Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. */, + // "allowImportingTsExtensions": true /* Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. */, // "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */ // "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */ // "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */ // "noUncheckedSideEffectImports": true, /* Check side effect imports. */ - "resolveJsonModule": true, /* Enable importing .json files. */ + "resolveJsonModule": true /* Enable importing .json files. */, // "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */ // "noResolve": true, /* Disallow 'import's, 'require's or ''s from expanding the number of files TypeScript should add to a project. */ @@ -55,9 +55,9 @@ // "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */ // "sourceMap": true, /* Create source map files for emitted JavaScript files. */ // "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */ - "noEmit": true /* Disable emitting files from a compilation. */, + // "noEmit": true /* Disable emitting files from a compilation. */, // "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */ - // "outDir": "./", /* Specify an output folder for all emitted files. */ + "outDir": "./dist" /* Specify an output folder for all emitted files. */, // "removeComments": true, /* Disable emitting comments. */ // "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */ // "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */ @@ -106,5 +106,7 @@ /* Completeness */ // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */ "skipLibCheck": true /* Skip type checking all .d.ts files. */ - } + }, + "include": ["src/**/*"], + "exclude": ["node_modules"] } diff --git a/backend/user-service/Dockerfile b/backend/user-service/Dockerfile index 8fc18a9843..550b015a95 100644 --- a/backend/user-service/Dockerfile +++ b/backend/user-service/Dockerfile @@ -1,4 +1,4 @@ -FROM node:20-alpine +FROM node:20-alpine as base WORKDIR /user-service @@ -10,4 +10,16 @@ COPY . . EXPOSE 3001 +# DEV + +FROM base AS dev + CMD ["npm", "run", "dev"] + +# PROD + +FROM base AS prod + +RUN npm run build + +CMD ["npm", "start"] diff --git a/backend/user-service/package.json b/backend/user-service/package.json index 0cdabebd0f..aef24b7c49 100644 --- a/backend/user-service/package.json +++ b/backend/user-service/package.json @@ -5,8 +5,9 @@ "main": "app.ts", "type": "module", "scripts": { - "start": "tsx ./src/server.ts", - "dev": "tsx watch ./src/server.ts", + "start": "tsx dist/server.js", + "dev": "tsx watch src/server.ts", + "build": "tsc", "lint": "eslint .", "test": "cross-env NODE_ENV=test jest --detectOpenHandles", "test:watch": "cross-env NODE_ENV=test jest --watch --detectOpenHandles" diff --git a/backend/user-service/src/server.ts b/backend/user-service/src/server.ts index 606e155603..d838149671 100644 --- a/backend/user-service/src/server.ts +++ b/backend/user-service/src/server.ts @@ -1,9 +1,9 @@ import http from "http"; -import index from "./app.ts"; +import index from "./app"; import dotenv from "dotenv"; -import { connectToDB } from "./model/repository.ts"; -import { seedAdminAccount } from "./scripts/seed.ts"; -import { connectRedis } from "./config/redis.ts"; +import { connectToDB } from "./model/repository"; +import { seedAdminAccount } from "./scripts/seed"; +import { connectRedis } from "./config/redis"; dotenv.config(); diff --git a/backend/user-service/tsconfig.json b/backend/user-service/tsconfig.json index 34059b779a..972bb166b1 100644 --- a/backend/user-service/tsconfig.json +++ b/backend/user-service/tsconfig.json @@ -26,7 +26,7 @@ /* Modules */ "module": "ESNext" /* Specify what module code is generated. */, - // "rootDir": "./", /* Specify the root folder within your source files. */ + "rootDir": "./src" /* Specify the root folder within your source files. */, "moduleResolution": "Node" /* Specify how TypeScript looks up a file from a given module specifier. */, // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */ // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */ @@ -35,7 +35,7 @@ // "types": [], /* Specify type package names to be included without being referenced in a source file. */ // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ // "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */ - "allowImportingTsExtensions": true /* Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. */, + // "allowImportingTsExtensions": true /* Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. */, // "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */ // "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */ // "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */ @@ -53,11 +53,11 @@ // "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */ // "declarationMap": true, /* Create sourcemaps for d.ts files. */ // "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */ - // "sourceMap": true, /* Create source map files for emitted JavaScript files. */ + "sourceMap": true /* Create source map files for emitted JavaScript files. */, // "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */ - "noEmit": true /* Disable emitting files from a compilation. */, + // "noEmit": true /* Disable emitting files from a compilation. */, // "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */ - // "outDir": "./", /* Specify an output folder for all emitted files. */ + "outDir": "./dist" /* Specify an output folder for all emitted files. */, // "removeComments": true, /* Disable emitting comments. */ // "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */ // "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */ @@ -106,5 +106,7 @@ /* Completeness */ // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */ "skipLibCheck": true /* Skip type checking all .d.ts files. */ - } + }, + "exclude": ["node_modules"], + "include": ["src/**/*"] } diff --git a/docker-compose-prod.yml b/docker-compose-prod.yml new file mode 100644 index 0000000000..1e713ecc48 --- /dev/null +++ b/docker-compose-prod.yml @@ -0,0 +1,266 @@ +services: + user-service: + image: peerprep/user-service + build: + context: ./backend/user-service + dockerfile: Dockerfile + target: prod + env_file: ./backend/user-service/.env + ports: + - 3001:3001 + depends_on: + - user-service-mongo + - user-service-redis + networks: + - peerprep-network + restart: on-failure + + question-service: + image: peerprep/question-service + build: + context: ./backend/question-service + dockerfile: Dockerfile + target: prod + env_file: ./backend/question-service/.env + ports: + - 3000:3000 + depends_on: + - question-service-mongo + - user-service + networks: + - peerprep-network + restart: on-failure + + matching-service: + image: peerprep/matching-service + build: + context: ./backend/matching-service + dockerfile: Dockerfile + target: prod + env_file: ./backend/matching-service/.env + ports: + - 3002:3002 + depends_on: + rabbitmq: + condition: service_healthy + user-service: + condition: service_started + networks: + - peerprep-network + restart: on-failure + + collab-service: + image: peerprep/collab-service + build: + context: ./backend/collab-service + dockerfile: Dockerfile + target: prod + env_file: ./backend/collab-service/.env + ports: + - 3003:3003 + depends_on: + - collab-service-redis + networks: + - peerprep-network + restart: on-failure + + code-execution-service: + image: peerprep/code-execution-service + build: + context: ./backend/code-execution-service + dockerfile: Dockerfile + target: prod + env_file: ./backend/code-execution-service/.env + ports: + - 3004:3004 + networks: + - peerprep-network + restart: on-failure + + communication-service: + image: peerprep/communication-service + build: + context: ./backend/communication-service + dockerfile: Dockerfile + target: prod + env_file: ./backend/communication-service/.env + ports: + - 3005:3005 + depends_on: + - user-service + networks: + - peerprep-network + restart: on-failure + + qn-history-service: + image: peerprep/qn-history-service + build: + context: ./backend/qn-history-service + dockerfile: Dockerfile + target: prod + env_file: ./backend/qn-history-service/.env + ports: + - 3006:3006 + depends_on: + - qn-history-service-mongo + - user-service + - question-service + networks: + - peerprep-network + restart: on-failure + + # frontend: + # image: peerprep/frontend + # build: ./frontend + # ports: + # - 5173:5173 + # depends_on: + # - user-service + # # - question-service + # # - matching-service + # # - collab-service + # # - code-execution-service + # # - communication-service + # # - qn-history-service + # networks: + # - peerprep-network + # restart: on-failure + + question-service-mongo: + image: mongo + restart: always + ports: + - 27017:27017 + networks: + - peerprep-network + volumes: + - question-service-mongo-data:/data/db + env_file: + - ./backend/question-service/.env + + question-service-mongo-express: + image: mongo-express + restart: always + ports: + - 8081:8081 + networks: + - peerprep-network + depends_on: + - question-service-mongo + env_file: ./backend/question-service/.env + + user-service-mongo: + image: mongo + restart: always + ports: + - 27018:27017 + networks: + - peerprep-network + volumes: + - user-service-mongo-data:/data/db + env_file: + - ./backend/user-service/.env + + user-service-mongo-express: + image: mongo-express + restart: always + ports: + - 8082:8081 + networks: + - peerprep-network + depends_on: + - user-service-mongo + env_file: ./backend/user-service/.env + + qn-history-service-mongo: + image: mongo + restart: always + ports: + - 27019:27017 + networks: + - peerprep-network + volumes: + - qn-history-service-mongo-data:/data/db + env_file: + - ./backend/qn-history-service/.env + + qn-history-service-mongo-express: + image: mongo-express + restart: always + ports: + - 8083:8081 + networks: + - peerprep-network + depends_on: + - qn-history-service-mongo + env_file: ./backend/qn-history-service/.env + + rabbitmq: + image: rabbitmq:4.0-management + container_name: rabbitmq + restart: always + ports: + - 5672:5672 + - 15672:15672 + networks: + - peerprep-network + env_file: ./backend/matching-service/.env + healthcheck: + test: rabbitmq-diagnostics check_port_connectivity + interval: 20s + timeout: 10s + retries: 10 + + user-service-redis: + image: redis:8.0-M01 + container_name: user-service-redis + ports: + - 6379:6379 + networks: + - peerprep-network + volumes: + - user-service-redis-data:/data + healthcheck: + test: ["CMD-SHELL", "redis-cli ping | grep PONG"] + interval: 10s + timeout: 10s + retries: 10 + command: ["redis-server"] + + collab-service-redis: + image: redis:8.0-M01 + container_name: collab-service-redis + ports: + - 6380:6379 + networks: + - peerprep-network + volumes: + - collab-service-redis-data:/data + healthcheck: + test: ["CMD-SHELL", "redis-cli ping | grep PONG"] + interval: 10s + timeout: 10s + retries: 10 + command: ["redis-server"] + + redis-insight: + image: redis/redisinsight:latest + container_name: redis-insight + ports: + - 5540:5540 + networks: + - peerprep-network + volumes: + - redis-insight-data:/data + +volumes: + question-service-mongo-data: + user-service-mongo-data: + qn-history-service-mongo-data: + user-service-redis-data: + collab-service-redis-data: + redis-insight-data: + +networks: + peerprep-network: + driver: bridge diff --git a/docker-compose-test.yml b/docker-compose-test.yml index d6bbbf78a7..450447edb0 100644 --- a/docker-compose-test.yml +++ b/docker-compose-test.yml @@ -3,7 +3,10 @@ name: peerprep-test services: test-user-service: image: peerprep/user-service - build: ./backend/user-service + build: + context: ./backend/user-service + dockerfile: Dockerfile + target: dev environment: - NODE_ENV=test - SERVICE_PORT=3001 @@ -32,7 +35,10 @@ services: test-question-service: image: peerprep/question-service - build: ./backend/question-service + build: + context: ./backend/question-service + dockerfile: Dockerfile + target: dev environment: - NODE_ENV=test - SERVICE_PORT=3000 @@ -53,7 +59,10 @@ services: test-matching-service: image: peerprep/matching-service - build: ./backend/matching-service + build: + context: ./backend/matching-service + dockerfile: Dockerfile + target: dev environment: - NODE_ENV=test - SERVICE_PORT=3002 @@ -70,7 +79,10 @@ services: test-collab-service: image: peerprep/collab-service - build: ./backend/collab-service + build: + context: ./backend/collab-service + dockerfile: Dockerfile + target: dev environment: - NODE_ENV=test - SERVICE_PORT=3003 @@ -87,7 +99,10 @@ services: test-code-execution-service: image: peerprep/code-execution-service - build: ./backend/code-execution-service + build: + context: ./backend/code-execution-service + dockerfile: Dockerfile + target: dev environment: - NODE_ENV=test - SERVICE_PORT=3004 @@ -102,7 +117,10 @@ services: test-communication-service: image: peerprep/communication-service - build: ./backend/communication-service + build: + context: ./backend/communication-service + dockerfile: Dockerfile + target: dev environment: - NODE_ENV=test - SERVICE_PORT=3005 @@ -116,7 +134,10 @@ services: test-qn-history-service: image: peerprep/qn-history-service - build: ./backend/qn-history-service + build: + context: ./backend/qn-history-service + dockerfile: Dockerfile + target: dev environment: - NODE_ENV=test - SERVICE_PORT=3006 @@ -133,7 +154,10 @@ services: test-frontend: image: peerprep/frontend - build: ./frontend + build: + context: ./frontend + dockerfile: Dockerfile + target: dev networks: - peerprep-network volumes: diff --git a/docker-compose.yml b/docker-compose.yml index 1d3067ba03..ccdad14888 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,7 +1,10 @@ services: user-service: image: peerprep/user-service - build: ./backend/user-service + build: + context: ./backend/user-service + dockerfile: Dockerfile + target: dev environment: - CHOKIDAR_USEPOLLING=true env_file: ./backend/user-service/.env @@ -19,7 +22,10 @@ services: question-service: image: peerprep/question-service - build: ./backend/question-service + build: + context: ./backend/question-service + dockerfile: Dockerfile + target: dev environment: - CHOKIDAR_USEPOLLING=true env_file: ./backend/question-service/.env @@ -37,7 +43,10 @@ services: matching-service: image: peerprep/matching-service - build: ./backend/matching-service + build: + context: ./backend/matching-service + dockerfile: Dockerfile + target: dev environment: - CHOKIDAR_USEPOLLING=true env_file: ./backend/matching-service/.env @@ -57,7 +66,10 @@ services: collab-service: image: peerprep/collab-service - build: ./backend/collab-service + build: + context: ./backend/collab-service + dockerfile: Dockerfile + target: dev environment: - CHOKIDAR_USEPOLLING=true env_file: ./backend/collab-service/.env @@ -74,7 +86,10 @@ services: code-execution-service: image: peerprep/code-execution-service - build: ./backend/code-execution-service + build: + context: ./backend/code-execution-service + dockerfile: Dockerfile + target: dev environment: - CHOKIDAR_USEPOLLING=true env_file: ./backend/code-execution-service/.env @@ -89,7 +104,10 @@ services: communication-service: image: peerprep/communication-service - build: ./backend/communication-service + build: + context: ./backend/communication-service + dockerfile: Dockerfile + target: dev environment: - CHOKIDAR_USEPOLLING=true env_file: ./backend/communication-service/.env @@ -106,7 +124,10 @@ services: qn-history-service: image: peerprep/qn-history-service - build: ./backend/qn-history-service + build: + context: ./backend/qn-history-service + dockerfile: Dockerfile + target: dev environment: - CHOKIDAR_USEPOLLING=true env_file: ./backend/qn-history-service/.env @@ -125,7 +146,10 @@ services: frontend: image: peerprep/frontend - build: ./frontend + build: + context: ./frontend + dockerfile: Dockerfile + target: dev environment: - CHOKIDAR_USEPOLLING=true ports: diff --git a/frontend/Dockerfile b/frontend/Dockerfile index 7888b16163..eeadf85bd5 100644 --- a/frontend/Dockerfile +++ b/frontend/Dockerfile @@ -1,4 +1,4 @@ -FROM node:20-alpine +FROM node:20-alpine as base WORKDIR /frontend @@ -10,4 +10,16 @@ COPY . . EXPOSE 5173 -CMD ["npm", "run", "dev"] \ No newline at end of file +# DEV + +FROM base AS dev + +CMD ["npm", "run", "dev"] + +# PROD + +FROM base AS prod + +RUN npm run build + +CMD ["npm", "run", "preview"] diff --git a/frontend/src/components/Navbar/Navbar.test.tsx b/frontend/src/components/Navbar/Navbar.test.tsx index 42a7dccb93..9779ef9fd4 100644 --- a/frontend/src/components/Navbar/Navbar.test.tsx +++ b/frontend/src/components/Navbar/Navbar.test.tsx @@ -21,6 +21,7 @@ beforeEach(() => { jest.spyOn(matchHooks, "useMatch").mockImplementation(() => ({ findMatch: jest.fn(), stopMatch: () => mockUseNavigate("/home"), + getMatchId: jest.fn(), acceptMatch: jest.fn(), rematch: jest.fn(), retryMatch: jest.fn(), @@ -32,6 +33,8 @@ beforeEach(() => { partner: null, matchPending: false, loading: false, + questionId: "123", + questionTitle: "Question", })); }); diff --git a/frontend/src/components/ProfileDetails/ProfileDetailstest.tsx b/frontend/src/components/ProfileDetails/ProfileDetails.test.tsx similarity index 100% rename from frontend/src/components/ProfileDetails/ProfileDetailstest.tsx rename to frontend/src/components/ProfileDetails/ProfileDetails.test.tsx From 73b443900418032a36869e70b16e2cce7d15a576 Mon Sep 17 00:00:00 2001 From: Nicole Lim Date: Sun, 10 Nov 2024 18:06:35 +0800 Subject: [PATCH 2/5] Add build script --- .gitignore | 1 + docker-compose-prod.yml | 35 +++++++++++++++++++---------------- frontend/Dockerfile | 6 ++++-- 3 files changed, 24 insertions(+), 18 deletions(-) diff --git a/.gitignore b/.gitignore index 84f98a5642..7d862a8996 100644 --- a/.gitignore +++ b/.gitignore @@ -11,6 +11,7 @@ node_modules dist dist-ssr *.local +*.tsbuildinfo # Coverage coverage diff --git a/docker-compose-prod.yml b/docker-compose-prod.yml index 1e713ecc48..a22235fee5 100644 --- a/docker-compose-prod.yml +++ b/docker-compose-prod.yml @@ -109,22 +109,25 @@ services: - peerprep-network restart: on-failure - # frontend: - # image: peerprep/frontend - # build: ./frontend - # ports: - # - 5173:5173 - # depends_on: - # - user-service - # # - question-service - # # - matching-service - # # - collab-service - # # - code-execution-service - # # - communication-service - # # - qn-history-service - # networks: - # - peerprep-network - # restart: on-failure + frontend: + image: peerprep/frontend + build: + context: ./frontend + dockerfile: Dockerfile + target: prod + ports: + - 5173:4173 + depends_on: + - user-service + - question-service + - matching-service + - collab-service + - code-execution-service + - communication-service + - qn-history-service + networks: + - peerprep-network + restart: on-failure question-service-mongo: image: mongo diff --git a/frontend/Dockerfile b/frontend/Dockerfile index eeadf85bd5..a78b37563e 100644 --- a/frontend/Dockerfile +++ b/frontend/Dockerfile @@ -8,12 +8,12 @@ RUN npm ci COPY . . -EXPOSE 5173 - # DEV FROM base AS dev +EXPOSE 5173 + CMD ["npm", "run", "dev"] # PROD @@ -22,4 +22,6 @@ FROM base AS prod RUN npm run build +EXPOSE 4173 + CMD ["npm", "run", "preview"] From 241114f997d8218f619d11923764543d6dcfdd09 Mon Sep 17 00:00:00 2001 From: Nicole Lim Date: Sun, 10 Nov 2024 19:34:28 +0800 Subject: [PATCH 3/5] Add build step --- .github/workflows/ci.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3978637ca8..d6f20f924a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -29,6 +29,8 @@ jobs: run: npm run lint - name: Test run: docker compose -f docker-compose-test.yml run --rm test-frontend + - name: Build + run: docker compose -f docker-compose-prod.yml build frontend backend-ci: runs-on: ubuntu-latest strategy: @@ -65,3 +67,5 @@ jobs: JWT_SECRET: ${{ secrets.JWT_SECRET }} ONE_COMPILER_KEY: ${{ secrets.ONE_COMPILER_KEY }} run: docker compose -f docker-compose-test.yml run --rm test-${{ matrix.service }} + - name: Build + run: docker compose -f docker-compose-prod.yml build ${{ matrix.service }} From 52c92249c15e050980360ce5ca019afa775be993 Mon Sep 17 00:00:00 2001 From: Nicole Lim Date: Wed, 13 Nov 2024 11:28:45 +0800 Subject: [PATCH 4/5] Update dockerignore and readme --- README.md | 20 ++++++++++++++++++++ backend/code-execution-service/.dockerignore | 1 + backend/collab-service/.dockerignore | 1 + backend/communication-service/.dockerignore | 1 + backend/matching-service/.dockerignore | 1 + backend/qn-history-service/.dockerignore | 1 + backend/question-service/.dockerignore | 1 + backend/user-service/.dockerignore | 1 + frontend/.dockerignore | 1 + 9 files changed, 28 insertions(+) diff --git a/README.md b/README.md index 3414a2e46b..4575367929 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,26 @@ To stop all the services, use the following command: docker-compose down ``` +## Running in Production Mode + +1. Build all the services (without using cache). + +``` +docker-compose -f docker-compose-prod.yml build --no-cache +``` + +2. Run all the services (in detached mode). + +``` +docker-compose -f docker-compose-prod.yml up -d +``` + +To stop all the services, use the following command: + +``` +docker-compose -f docker-compose-prod.yml down +``` + ## Useful links - User Service: http://localhost:3001 diff --git a/backend/code-execution-service/.dockerignore b/backend/code-execution-service/.dockerignore index 4abc77f632..d1d5485927 100644 --- a/backend/code-execution-service/.dockerignore +++ b/backend/code-execution-service/.dockerignore @@ -3,3 +3,4 @@ node_modules tests .env* *.md +dist diff --git a/backend/collab-service/.dockerignore b/backend/collab-service/.dockerignore index 4abc77f632..d1d5485927 100644 --- a/backend/collab-service/.dockerignore +++ b/backend/collab-service/.dockerignore @@ -3,3 +3,4 @@ node_modules tests .env* *.md +dist diff --git a/backend/communication-service/.dockerignore b/backend/communication-service/.dockerignore index 4abc77f632..d1d5485927 100644 --- a/backend/communication-service/.dockerignore +++ b/backend/communication-service/.dockerignore @@ -3,3 +3,4 @@ node_modules tests .env* *.md +dist diff --git a/backend/matching-service/.dockerignore b/backend/matching-service/.dockerignore index 4abc77f632..d1d5485927 100644 --- a/backend/matching-service/.dockerignore +++ b/backend/matching-service/.dockerignore @@ -3,3 +3,4 @@ node_modules tests .env* *.md +dist diff --git a/backend/qn-history-service/.dockerignore b/backend/qn-history-service/.dockerignore index 4abc77f632..d1d5485927 100644 --- a/backend/qn-history-service/.dockerignore +++ b/backend/qn-history-service/.dockerignore @@ -3,3 +3,4 @@ node_modules tests .env* *.md +dist diff --git a/backend/question-service/.dockerignore b/backend/question-service/.dockerignore index 4abc77f632..d1d5485927 100644 --- a/backend/question-service/.dockerignore +++ b/backend/question-service/.dockerignore @@ -3,3 +3,4 @@ node_modules tests .env* *.md +dist diff --git a/backend/user-service/.dockerignore b/backend/user-service/.dockerignore index 4abc77f632..d1d5485927 100644 --- a/backend/user-service/.dockerignore +++ b/backend/user-service/.dockerignore @@ -3,3 +3,4 @@ node_modules tests .env* *.md +dist diff --git a/frontend/.dockerignore b/frontend/.dockerignore index 9b07ce379e..3f2bee0ca7 100644 --- a/frontend/.dockerignore +++ b/frontend/.dockerignore @@ -1,3 +1,4 @@ coverage node_modules *.md +dist From af35589bf0487664d32bd519f3178014020cc3fc Mon Sep 17 00:00:00 2001 From: Nicole Lim Date: Wed, 13 Nov 2024 13:37:32 +0800 Subject: [PATCH 5/5] Fix dockerfile warnings --- backend/user-service/Dockerfile | 2 +- frontend/Dockerfile | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/user-service/Dockerfile b/backend/user-service/Dockerfile index 550b015a95..5f6957c64d 100644 --- a/backend/user-service/Dockerfile +++ b/backend/user-service/Dockerfile @@ -1,4 +1,4 @@ -FROM node:20-alpine as base +FROM node:20-alpine AS base WORKDIR /user-service diff --git a/frontend/Dockerfile b/frontend/Dockerfile index a78b37563e..0a069a4194 100644 --- a/frontend/Dockerfile +++ b/frontend/Dockerfile @@ -1,4 +1,4 @@ -FROM node:20-alpine as base +FROM node:20-alpine AS base WORKDIR /frontend