Skip to content

Commit

Permalink
Merge pull request #122 from nicolelim02/chore/build
Browse files Browse the repository at this point in the history
Add build script
  • Loading branch information
guanquann authored Nov 13, 2024
2 parents a516ac4 + af35589 commit d4009ba
Show file tree
Hide file tree
Showing 51 changed files with 582 additions and 113 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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 }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ node_modules
dist
dist-ssr
*.local
*.tsbuildinfo

# Coverage
coverage
Expand Down
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions backend/code-execution-service/.dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ node_modules
tests
.env*
*.md
dist
14 changes: 13 additions & 1 deletion backend/code-execution-service/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:20-alpine
FROM node:20-alpine AS base

WORKDIR /code-execution-service

Expand All @@ -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"]
5 changes: 3 additions & 2 deletions backend/code-execution-service/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 ."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
File renamed without changes.
14 changes: 8 additions & 6 deletions backend/code-execution-service/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand All @@ -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. */
Expand All @@ -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. */
Expand All @@ -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. */
Expand Down Expand Up @@ -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"]
}
1 change: 1 addition & 0 deletions backend/collab-service/.dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ node_modules
tests
.env*
*.md
dist
14 changes: 13 additions & 1 deletion backend/collab-service/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:20-alpine
FROM node:20-alpine AS base

WORKDIR /collab-service

Expand All @@ -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"]
3 changes: 2 additions & 1 deletion backend/collab-service/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 ."
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
8 changes: 4 additions & 4 deletions backend/collab-service/src/server.ts
Original file line number Diff line number Diff line change
@@ -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);

Expand Down
14 changes: 8 additions & 6 deletions backend/collab-service/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand All @@ -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. */
Expand All @@ -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. */
Expand All @@ -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. */
Expand Down Expand Up @@ -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"]
}
1 change: 1 addition & 0 deletions backend/communication-service/.dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ node_modules
tests
.env*
*.md
dist
16 changes: 14 additions & 2 deletions backend/communication-service/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:20-alpine
FROM node:20-alpine AS base

WORKDIR /communication-service

Expand All @@ -10,4 +10,16 @@ COPY . .

EXPOSE 3005

CMD ["npm", "run", "dev"]
# DEV

FROM base AS dev

CMD ["npm", "run", "dev"]

# PROD

FROM base AS prod

RUN npm run build

CMD ["npm", "start"]
3 changes: 2 additions & 1 deletion backend/communication-service/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 ."
Expand Down
14 changes: 8 additions & 6 deletions backend/communication-service/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand All @@ -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. */
Expand All @@ -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. */
Expand All @@ -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. */
Expand Down Expand Up @@ -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"]
}
1 change: 1 addition & 0 deletions backend/matching-service/.dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ node_modules
tests
.env*
*.md
dist
14 changes: 13 additions & 1 deletion backend/matching-service/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:20-alpine
FROM node:20-alpine AS base

WORKDIR /matching-service

Expand All @@ -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"]
3 changes: 2 additions & 1 deletion backend/matching-service/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 ."
Expand Down
8 changes: 4 additions & 4 deletions backend/matching-service/src/server.ts
Original file line number Diff line number Diff line change
@@ -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);

Expand Down
Loading

0 comments on commit d4009ba

Please sign in to comment.