Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#404 Node.js 버전 18로 올리기, #414 GitHub Actions 캐시 사용 #413

Merged
merged 15 commits into from
Oct 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 33 additions & 4 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-

Comment on lines +25 to +35
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오 캐시 도입이 되면 빌드가 훨씬 빨라지겠네요 :D

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

감사합니다! 배포가 더 빨라질 수 있어 기대돼요 ㅎㅎ

- name: Get previous tag-version
id: previous_tag
uses: WyriHaximus/github-action-get-previous-tag@v1
Expand All @@ -47,15 +58,33 @@ jobs:
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1

- name: Build and Push to AWS ECR
- name: Build Image
id: build_image
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:
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: Push to AWS ECR
id: push_image
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
IMAGE_TAG: ${{ steps.tag.outputs.tag }}
ECR_REPOSITORY: taxi-back
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"
echo "Push image : $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG and latest"

- name: Remove old cache
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache

36 changes: 31 additions & 5 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,28 @@ jobs:
- name: Login to AWS ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1
- name: Build and Push to AWS ECR

- name: Build Image
id: build_image
uses: docker/build-push-action@v5
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: taxi-back
with:
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: Push to AWS ECR
id: push_image
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: taxi-back
run: |
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:dev .
docker push $ECR_REGISTRY/$ECR_REPOSITORY:dev
echo "Push iamge : $ECR_REGISTRY/$ECR_REPOSITORY:dev"
echo "Push image : $ECR_REGISTRY/$ECR_REPOSITORY:dev"

- name: Remove old cache
run: |
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 link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pnpm fetch 명령어는 lockfile만으로도 의존성을 virtual store(node_modules/.pnpm 디렉토리)에 저장할 수 있습니다. lockfile이 바뀌지 않는 이상, package.json의 내용(taxi-back 패키지 버전, 커맨드 등)이 바뀌어도 image layer가 유효합니다.
참조: https://pnpm.io/cli/fetch


# 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
2 changes: 2 additions & 0 deletions loadenv.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,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 Down
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"
},
Comment on lines +17 to +20
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

크.. 버전업 고생하셨습니다 :D

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

히히 다른 의존성 안 올려도 바로 잘 돌아가더라구요 ㅎㅎ 옛날엔 이슈가 많았던 것 같은데 다행이었습니다..

"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