Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into #156-move-rooms-to-th…
Browse files Browse the repository at this point in the history
…e-past-room-list-and-change-settlestatus-automatically-when-the-participant-is-one
  • Loading branch information
cokia committed Apr 2, 2024
2 parents 11cfed9 + 356e56e commit 620b67d
Show file tree
Hide file tree
Showing 121 changed files with 8,122 additions and 2,360 deletions.
7 changes: 7 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,10 @@ CORS_WHITELIST=[CORS 정책에서 허용하는 도메인의 목록(e.g. ["http:/
GOOGLE_APPLICATION_CREDENTIALS=[GOOGLE_APPLICATION_CREDENTIALS JSON]
TEST_ACCOUNTS=[스팍스SSO로 로그인시 무조건 테스트로 로그인이 가능한 허용 아이디 목록]
SLACK_REPORT_WEBHOOK_URL=[Slack 웹훅 URL들이 담긴 JSON]

# optional environment variables for taxiSampleGenerator
SAMPLE_NUM_OF_ROOMS=[방의 개수]
SAMPLE_NUM_OF_CHATS=[각 방의 채팅 개수]
SAMPLE_MAXIMUM_INTERVAL_BETWEEN_CHATS=[채팅 간 최대 시간 간격(단위: 초, 실수도 가능)]
SAMPLE_OCCURENCE_OF_JOIN=[새로운 채팅이 입장 메세지일 확률(0 ~ 1 사이의 값)]
SAMPLE_OCCURENCE_OF_ABORT=[새로운 채팅이 퇴장 메세지일 확률(0 ~ 1 사이의 값)]
33 changes: 26 additions & 7 deletions .github/workflows/push_image_ecr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,17 @@ jobs:
with:
fetch-depth: 0

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Cache Docker layers
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Get previous tag-version
id: previous_tag
uses: WyriHaximus/github-action-get-previous-tag@v1
Expand All @@ -47,15 +58,23 @@ jobs:
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1

- name: Build and Push to AWS ECR
id: build_image
- name: Build Image and Push to AWS ECR
id: build_image_and_push
uses: docker/build-push-action@v5
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
IMAGE_TAG: ${{ steps.tag.outputs.tag }}
ECR_REPOSITORY: taxi-back
with:
push: true
tags: |
"${{ env.ECR_REGISTRY }}/${{ env.ECR_REPOSITORY }}:${{ env.IMAGE_TAG }}"
"${{ env.ECR_REGISTRY }}/${{ env.ECR_REPOSITORY }}:latest"
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new

- name: Remove old cache
run: |
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:latest .
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
docker push $ECR_REGISTRY/$ECR_REPOSITORY:latest
echo "Push iamge : $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG and latest"
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
32 changes: 25 additions & 7 deletions .github/workflows/push_image_ecr_dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,18 @@ jobs:
uses: actions/checkout@v3
with:
fetch-depth: 0


- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Cache Docker layers
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
Expand All @@ -31,13 +42,20 @@ jobs:
- name: Login to AWS ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1

- name: Build and Push to AWS ECR
id: build_image

- name: Build Image and Push to AWS ECR
id: build_image_and_push
uses: docker/build-push-action@v5
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: taxi-back
with:
push: true
tags: "${{ env.ECR_REGISTRY }}/${{ env.ECR_REPOSITORY }}:dev"
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new

- name: Remove old cache
run: |
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:dev .
docker push $ECR_REGISTRY/$ECR_REPOSITORY:dev
echo "Push iamge : $ECR_REGISTRY/$ECR_REPOSITORY:dev"
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
32 changes: 8 additions & 24 deletions .github/workflows/test_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,38 +12,23 @@ jobs:
strategy:
matrix:
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
node-version: [16.x]
node-version: ['18.x']
mongodb-version: ['5.0']
steps:
- name: Start MongoDB
run: sudo docker run --name mongodb -d -p 27017:27017 mongo:${{ matrix.mongodb-version }}
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/checkout@v3
- uses: actions/checkout@v3
with:
submodules: true
- name: Install Node.js
uses: actions/setup-node@v3
with:
node-version: 16

- uses: pnpm/action-setup@v2
name: Install pnpm
- name: Install pnpm
uses: pnpm/action-setup@v2
with:
version: 8
- id: submodule-local
name: Save local version of submodule
run: echo "ver=`cd sampleGenerator && git log --pretty="%h" -1 && cd ..`" >> $GITHUB_OUTPUT
- id: submodule-origin
name: Save origin version of submodule
run: echo "ver=`cd sampleGenerator && git log origin --pretty="%h" -1 && cd ..`" >> $GITHUB_OUTPUT
- name: Check submodule version
if: ${{ steps.submodule-local.outputs.ver != steps.submodule-origin.outputs.ver }}
uses: actions/github-script@v3
- name: Install Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
script: |
core.setFailed('Please update submodule to the latest version by using \"git submodule update --remote\"')
- name: Install sampleGenerator dependencies from package-lock.json
run: cd sampleGenerator && pnpm i --force --frozen-lockfile && cd ..
node-version: ${{ matrix.node-version }}
cache: 'pnpm'
- name: Install taxi-back dependencies from package-lock.json
run: pnpm i --force --frozen-lockfile
- name: Run unit tests
Expand All @@ -53,6 +38,5 @@ jobs:
AWS_S3_BUCKET_NAME: ${{ secrets.AWS_S3_BUCKET_NAME }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
DB_PATH: ${{ secrets.DB_PATH }}
FRONT_URL: ${{ secrets.FRONT_URL }}
PORT: ${{ secrets.PORT }}
SESSION_KEY: ${{ secrets.SESSION_KEY }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*.code-workspace
*.swp
/logs/*.log
.vscode

# AdminJS 관련 디렉토리
.adminjs
4 changes: 0 additions & 4 deletions .gitmodules

This file was deleted.

2 changes: 2 additions & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Force Node.js and pnpm versions according to package.json
engine-strict=true
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v18.17.0
21 changes: 12 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
FROM node:16-alpine
FROM node:18-alpine

# Copy repository
WORKDIR /usr/src/app
COPY . .

# Install curl (for taxi-docker)
RUN apk update && apk add curl
RUN npm install --global pnpm@8.6.6 serve@14.1.2
# Install curl(for taxi-watchtower) and pnpm
RUN apk update && apk add curl && npm install --global pnpm@8.8.0

# Install requirements
RUN pnpm i --force --frozen-lockfile
# pnpm fetch does require only lockfile
COPY pnpm-lock.yaml .

# Note: devDependencies are not fetched
RUN pnpm fetch --prod

# Copy repository and install dependencies
ADD . ./
RUN pnpm install --offline --prod

# Run container
EXPOSE 80
ENV PORT 80
CMD ["pnpm", "run", "serve"]

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

## Prerequisites
- Recommended npm version : 8.5.5 (with node v.16.15.0)
- Recommended mognoDB version : 5.0.8
- [Issue with node version](https://github.com/sparcs-kaist/taxi-front/issues/76)
## Prerequisite

- Recommended node version : >=18.0.0 (Node v18.18.0, for example)
- Recommended pnpm version : >=8.0.0 (pmpm v8.8.0, for example)
- Recommended mongoDB version : 5.0.8

## Project Setup

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

### Install Requirements
```bash
$ npm install --save
$ pnpm install
```

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

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

## License
This project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details
Expand All @@ -46,4 +49,3 @@ See [contributors](https://github.com/sparcs-kaist/taxi-front/graphs/contributor
- app : https://github.com/sparcs-kaist/taxi-app
- docker : https://github.com/sparcs-kaist/taxi-docker
- figma : https://www.figma.com/file/li34hP1oStJAzLNjcG5KjN/SPARCS-Taxi?node-id=0%3A1
- taxiSampleGenerator : https://github.com/sparcs-kaist/taxiSampleGenerator
23 changes: 21 additions & 2 deletions app.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
// 모듈 require
const express = require("express");
const http = require("http");
const { port: httpPort } = require("./loadenv");
const {
nodeEnv,
port: httpPort,
eventConfig,
mongo: mongoUrl,
} = require("./loadenv");
const logger = require("./src/modules/logger");
const { connectDatabase } = require("./src/modules/stores/mongo");
const { startSocketServer } = require("./src/modules/socket");

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

// 데이터베이스 연결
connectDatabase(mongoUrl);

// [Middleware] request body 파싱
app.use(express.urlencoded({ extended: false }));
app.use(express.json());

// reverse proxy가 설정한 헤더를 신뢰합니다.
if (nodeEnv === "production") app.set("trust proxy", 2);

// [Middleware] CORS 설정
app.use(require("./src/middlewares/cors"));

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

// [Router] 이벤트 전용 라우터입니다.
eventConfig &&
app.use(
`/events/${eventConfig.mode}`,
require("./src/lottery").lotteryRouter
);

// [Middleware] 모든 API 요청에 대하여 origin 검증
app.use(require("./src/middlewares/originValidator"));

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

// socket.io 서버 시작
Expand Down
10 changes: 8 additions & 2 deletions loadenv.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@
require("dotenv").config({ path: `./.env.${process.env.NODE_ENV}` });

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

0 comments on commit 620b67d

Please sign in to comment.