diff --git a/.env b/.env new file mode 100755 index 0000000..5e4d968 --- /dev/null +++ b/.env @@ -0,0 +1,8 @@ +DATABASE_URL="postgresql://postgres:1234@db:5432/skku?schema=public" +PORT=4000 +SESSION_SECRET=ASD3FCV3XDSI5MVQWR643LKW23EQFLM +MINIO_PORT=9000 +MINIO_END_POINT=ejp-minio +MINIO_ACCESS_KEY=skku-ejs +MINIO_SECRET_KEY=12345678 +MINIO_BUCKET_NAME=test diff --git a/.gitignore b/.gitignore index 57264e0..2b34d50 100644 --- a/.gitignore +++ b/.gitignore @@ -2,7 +2,7 @@ /dist /node_modules .pnpm-store -.env + #minio config .minio.sys diff --git a/README.md b/README.md index f5aa86c..aace291 100644 --- a/README.md +++ b/README.md @@ -1,73 +1,70 @@ -

- Nest Logo -

- -[circleci-image]: https://img.shields.io/circleci/build/github/nestjs/nest/master?token=abc123def456 -[circleci-url]: https://circleci.com/gh/nestjs/nest - -

A progressive Node.js framework for building efficient and scalable server-side applications.

-

-NPM Version -Package License -NPM Downloads -CircleCI -Coverage -Discord -Backers on Open Collective -Sponsors on Open Collective - - Support us - -

