Skip to content

Commit

Permalink
Merge pull request #29 from UMC-FITple/feat/#28_backend_cicd-1
Browse files Browse the repository at this point in the history
CI/CD 파이프라인 구축
  • Loading branch information
seoyeoneel02 authored Aug 13, 2024
2 parents 0d190d1 + cc3d7a5 commit d464973
Show file tree
Hide file tree
Showing 7 changed files with 898 additions and 15 deletions.
86 changes: 86 additions & 0 deletions .github/workflows/dev_deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
name: Node.js Dev CI/CD

on:
pull_request: # pull request -> merge 가 되었을 때 Github Action 실행!
types: [ closed ]
workflow_dispatch: # 수동 실행도 가능하도록 함

jobs:
build:
# pull 요청이 dev에 merge 되었을 때 아래 steps를 실행
if: github.event.pull_request.merged == true && github.event.pull_request.base.ref == 'dev'

runs-on: ubuntu-latest # 우분투 최신 버전으로 실행

strategy:
matrix:
node-version: ['18.x'] # 노드 버전 지정! 여러 개도 가능! ['18.x', '14.x'] 요렇게

steps:
# build 할 코드를 가져옴 (코드 checkout - github에서 제공해주는 checkout@v3 사용)
- name: Checkout
uses: actions/checkout@v3

# Node.js 세팅
- name: Set up Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'pnpm'

- name: Install Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}

# dependencies 설치, test and build
- name: Install dependencies
run: pnpm ci # dependencies 설치 pnpm ci, pnpm install 모두 다 됨!

- name: Run Build
run: pnpm run build # 빌드

# 배포 패키지 생성
- name: Generate deployment package
run: |
cp -R .platform dist
cp package.json dist/package.json
cp package-lock.json dist/package-lock.json
cp Procfile dist/Procfile
cd dist
zip -r deploy.zip .
# 생성한 deploy.zip 파일 내부 확인용!
- name: Get Zip Inside
run: zipinfo -1 dist/deploy.zip

# 현재 시간 얻기 (Build 시점의 시간 얻기)
- name: Get current time
uses: 1466587594/get-current-time@v2
id: current-time
with:
format: YYYY-MM-DDTHH-mm-ss
utcOffset: "+09:00" # 한국 시간 고려

# 현재 시간 출력 (위에서 얻은 build 시점의 시간 보여주기)
- name: Show Current Time
run: echo "CurrentTime=${{steps.current-time.outputs.formattedTime}}"
shell: bash

# Beanstalk 배포
- name: Beanstalk Deploy
uses: einaregilsson/beanstalk-deploy@v21
with:
aws_access_key: ${{secrets.AWS_ACTION_ACCESS_KEY_ID}}
aws_secret_key: ${{secrets.AWS_ACTION_SECRET_ACCESS_KEY}}
application_name: FITple-dev
environment_name: FITple-dev-env
version_label: github-action-${{ steps.current-time.outputs.formattedTime }} # version_label은 이전에 배포한 label과 중복되면 안됨!
use_existing_version_if_available: true
region: ap-northeast-2
deployment_package: dist/deploy.zip
wait_for_deployment: false # 바로 Beanstalk으로 넘어갈 수 있도록 함

# 그냥 다 했다고 출력하기
- name: Deployed!
run: echo App deployed to ELB
55 changes: 55 additions & 0 deletions .platform/nginx/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
user nginx;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
worker_processes auto;
worker_rlimit_nofile 33282;

events {
use epoll;
worker_connections 1024;
multi_accept on;
}

http {
include /etc/nginx/mime.types;
default_type application/octet-stream;

log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';

include conf.d/*.conf;

map $http_upgrade $connection_upgrade {
default "upgrade";
}

upstream node {
server 127.0.0.1:3000;
keepalive 1024;
}

server {
listen 80 default_server;
listen [::]:80 default_server;

location / {
proxy_pass http://node;
proxy_http_version 1.1;
proxy_set_header Connection $connection_upgrade;
proxy_set_header Upgrade $http_upgrade;

proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}

access_log /var/log/nginx/access.log main;

gzip off;
gzip_comp_level 4;

# Include the Elastic Beanstalk generated locations
include conf.d/elasticbeanstalk/healthd.conf;
}
}
1 change: 1 addition & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: pnpm ci & pnpm run start
20 changes: 10 additions & 10 deletions src/index.js → index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ import express from 'express';
import cors from 'cors';
import cookieParser from 'cookie-parser';
import SwaggerUi from 'swagger-ui-express';
import { specs } from './swagger/swagger.config.js';
import { init } from './db/index.js';
import { status } from './config/response.status.js';
import { BaseError } from './config/error.js';
import { response } from './config/response.js';
import { signupRouter } from './routes/signup.js';
import { loginRouter } from './routes/login.js';
import { searchRouter } from './routes/search.js';
import { refreshTokenRouter } from './routes/refreshToken.js';
import sizeUploadRoutes from './routes/uploadsize.routes.js';
import { specs } from './src/swagger/swagger.config.js';
import { init } from './src/db/index.js';
import { status } from './src/config/response.status.js';
import { BaseError } from './src/config/error.js';
import { response } from './src/config/response.js';
import { signupRouter } from './src/routes/signup.js';
import { loginRouter } from './src/routes/login.js';
import { searchRouter } from './src/routes/search.js';
import { refreshTokenRouter } from './src/routes/refreshToken.js';
import sizeUploadRoutes from './src/routes/uploadsize.routes.js';

dotenv.config();

Expand Down
12 changes: 9 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
"type": "module",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node src/index.js",
"start:dev": "nodemon --exec babel-node index.js",
"start:dist": "webpack --mode production & node ./dist/main.js",
"start": "node main.js",
"dev": "nodemon src/index.js",
"build": "babel src -d dist",
"build": "webpack",
"lint": "eslint .",
"format": "prettier --write ."
},
Expand All @@ -20,14 +22,18 @@
"@babel/core": "^7.24.9",
"@babel/node": "^7.24.8",
"@babel/preset-env": "^7.24.8",
"babel-loader": "^9.1.3",
"eslint": "^9.7.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.2.1",
"nodemon": "^3.1.4",
"prettier": "^3.3.3",
"swagger-cli": "^4.0.4",
"swagger-jsdoc": "^6.2.8",
"swagger-ui-express": "^5.0.1"
"swagger-ui-express": "^5.0.1",
"webpack": "^5.93.0",
"webpack-cli": "^5.1.4",
"webpack-node-externals": "^3.0.0"
},
"dependencies": {
"bcrypt": "^5.1.1",
Expand Down
Loading

0 comments on commit d464973

Please sign in to comment.