Skip to content

Commit

Permalink
Merge pull request #432 from sparcs-kaist/dev
Browse files Browse the repository at this point in the history
Main branch update from Dev branch
  • Loading branch information
14KGun authored Nov 14, 2023
2 parents 150504a + d4893b0 commit a1c76cd
Show file tree
Hide file tree
Showing 32 changed files with 1,902 additions and 1,313 deletions.
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
20 changes: 9 additions & 11 deletions .github/workflows/test_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +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
- name: Install Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'pnpm'
- id: submodule-local
name: Save local version of submodule
run: echo "ver=`cd sampleGenerator && git log --pretty="%h" -1 && cd ..`" >> $GITHUB_OUTPUT
Expand All @@ -53,6 +52,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 }}
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 [email protected] [email protected]
# Install curl(for taxi-watchtower) and pnpm
RUN apk update && apk add curl && npm install --global [email protected]

# 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"]

15 changes: 9 additions & 6 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 Down
4 changes: 2 additions & 2 deletions app.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// 모듈 require
const express = require("express");
const http = require("http");
const { port: httpPort, eventConfig } = require("./loadenv");
const { nodeEnv, port: httpPort, eventConfig } = require("./loadenv");
const logger = require("./src/modules/logger");
const { connectDatabase } = require("./src/modules/stores/mongo");
const { startSocketServer } = require("./src/modules/socket");
Expand All @@ -20,7 +20,7 @@ app.use(express.urlencoded({ extended: false }));
app.use(express.json());

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

// [Middleware] CORS 설정
app.use(require("./src/middlewares/cors"));
Expand Down
16 changes: 8 additions & 8 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
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,10 +43,5 @@ module.exports = {
slackWebhookUrl: {
report: process.env.SLACK_REPORT_WEBHOOK_URL || "", // optional
},
eventConfig: (process.env.EVENT_CONFIG &&
JSON.parse(process.env.EVENT_CONFIG)) || {
mode: "2023fall",
startAt: "2023-09-25T00:00:00+09:00",
endAt: "2023-10-12T00:00:00+09:00",
},
eventConfig: process.env.EVENT_CONFIG && JSON.parse(process.env.EVENT_CONFIG),
};
40 changes: 22 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,22 @@
"name": "taxi-back",
"version": "1.0.0",
"description": "KAIST Taxi Party Matching Web Service",
"author": "sparcs/taxi",
"license": "MIT",
"main": "app.js",
"scripts": {
"preinstall": "npx only-allow pnpm",
"start": "cross-env TZ='Asia/Seoul' npx nodemon app.js",
"test": "npm run sample && cross-env TZ='Asia/Seoul' npm run mocha",
"mocha": "cross-env TZ='Asia/Seoul' NODE_ENV=test mocha --recursive --reporter spec --exit",
"serve": "cross-env TZ='Asia/Seoul' NODE_ENV=production node app.js",
"lint": "npx eslint --fix .",
"sample": "cd sampleGenerator && npm start && cd .."
},
"engines": {
"node": ">=18.0.0",
"pnpm": ">=8.0.0"
},
"dependencies": {
"@adminjs/express": "^5.1.0",
"@adminjs/mongoose": "^3.0.3",
Expand All @@ -22,12 +37,12 @@
"eslint-config-prettier": "^8.3.0",
"express": "^4.17.1",
"express-formidable": "^1.2.0",
"express-rate-limit": "^6.6.0",
"express-rate-limit": "^7.1.0",
"express-session": "^1.17.3",
"express-validator": "^6.14.0",
"firebase-admin": "^11.4.1",
"jsonwebtoken": "^8.5.1",
"mongoose": "^6.11.3",
"jsonwebtoken": "^9.0.2",
"mongoose": "^6.12.0",
"node-cron": "3.0.2",
"node-mocks-http": "^1.12.1",
"querystring": "^0.2.1",
Expand All @@ -40,22 +55,11 @@
"winston-daily-rotate-file": "^4.7.1"
},
"devDependencies": {
"chai": "*",
"chai": "^4.3.10",
"eslint": "^8.22.0",
"eslint-plugin-mocha": "^10.1.0",
"mocha": "*",
"nodemon": "^2.0.14",
"mocha": "^10.2.0",
"nodemon": "^3.0.1",
"supertest": "^6.2.4"
},
"scripts": {
"preinstall": "npx only-allow pnpm",
"start": "cross-env TZ='Asia/Seoul' npx nodemon app.js",
"test": "npm run sample && cross-env TZ='Asia/Seoul' npm run mocha",
"mocha": "cross-env TZ='Asia/Seoul' NODE_ENV=test mocha --recursive --reporter spec --exit",
"serve": "cross-env TZ='Asia/Seoul' NODE_ENV=production node app.js",
"lint": "npx eslint --fix .",
"sample": "cd sampleGenerator && npm start && cd .."
},
"author": "sparcs/taxi",
"license": "MIT"
}
}
Loading

0 comments on commit a1c76cd

Please sign in to comment.