Skip to content

Commit 620b67d

Browse files
committed
Merge remote-tracking branch 'origin/main' into #156-move-rooms-to-the-past-room-list-and-change-settlestatus-automatically-when-the-participant-is-one
2 parents 11cfed9 + 356e56e commit 620b67d

File tree

121 files changed

+8122
-2360
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

121 files changed

+8122
-2360
lines changed

.env.example

+7
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,10 @@ CORS_WHITELIST=[CORS 정책에서 허용하는 도메인의 목록(e.g. ["http:/
1616
GOOGLE_APPLICATION_CREDENTIALS=[GOOGLE_APPLICATION_CREDENTIALS JSON]
1717
TEST_ACCOUNTS=[스팍스SSO로 로그인시 무조건 테스트로 로그인이 가능한 허용 아이디 목록]
1818
SLACK_REPORT_WEBHOOK_URL=[Slack 웹훅 URL들이 담긴 JSON]
19+
20+
# optional environment variables for taxiSampleGenerator
21+
SAMPLE_NUM_OF_ROOMS=[방의 개수]
22+
SAMPLE_NUM_OF_CHATS=[각 방의 채팅 개수]
23+
SAMPLE_MAXIMUM_INTERVAL_BETWEEN_CHATS=[채팅 간 최대 시간 간격(단위: 초, 실수도 가능)]
24+
SAMPLE_OCCURENCE_OF_JOIN=[새로운 채팅이 입장 메세지일 확률(0 ~ 1 사이의 값)]
25+
SAMPLE_OCCURENCE_OF_ABORT=[새로운 채팅이 퇴장 메세지일 확률(0 ~ 1 사이의 값)]

.github/workflows/push_image_ecr.yml

+26-7
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,17 @@ jobs:
2222
with:
2323
fetch-depth: 0
2424

25+
- name: Set up Docker Buildx
26+
uses: docker/setup-buildx-action@v3
27+
28+
- name: Cache Docker layers
29+
uses: actions/cache@v3
30+
with:
31+
path: /tmp/.buildx-cache
32+
key: ${{ runner.os }}-buildx-${{ github.sha }}
33+
restore-keys: |
34+
${{ runner.os }}-buildx-
35+
2536
- name: Get previous tag-version
2637
id: previous_tag
2738
uses: WyriHaximus/github-action-get-previous-tag@v1
@@ -47,15 +58,23 @@ jobs:
4758
id: login-ecr
4859
uses: aws-actions/amazon-ecr-login@v1
4960

50-
- name: Build and Push to AWS ECR
51-
id: build_image
61+
- name: Build Image and Push to AWS ECR
62+
id: build_image_and_push
63+
uses: docker/build-push-action@v5
5264
env:
5365
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
5466
IMAGE_TAG: ${{ steps.tag.outputs.tag }}
5567
ECR_REPOSITORY: taxi-back
68+
with:
69+
push: true
70+
tags: |
71+
"${{ env.ECR_REGISTRY }}/${{ env.ECR_REPOSITORY }}:${{ env.IMAGE_TAG }}"
72+
"${{ env.ECR_REGISTRY }}/${{ env.ECR_REPOSITORY }}:latest"
73+
cache-from: type=local,src=/tmp/.buildx-cache
74+
cache-to: type=local,dest=/tmp/.buildx-cache-new
75+
76+
- name: Remove old cache
5677
run: |
57-
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .
58-
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:latest .
59-
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
60-
docker push $ECR_REGISTRY/$ECR_REPOSITORY:latest
61-
echo "Push iamge : $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG and latest"
78+
rm -rf /tmp/.buildx-cache
79+
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
80+

.github/workflows/push_image_ecr_dev.yml

+25-7
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,18 @@ jobs:
2020
uses: actions/checkout@v3
2121
with:
2222
fetch-depth: 0
23-
23+
24+
- name: Set up Docker Buildx
25+
uses: docker/setup-buildx-action@v3
26+
27+
- name: Cache Docker layers
28+
uses: actions/cache@v3
29+
with:
30+
path: /tmp/.buildx-cache
31+
key: ${{ runner.os }}-buildx-${{ github.sha }}
32+
restore-keys: |
33+
${{ runner.os }}-buildx-
34+
2435
- name: Configure AWS credentials
2536
uses: aws-actions/configure-aws-credentials@v1
2637
with:
@@ -31,13 +42,20 @@ jobs:
3142
- name: Login to AWS ECR
3243
id: login-ecr
3344
uses: aws-actions/amazon-ecr-login@v1
34-
35-
- name: Build and Push to AWS ECR
36-
id: build_image
45+
46+
- name: Build Image and Push to AWS ECR
47+
id: build_image_and_push
48+
uses: docker/build-push-action@v5
3749
env:
3850
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
3951
ECR_REPOSITORY: taxi-back
52+
with:
53+
push: true
54+
tags: "${{ env.ECR_REGISTRY }}/${{ env.ECR_REPOSITORY }}:dev"
55+
cache-from: type=local,src=/tmp/.buildx-cache
56+
cache-to: type=local,dest=/tmp/.buildx-cache-new
57+
58+
- name: Remove old cache
4059
run: |
41-
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:dev .
42-
docker push $ECR_REGISTRY/$ECR_REPOSITORY:dev
43-
echo "Push iamge : $ECR_REGISTRY/$ECR_REPOSITORY:dev"
60+
rm -rf /tmp/.buildx-cache
61+
mv /tmp/.buildx-cache-new /tmp/.buildx-cache

.github/workflows/test_ci.yml

+8-24
Original file line numberDiff line numberDiff line change
@@ -12,38 +12,23 @@ jobs:
1212
strategy:
1313
matrix:
1414
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
15-
node-version: [16.x]
15+
node-version: ['18.x']
1616
mongodb-version: ['5.0']
1717
steps:
1818
- name: Start MongoDB
1919
run: sudo docker run --name mongodb -d -p 27017:27017 mongo:${{ matrix.mongodb-version }}
20-
- name: Use Node.js ${{ matrix.node-version }}
21-
uses: actions/checkout@v3
20+
- uses: actions/checkout@v3
2221
with:
2322
submodules: true
24-
- name: Install Node.js
25-
uses: actions/setup-node@v3
26-
with:
27-
node-version: 16
28-
29-
- uses: pnpm/action-setup@v2
30-
name: Install pnpm
23+
- name: Install pnpm
24+
uses: pnpm/action-setup@v2
3125
with:
3226
version: 8
33-
- id: submodule-local
34-
name: Save local version of submodule
35-
run: echo "ver=`cd sampleGenerator && git log --pretty="%h" -1 && cd ..`" >> $GITHUB_OUTPUT
36-
- id: submodule-origin
37-
name: Save origin version of submodule
38-
run: echo "ver=`cd sampleGenerator && git log origin --pretty="%h" -1 && cd ..`" >> $GITHUB_OUTPUT
39-
- name: Check submodule version
40-
if: ${{ steps.submodule-local.outputs.ver != steps.submodule-origin.outputs.ver }}
41-
uses: actions/github-script@v3
27+
- name: Install Node.js ${{ matrix.node-version }}
28+
uses: actions/setup-node@v3
4229
with:
43-
script: |
44-
core.setFailed('Please update submodule to the latest version by using \"git submodule update --remote\"')
45-
- name: Install sampleGenerator dependencies from package-lock.json
46-
run: cd sampleGenerator && pnpm i --force --frozen-lockfile && cd ..
30+
node-version: ${{ matrix.node-version }}
31+
cache: 'pnpm'
4732
- name: Install taxi-back dependencies from package-lock.json
4833
run: pnpm i --force --frozen-lockfile
4934
- name: Run unit tests
@@ -53,6 +38,5 @@ jobs:
5338
AWS_S3_BUCKET_NAME: ${{ secrets.AWS_S3_BUCKET_NAME }}
5439
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
5540
DB_PATH: ${{ secrets.DB_PATH }}
56-
FRONT_URL: ${{ secrets.FRONT_URL }}
5741
PORT: ${{ secrets.PORT }}
5842
SESSION_KEY: ${{ secrets.SESSION_KEY }}

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*.code-workspace
77
*.swp
88
/logs/*.log
9+
.vscode
910

1011
# AdminJS 관련 디렉토리
1112
.adminjs

.gitmodules

-4
This file was deleted.

.npmrc

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Force Node.js and pnpm versions according to package.json
2+
engine-strict=true

.nvmrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
v18.17.0

Dockerfile

+12-9
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
1-
FROM node:16-alpine
1+
FROM node:18-alpine
22

3-
# Copy repository
43
WORKDIR /usr/src/app
5-
COPY . .
64

7-
# Install curl (for taxi-docker)
8-
RUN apk update && apk add curl
9-
RUN npm install --global [email protected] [email protected]
5+
# Install curl(for taxi-watchtower) and pnpm
6+
RUN apk update && apk add curl && npm install --global [email protected]
107

11-
# Install requirements
12-
RUN pnpm i --force --frozen-lockfile
8+
# pnpm fetch does require only lockfile
9+
COPY pnpm-lock.yaml .
10+
11+
# Note: devDependencies are not fetched
12+
RUN pnpm fetch --prod
13+
14+
# Copy repository and install dependencies
15+
ADD . ./
16+
RUN pnpm install --offline --prod
1317

1418
# Run container
1519
EXPOSE 80
1620
ENV PORT 80
1721
CMD ["pnpm", "run", "serve"]
18-

README.md

+9-7
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@ Taxi는 KAIST 구성원들의 택시 동승 인원 모집을 위한 서비스입
99
- Notion : [Sparcs Notion Taxi page](https://www.notion.so/sparcs/Taxi-9d371e8ac5ac4f0c9b9c35869682a0eb) (Only SPARCS members can access it)
1010
- Slack : #taxi-main, #taxi-notice, #taxi-bug-report, #taxi-github-bot, #taxi-notion-bot (Only SPARCS members can access it)
1111

12-
## Prerequisites
13-
- Recommended npm version : 8.5.5 (with node v.16.15.0)
14-
- Recommended mognoDB version : 5.0.8
15-
- [Issue with node version](https://github.com/sparcs-kaist/taxi-front/issues/76)
12+
## Prerequisite
13+
14+
- Recommended node version : >=18.0.0 (Node v18.18.0, for example)
15+
- Recommended pnpm version : >=8.0.0 (pmpm v8.8.0, for example)
16+
- Recommended mongoDB version : 5.0.8
1617

1718
## Project Setup
1819

@@ -24,15 +25,17 @@ $ git clone https://github.com/sparcs-kaist/taxi-back
2425

2526
### Install Requirements
2627
```bash
27-
$ npm install --save
28+
$ pnpm install
2829
```
2930

3031
### Set Environment Configuration
3132
See [notion page](https://www.notion.so/sparcs/Environment-Variables-1b404bd385fa495bac6d5517b57d72bf).
3233
Refer to [.env.example](.env.example) and write your own `.env`.
3334

3435
## Backend Route Information
35-
See [Backend Route Documentation](src/routes/docs/README.md)
36+
API specification is defined on Swagger.
37+
Start development server and visit `/docs` to see the specification of each endpoint.
38+
Some endpoints are not documented in Swagger yet. For those endpoints, refer to [routes/docs/README.md](./src/routes/docs/README.md).
3639

3740
## License
3841
This project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details
@@ -46,4 +49,3 @@ See [contributors](https://github.com/sparcs-kaist/taxi-front/graphs/contributor
4649
- app : https://github.com/sparcs-kaist/taxi-app
4750
- docker : https://github.com/sparcs-kaist/taxi-docker
4851
- figma : https://www.figma.com/file/li34hP1oStJAzLNjcG5KjN/SPARCS-Taxi?node-id=0%3A1
49-
- taxiSampleGenerator : https://github.com/sparcs-kaist/taxiSampleGenerator

app.js

+21-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
// 모듈 require
22
const express = require("express");
33
const http = require("http");
4-
const { port: httpPort } = require("./loadenv");
4+
const {
5+
nodeEnv,
6+
port: httpPort,
7+
eventConfig,
8+
mongo: mongoUrl,
9+
} = require("./loadenv");
510
const logger = require("./src/modules/logger");
11+
const { connectDatabase } = require("./src/modules/stores/mongo");
612
const { startSocketServer } = require("./src/modules/socket");
713

814
// Firebase Admin 초기설정
@@ -11,10 +17,16 @@ require("./src/modules/fcm").initializeApp();
1117
// 익스프레스 서버 생성
1218
const app = express();
1319

20+
// 데이터베이스 연결
21+
connectDatabase(mongoUrl);
22+
1423
// [Middleware] request body 파싱
1524
app.use(express.urlencoded({ extended: false }));
1625
app.use(express.json());
1726

27+
// reverse proxy가 설정한 헤더를 신뢰합니다.
28+
if (nodeEnv === "production") app.set("trust proxy", 2);
29+
1830
// [Middleware] CORS 설정
1931
app.use(require("./src/middlewares/cors"));
2032

@@ -38,6 +50,13 @@ app.use(require("./src/middlewares/limitRate"));
3850
// [Router] Swagger (API 문서)
3951
app.use("/docs", require("./src/routes/docs"));
4052

53+
// [Router] 이벤트 전용 라우터입니다.
54+
eventConfig &&
55+
app.use(
56+
`/events/${eventConfig.mode}`,
57+
require("./src/lottery").lotteryRouter
58+
);
59+
4160
// [Middleware] 모든 API 요청에 대하여 origin 검증
4261
app.use(require("./src/middlewares/originValidator"));
4362

@@ -58,7 +77,7 @@ app.use(require("./src/middlewares/errorHandler"));
5877
const serverHttp = http
5978
.createServer(app)
6079
.listen(httpPort, () =>
61-
logger.info(`Express 서버가 ${httpPort}번 포트에서 시작됨.`)
80+
logger.info(`Express server started from port ${httpPort}`)
6281
);
6382

6483
// socket.io 서버 시작

loadenv.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22
require("dotenv").config({ path: `./.env.${process.env.NODE_ENV}` });
33

44
module.exports = {
5-
nodeEnv: process.env.NODE_ENV,
5+
nodeEnv: process.env.NODE_ENV, // required ("production" or "development" or "test")
66
mongo: process.env.DB_PATH, // required
7-
session: process.env.SESSION_KEY || "TAXI_SESSION_KEY", // optional
7+
session: {
8+
secret: process.env.SESSION_KEY || "TAXI_SESSION_KEY", // optional
9+
expiry: 14 * 24 * 3600 * 1000, // 14일, ms 단위입니다.
10+
},
811
redis: process.env.REDIS_PATH, // optional
912
sparcssso: {
1013
id: process.env.SPARCSSSO_CLIENT_ID || "", // optional
@@ -25,6 +28,8 @@ module.exports = {
2528
secretKey: process.env.JWT_SECRET_KEY || "TAXI_JWT_KEY",
2629
option: {
2730
algorithm: "HS256",
31+
// FIXME: remove FRONT_URL from issuer. 단, issuer를 변경하면 이전에 발급했던 모든 JWT가 무효화됩니다.
32+
// See https://github.com/sparcs-kaist/taxi-back/issues/415
2833
issuer: process.env.FRONT_URL || "http://localhost:3000", // optional (default = "http://localhost:3000")
2934
},
3035
TOKEN_EXPIRED: -3,
@@ -38,4 +43,5 @@ module.exports = {
3843
slackWebhookUrl: {
3944
report: process.env.SLACK_REPORT_WEBHOOK_URL || "", // optional
4045
},
46+
eventConfig: process.env.EVENT_CONFIG && JSON.parse(process.env.EVENT_CONFIG), // optional
4147
};

0 commit comments

Comments
 (0)