- - -## Description - -[Nest](https://github.com/nestjs/nest) framework TypeScript starter repository. - -## Installation - -```bash -$ pnpm install -``` - -## Running the app - -```bash -# development -$ pnpm run start - -# watch mode -$ pnpm run start:dev - -# production mode -$ pnpm run start:prod -``` - -## Test - -```bash -# unit tests -$ pnpm run test - -# e2e tests -$ pnpm run test:e2e - -# test coverage -$ pnpm run test:cov -``` - -## Support - -Nest is an MIT-licensed open source project. It can grow thanks to the sponsors and support by the amazing backers. If you'd like to join them, please [read more here](https://docs.nestjs.com/support). - -## Stay in touch - -- Author - [Kamil MyΕ›liwiec](https://kamilmysliwiec.com) -- Website - [https://nestjs.com](https://nestjs.com/) -- Twitter - [@nestframework](https://twitter.com/nestframework) - -## License - -Nest is [MIT licensed](LICENSE). +# EJP-BE: Edged Judger Platform Backend Server 🍎 + +EJS-Be is a nestJs-based backend server that enables EJP ecosystem. In order for EJS-S and EJS-T to function properly, instructors need to deploy this server in the environment of their choice. EJS-Be operates within a Docker Engine-based container environment. + +## Table of Contents + +- [Highlights 🌟](#highlights-🌟) +- [Getting Started πŸ“š](#getting-started-πŸ“š) + - [Prerequisites](#prerequisites) + - [Installation](#installation) +- [How it Works](#HowitWorks) +- [Contributing 🀝](#contributing-🀝) +- [License πŸ“„](#license-πŸ“„) + +## Highlights 🌟 + +- **Container Based**: As long as Docker is installed, the server can be run in any environment.. +- **User adminstration System**: Granting permissions to users for repositories and problems ensures that only users with those specific permissions can access them. + +## Getting Started πŸ“š + +### Prerequisites + +- Requires Docker Engine installed + +### Installation + +1. Clone the EJP-Be repository. + ```bash + git clone https://github.com/EdgeCrafters/ejp-be.git + ``` +2. Navigate to the cloned directory and build ejs-be image. + ```bash + cd ejp-be + docker-compose -f docker-compose.prod.yml build + ``` + +### Usage + +1. run docker-compose container + ```bash + docker-compose -f docker-compose.prod.yml up -d + ``` + +default tutor authentication +id: tutor01 +password: 1234 + +default student authentication +id: student01 +password: 1234 + +## Contributing 🀝 + +We welcome contributions from the community! Feel free to fork the repository, make your changes, and submit a pull request. For more details, check out our [contribution guidelines](#). + +## License πŸ“„ + +EJP-Be is part of the EJP project and follows the same MIT license. + +## HowitWorks + +EJP-Be is composed of a total of four containers. EJP-Be, EJP-Minio, and EJP-db communicate through a dedicated container network established using docker-compose. + +1. EJP-be +2. EJP-db + EJP-db serves as a PostgreSQL-based database that stores user information, user repository details, and metadata information about problems and repositories. +3. EJP-minio + +4. EJP-minio-mc \ No newline at end of file diff --git a/builder/Dockerfile b/builder/Dockerfile index 2a38b16..d705505 100644 --- a/builder/Dockerfile +++ b/builder/Dockerfile @@ -1,24 +1,22 @@ -# USAGE `docker build -f builder/Dockerfile .` - -### BUILDER ### -FROM node:18-alpine AS builder - -COPY . /build -WORKDIR /build - -RUN npm install -g pnpm -RUN pnpm install - -RUN npx prisma generate -RUN npm run build - -EXPOSE 4000 - -### PRODUCTION ### -FROM node:18-alpine - -ENV NODE_ENV=production -COPY --from=builder /build . -COPY ./builder/entrypoint.sh . - +# USAGE `docker build -f builder/Dockerfile .` + +### BUILDER ### +FROM node:18-alpine AS builder + +COPY . /build +WORKDIR /build + +RUN npm install -g pnpm +RUN pnpm install + +RUN npx prisma generate +RUN npm run build + +### PRODUCTION ### +FROM node:18-alpine + +ENV NODE_ENV=production +COPY --from=builder /build . +COPY ./builder/entrypoint.sh . + ENTRYPOINT ["./entrypoint.sh"] \ No newline at end of file diff --git a/builder/Dockerfile.dockerignore b/builder/Dockerfile.dockerignore index 3448c95..20d9d0f 100644 --- a/builder/Dockerfile.dockerignore +++ b/builder/Dockerfile.dockerignore @@ -1,16 +1,16 @@ -* - -!src -!prisma -!package.json -!pnpm-lock.yaml -!builder/entrypoint.sh -!nest-cli.json -!tsconfig.build.json -!tsconfig.json -!.swcrc -!.npmrc - -dist -.env +* + +!src +!prisma +!package.json +!pnpm-lock.yaml +!builder/entrypoint.sh +!nest-cli.json +!tsconfig.build.json +!tsconfig.json +!.swcrc +!.npmrc + +dist +!.env .env.* \ No newline at end of file diff --git a/builder/entrypoint.sh b/builder/entrypoint.sh index 0bfc9af..c974701 100755 --- a/builder/entrypoint.sh +++ b/builder/entrypoint.sh @@ -1,3 +1,4 @@ #!/bin/sh npx prisma migrate deploy +npx prisma db seed node dist/src/main.js \ No newline at end of file diff --git a/docker-compose.prod.yml b/docker-compose.prod.yml new file mode 100644 index 0000000..17a3a50 --- /dev/null +++ b/docker-compose.prod.yml @@ -0,0 +1,45 @@ +version: '3' + +services: + server: + container_name: ejp-be + build: + dockerfile: ./builder/Dockerfile + ports: + - 4000:4000 + stdin_open: true + tty: true + depends_on: + - db + db: + container_name: ejp-db + image: postgres:14-alpine + expose: + - '5432' + environment: + POSTGRES_USER: postgres + POSTGRES_PASSWORD: 1234 + POSTGRES_DB: skku + minio: + container_name: ejp-minio + image: minio/minio + command: server /data --console-address ":9001" + expose: + - '9001' + - '9000' + environment: + MINIO_ROOT_USER: skku-ejs + MINIO_ROOT_PASSWORD: 12345678 + + mcservice: + container_name: ejp-minio-mc + image: minio/mc + restart: on-failure + depends_on: + - minio + entrypoint: > + /bin/sh -c " + /usr/bin/mc alias set myminio http://ejp-minio:9000 skku-ejs 12345678; + /usr/bin/mc mb myminio/test; + /usr/bin/mc policy set public myminio/test; + " diff --git a/package.json b/package.json index 3d2da28..c5eb3ae 100644 --- a/package.json +++ b/package.json @@ -76,6 +76,6 @@ "typescript": "^5.1.3" }, "prisma": { - "seed": "swc-node prisma/seed.ts" + "seed": "ts-node --compiler-options {\"module\":\"CommonJS\"} prisma/seed.ts" } }