๐ค CI/CD๋?
โญ๏ธ CI
CI๋ Continuous Integration์ ์ฝ์๋ก ์ง์์ ์ธ ํตํฉ์ ์๋ฏธํฉ๋๋ค.
์ฝ๊ฒ ๋งํ๋ฉด ๋น๋/ํ ์คํธ ์๋ํ ๊ณผ์ ์ด๋ผ๊ณ ํ ์ ์๋๋ฐ, CI๋ฅผ ์ฑ๊ณต์ ์ผ๋ก ๊ตฌํํ ๊ฒฝ์ฐ ์ ํ๋ฆฌ์ผ์ด์ ์ ๋ํ ์๋ก์ด ์ฝ๋ ๋ณ๊ฒฝ ์ฌํญ์ด ๋ฐ์ํ ๋๋ง๋ค Build, Test๋ฅผ ์๋์ผ๋ก ํ์ง ์์๋ ํ๋ก๊ทธ๋จ์ด ์๋์ผ๋ก ์ด๋ฌํ ๊ณผ์ ๋ค์ ์งํํด์ค๋๋ค.
โญ๏ธ CD
CD๋ Continuous Delivery ๋๋ Continuous Deployment์ ์ฝ์๋ก ์ง์์ ์ธ ์ ๊ณต, ์ง์์ ์ธ ๋ฐฐํฌ๋ฅผ ์๋ฏธํฉ๋๋ค.
CI ๊ณผ์ ์ ๊ฑฐ์น๋ฉด Build, Test ๊ณผ์ ์ ๋ชจ๋ ๊ฑฐ์น๊ธฐ ๋๋ฌธ์, ๋ฐฐํฌ ๋จ๊ณ ์ ์ ์ ํ๋ฆฌ์ผ์ด์ ์ ๋ฌธ์ ๊ฐ ์๋์ง ๊ฒ์ฆ์ด ๊ฐ๋ฅํฉ๋๋ค. ๋ฌธ์ ๊ฐ ์๋ค๋ ๊ฒ์ด ๊ฒ์ฆ์ด ๋๋ฉด, ๊ฒ์ฆ๋ ์ ํ๋ฆฌ์ผ์ด์ ์ ์ค์ ํ๋ก๋์ ํ๊ฒฝ์ผ๋ก ์๋์ผ๋ก ๋ฐฐํฌํด์ค๋๋ค.
๐ Github ํ๊ฒฝ๋ณ์ ๋ฑ๋กํ๊ธฐ
CI ๊ณผ์ ์ Github Actions๋ฅผ ํ์ฉํด ์งํํฉ๋๋ค.
.env ํ์ผ์ ๊นํ๋ธ์ ์ฌ๋ฆฌ์ง ์๊ธฐ ๋๋ฌธ์ ์ฌ์ฉํ ํค ๊ฐ๋ค์ ๊นํ๋ธ์ ๋ฑ๋กํด์ค์ผํฉ๋๋ค.
Repository์ Settings > Security > Secrets > Actions ๋ก ์ด๋ํด์ค๋๋ค.

New Repository secret ์ ํด๋ฆญํด์ค๋๋ค.

.env ํ์ผ์ ํค ๊ฐ๋ค์ ์์ ๊ฐ์ด ๋ชจ๋ ๋ฑ๋กํด์ค๋๋ค.

๐ Github Actions workflow ์์ฑ
ํ๋ก์ ํธ ์ต์๋จ์ .github/workflows/deploy.yml ํ์ผ์ ์์ฑํด์ค๋๋ค.
์ ์ฒด ์ฝ๋ deploy.yml
# This workflow will do a clean install of node dependencies, cache/restore them, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
name: deploy
on:
push:
branches: [develop]
pull_request:
branches: [develop]
jobs:
build:
runs-on: ubuntu-18.04
strategy:
matrix:
node-version: [16.15.1]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
steps:
- name: Checkout source code.
uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
- name: Check Npm -v
run: npm -v
- name: create env file
working-directory: ./
run: |
pwd
touch .env
echo PORT=${{ secrets.PORT }} >> .env
echo MONGODB_URI=${{ secrets.MONGODB_URI }} >> .env
echo JWT_SECRET=${{ secrets.JWT_SECRET }} >> .env
echo JWT_ALGO=${{ secrets.JWT_ALGO }} >> .env
cat .env
- name: build server files
working-directory: ./
run: |
yarn
yarn run build
on:
push:
branches: [develop]
pull_request:
branches: [develop]
develop ๋ธ๋์น์ Pushํ๊ฑฐ๋ Pull Requestํ์ ๋ Workflow๋ฅผ Triger(์คํ)ํฉ๋๋ค.
jobs:
build:
runs-on: ubuntu-18.04
strategy:
matrix:
node-version: [16.15.1]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
runs-on
์๋ ์ฌ์ฉํ ๊ฐ์ ํ๊ฒฝ์ ์ธ์คํด์ค๋ฅผ ์ง์ ํด์ค๋๋ค.
node-version
์๋ ์ฌ์ฉํ node์ ๋ฒ์ ์ ๋ช
์ํฉ๋๋ค.
steps:
- name: Checkout source code.
uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
- name: Check Npm -v
run: npm -v
- name: create env file
working-directory: ./
run: |
pwd
touch .env
echo PORT=${{ secrets.PORT }} >> .env
echo MONGODB_URI=${{ secrets.MONGODB_URI }} >> .env
echo JWT_SECRET=${{ secrets.JWT_SECRET }} >> .env
echo JWT_ALGO=${{ secrets.JWT_ALGO }} >> .env
cat .env
- name: build server files
working-directory: ./
run: |
yarn
yarn run build
Checkout source code.
step์ Github์ repository์ ์ฌ๋ ค๋ ์ฝ๋๋ฅผ CI ์๋ฒ๋ก ๋ด๋ ค๋ฐ์ ํ์ ํน์ ๋ธ๋์น๋ก ์ ํํ๋ ๊ณผ์ ์
๋๋ค.
Use Node.js ${{ matrix.node-version }}
step์ ๋ช
์ํ Node๋ฅผ ๋ฒ์ ์ ๋ง๊ฒ ์ค์นํ๋ ๊ณผ์ ์
๋๋ค.
create env file
step์ Github์ ๋ฑ๋กํ ํ๊ฒฝ๋ณ์๋ค๋ก .env ํ์ผ์ ์์ฑํด์ฃผ๋ ๊ณผ์ ์
๋๋ค.
build server files
step์์๋ yarn
๋ช
๋ น์ด๋ก ํ์ํ dependency๋ค์ ์ค์นํ ํ์ ๋น๋๋ฅผ ํด์ฃผ๋ ๊ณผ์ ์
๋๋ค.
๐ Github Actions ํ์ธ
deploy.yml ํ์ผ์ Repository์ ๋ฑ๋กํ ์ดํ develop ๋ธ๋์น์ Push, Pull Requestํ๋ฉด ์ํฌํ๋ก์ฐ๊ฐ ์คํ๋ฉ๋๋ค.

๊นํ๋ธ Repository์ Actions์ ๋ค์ด๊ฐ๋ณด๋ฉด CI๊ฐ ์ ์์ ์ผ๋ก ์คํ๋ ๊ฒ์ ํ์ธํ ์ ์์ต๋๋ค.

Workflow๋ฅผ ํด๋ฆญํด๋ณด๋ฉด deploy.yml ํ์ผ์ ๋ฑ๋กํ step๋ณ๋ก ์คํ๋ ๊ฒฐ๊ณผ์ ๋ก๊ทธ๋ฅผ ํ์ธํ ์ ์์ต๋๋ค.
๋ค์ ๊ธ์์๋ AWS CodeDeploy๋ฅผ ํ์ฉํ CD ๊ณผ์ ์ ์ง์ค์ ์ผ๋ก ์ดํด๋ณด๊ฒ ์ต๋๋ค.