๐จ๐ฆฒ๊ธฐ์กด ๋ฐฉ์์ ๋ฌธ์ ์
Node.js, EC2, github์ ํตํด ์๋ฒ ๋ฐฐํฌ ์์ ์ ์งํํ๋ ๊ณผ์
local ๊ฐ๋ฐ -> github push -> ec2์์ pull -> build or run -> ๋ฐฐํฌ ์๋ฃ
๋งค๋ฒ ๊ฐ๋ฐ ํ ์ง์ EC2 ์ ์ํด์ pull ๋ฐ๊ณ build, run ํด์ค์ผํ๋ ๋ฒ๊ฑฐ๋ก์์ด ์๊ธด๋ค.!.!.!
๊ทธ๋์ ๋ฐฐํฌ ์๋ํ ๊ณผ์ ์ ํตํด ์ด ๊ณผ์ ์ ์ฝ๊ณ ๊ฐํธํ๊ฒ ํ ์ ์๋ค.
Git์ GithubActions์ AWS์์ ์ ๊ณตํ๋ CodeDeploy๋ฅผ ํตํด Github repository์์ ์์ ํ code๊ฐ ๋ฐ๋ก ec์์ deploy ๋๋๋ก ๋ฐฐํฌ ์๋ํ๋ฅผ ์งํํด๋ณด๊ฒ ๋ค.
CI/CD ?
CI
CI๋ Continuous Integration์ ์ฝ์๋ก ์ง์์ ์ธ ํตํฉ์ ์๋ฏธํ๋ค๊ณ ํ๋ค.
๋น๋/ํ ์คํธ ์๋ํ ๊ณผ์ , CI๋ฅผ ์ฑ๊ณต์ ์ผ๋ก ๊ตฌํํ ๊ฒฝ์ฐ ์ ํ๋ฆฌ์ผ์ด์ ์ ๋ํ ์๋ก์ด ์ฝ๋ ๋ณ๊ฒฝ ์ฌํญ์ด ๋ฐ์ํ ๋๋ง๋ค Build, Test๋ฅผ ์๋์ผ๋ก ํ์ง ์์๋ ํ๋ก๊ทธ๋จ์ด ์๋์ผ๋ก ์ด๋ฌํ ๊ณผ์ ๋ค์ ์งํํด์ค๋๋ค.
CD
CD๋ Continuous Delivery ๋๋ Continuous Deployment์ ์ฝ์๋ก ์ง์์ ์ธ ์ ๊ณต, ์ง์์ ์ธ ๋ฐฐํฌ๋ฅผ ์๋ฏธํ๋ค๊ณ ํ๋ค.
CI ๊ณผ์ ์ ๊ฑฐ์น๋ฉด Build, Test ๊ณผ์ ์ ๋ชจ๋ ๊ฑฐ์น๊ธฐ ๋๋ฌธ์, ๋ฐฐํฌ ๋จ๊ณ ์ ์ ์ ํ๋ฆฌ์ผ์ด์ ์ ๋ฌธ์ ๊ฐ ์๋์ง ๊ฒ์ฆ์ด ๊ฐ๋ฅํฉ๋๋ค. ๋ฌธ์ ๊ฐ ์๋ค๋ ๊ฒ์ด ๊ฒ์ฆ์ด ๋๋ฉด, ๊ฒ์ฆ๋ ์ ํ๋ฆฌ์ผ์ด์ ์ ์ค์ ํ๋ก๋์ ํ๊ฒฝ์ผ๋ก ์๋์ผ๋ก ๋ฐฐํฌํด์ค๋๋ค.
Github Actions์ ์ด์ฉํ CI ๊ณผ์ ์งํ
1. Github ํ๊ฒฝ ๋ณ์ ๋ฑ๋ก
.env ํ์ผ์ ๊นํ๋ธ์ ์ฌ๋ฆฌ๋ฉด ํฐ์ผ๋๋ค ใท -ใท
์ฌ์ฉํ ํค ๊ฐ๋ค์ ๊นํ๋ธ์ ์ฐ๋ฆฌ๋ง ์๊ฒ๋ ๋ฑ๋กํด์ค๋ค.
๊นํ์ ๋ ํฌ > Settings > Security > Secrets > Actions
ํ๋ก์ ํธ ํ์ผ ๋ด์ .env ํ์ผ์ ์๋ ๊ฒ๋ค์ ๋ค ์ฎ๊ฒจ์ค
2. Github Actions workflow ์์ฑ
ํ๋ก์ ํธ ์ต์๋จ์ .github/workflows/deploy.yml ํ์ผ์ ์์ฑํด์ค๋๋ค.
deploy.yml
name: deploy
on:
push:
branches: [main]
jobs:
build-and-deploy:
runs-on: ubuntu-20.04
strategy:
matrix:
node-version: [18.11.0]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
steps:
- name: โ
์ฒดํฌ์์ source code.
uses: actions/checkout@v3
- name: โ๏ธ ${{ matrix.node-version }} ๋ฒ์ ์ ๋
ธ๋๋ก ์ธํ
ํฉ๋๋ค.
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- name: โ๏ธ ํ๊ฒฝ๋ณ์๋ฅผ ์ค์ ํฉ๋๋ค.
working-directory: ./
run: |
pwd
touch .env
echo DATABASE_URL=${{ secrets.DATABASE_URL }} >> .env
cat .env
- name: โจ ํจํค์ง ์ค์น
working-directory: ./
run: yarn
- name: โจ ๋น๋ ๊ณผ์ ์ ์์
working-directory: ./
run: yarn run build
branches : ์ด๋ค ๋ธ๋์น์ Push, Pull Requestํ์๋ Workflow๋ฅผ Triger(์คํ)
runs-on : ์ฌ์ฉํ ๊ฐ์ ํ๊ฒฝ์ ์ธ์คํด์ค๋ฅผ ์ง์
node-version : ์ฌ์ฉํ node์ ๋ฒ์
์๋์ ์ค๋ฅ๊ฐ ๋์ ubuntu - ๋ฒ์ ์ 20์ผ๋ก ์ค์ ํจ
node: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.28' not found (required by node) ์๋ฌ ํด๊ฒฐ ์ฌ๋ก
OS ๋ฒ์ ์ ์ค์์ฑ
velog.io
Checkout source code : Github์ repository์ ์ฌ๋ ค๋ ์ฝ๋๋ฅผ CI ์๋ฒ๋ก ๋ด๋ ค๋ฐ์ ํ์ ํน์ ๋ธ๋์น๋ก ์ ํํ๋ ๊ณผ์ .
node-version : Node๋ฅผ ๋ฒ์ ์ ๋ง๊ฒ ์ค์น
create env file : Github์ ๋ฑ๋กํ ํ๊ฒฝ๋ณ์๋ค๋ก .env ํ์ผ์ ์์ฑํด์ฃผ๋ ๊ณผ์
build server files : yarn ๋ช ๋ น์ด๋ก ํ์ํ dependency๋ค์ ์ค์นํ ํ์ ๋น๋ํ๋ ๊ณผ์
๐ฅ์์ ์ฝ์งํ ๋ถ๋ถ๐ฅ
github actions yarn run build keeps running
๋ธ๋ก๊ทธ ๊ธ ๋ณด๊ณ ๋ฐ๋ผํ๋๋ฐ , yarn run build ๋ถ๋ถ์์ 3์๊ฐ 50๋ถ๊น์ง ๊ธฐ๋ค๋ ธ๋๋ฐ ๊ณ์ ๋ก๋ฉ๋ง ๊ฑธ๋ ธ๋ค..
CI ๊ณผ์ ์ ๋๋ฌด ๋ฆ๊ฒ ๋ถ์ฌ์ ํ์ผ๋ค์ ์คํํ ๊ฒ ๋ง์์ ๋ฒ์ ์ฃผ๋๊ฑด๊ฐ ์ถ์๋๋ฐ ๊ทธ๊ฒ ์๋์๋ค!!!!!!!
package.jsonํ์ผ์
scripts:์ build ๋ช ๋ น์ด๊ฐ tsc && node dist๋ก ๋์ด์์๋ค.
node dist๋ก ์๋ฒ๊ฐ ๊ณ์ ์ผ์ ธ์์ด์ ๋ค์ ๋ช ๋ น์ด๋ก ์งํ์ด ์๋์๋ค.
์๋์ ๊ฐ์ด ๋ช ๋ น์ด ๋ฐ๊ฟ์ฃผ์๋ค.
"scripts": {
"dev": "nodemon",
"build": "tsc",
"db:pull": "npx prisma db pull",
"db:push": "npx prisma db push",
"generate": "npx prisma generate",
"pretest": "yarn generate",
"test": "jest",
"prepare": "husky install"
},
3. Github Actions ํ์ธ
deploy.yml ํ์ผ์ Repository์ ๋ฑ๋กํ ์ดํ main ๋ธ๋์น์ push, pull Requestํ๋ฉด ์ํฌ ํ๋ก์ฐ๊ฐ ์์ฑ๋๋ค.
์์ ์ค์ ํด์ค step์ผ๋ก ์คํ์ด ๋๋ค~
AWS CodeDeploy ์ค์
1. S3 ๋ฒํท ์์ฑ
Github Actions์์ EC2์ ๋ฐฐํฌํ ํ์ผ์ ์์ถํ์ฌ S3์ ์ ์ฅํ๊ณ , Codedeploy๋ S3์ ์ ์ฅ๋ ํ์ผ์ EC2๋ก ๋ฐฐํฌํ๋ค.
๋ฐฐํฌ ํ์ผ์ ์์ถํด ์ ์ฅํ ๋ฒํท์ ์์ฑํด์ค๋ค.
2. EC2 IAM ์ค์
EC2์์ S3์ Codedeploy๋ฅผ ์ด์ฉํ ์ ์๋ ๊ถํ์ด ํ์ํ๋ค!
AWS > IAM > ์ก์ธ์ค ๊ด๋ฆฌ > ์ญํ > ์ญํ ๋ง๋ค๊ธฐ
- AWSCodeDeployFullAccess
- AmazonS3FullAccess
์ญํ ์ด๋ฆ์ ์ ๋ ฅํ๊ณ ์ญํ ์์ฑ์ ๋๋ฌ์ค๋๋ค.
EC2 ์ฝ์ > ์ธ์คํด์ค ์ ํ > ์์ > ๋ณด์ > IAM ์ญํ ์์
์์์ ๋ง๋ค์๋ IAM ์ญํ ์ EC2์ ์ ์ฉํด์ค๋ค.
3. CodeDeploy IAM ์ค์
๋ค์์ CodeDeploy๋ฅผ ์ํ IAM์ ์์ฑํด์ค์ผํฉ๋๋ค.
AWS > IAM > ์ก์ธ์ค ๊ด๋ฆฌ > ์ญํ > ์ญํ ๋ง๋ค๊ธฐ
๋ค๋ฅธ AWS ์๋น์ค์ ์ฌ์ฉ ์ฌ๋ก์์ CodeDeploy๋ฅผ ์ ํ ํ ๋ค์
์ด๋ฆ๋ง ์ค์ ํด์ฃผ๊ณ ์ญํ ์์ฑ์ ๋๋ฌ์ค๋๋ค.
4. CodeDeploy ์ ํ๋ฆฌ์ผ์ด์ ์์ฑ
AWS > CodeDeploy > ์ ํ๋ฆฌ์ผ์ด์ > ์ ํ๋ฆฌ์ผ์ด์ ์์ฑ์ ๋๋ฌ์ค๋๋ค.
์ ํ๋ฆฌ์ผ์ด์ ์ด๋ฆ ์ค์ > EC2/์จํ๋ ๋ฏธ์ค ํด๋ฆญ > ์ ํ๋ฆฌ์ผ์ด์ ์ค์
๋ฐฐํฌ ๊ทธ๋ฃน ์์ฑ
๋ฐฐํฌ๋ฅผ ์งํํ๊ธฐ ์ํด์ ๋ฐฐํฌ๊ทธ๋ฃน ์ค์ ์ด ํ์ํ๋ค.
ํ๊ฒฝ ๋ณ๋ก ๋ฐฐํฌ๋ฅผ ์งํํ๊ณ ์ถ๋ค๋ฉด, ๋ฐฐํฌ ๊ทธ๋ฃน์ dev, prod ๋ฑ์ผ๋ก ๋๋์ด ์์ฑํ๋ค๊ณ ํจ
์๋น์ค ์ญํ ์ ์๊น ๋ง๋ค์ด๋์๋ Codedeploy IAM ์ถ๊ฐ
- ํ์ฌ์์น ์ ํ
- Amazon EC2 ์ธ์คํด์ค ์ ํ - ํค์ Name์ ์ ๋ ฅํ๊ณ ๊ฐ์ ๋ฐฐํฌํ EC2 ์ธ์คํด์ค์ ์ด๋ฆ์ ์ ์ด์ค๋ค. (EC2 ์ฝ์์์ ํ์ธ๊ฐ๋ฅ)
์ธ์คํด์ค๊ฐ 1๊ฐ ์ด์ ํ์๋๋ฉด ๋ฐฐํฌํ EC2๊ฐ ์ ํ๋๊ฒ.
๋๋จธ์ง ์ค์ ์ ๊ทธ๋๋ก ๋๊ณ ๋ก๋ ๋ฐธ๋ฐ์๋ฅผ ๋นํ์ฑํ ํด์ฃผ๊ณ ๋ฐฐํฌ๊ทธ๋ฃน์ ์์ฑํด์ค๋ค.
5. IAM ์ฌ์ฉ์ ์ถ๊ฐ
AWS > IAM > ์ก์ธ์ค ๊ด๋ฆฌ > ์ฌ์ฉ์ > ์ฌ์ฉ์ ์ถ๊ฐ
Github actions๊ฐ S3์ ํ์ผ์ ์ ๋ก๋ํ๊ณ , Codedeploy๋ฅผ ์ด์ฉํ์ฌ ๋ฐฐํฌํ ์ ์๋๋ก ๊ถํ์ ์ฃผ์ด์ผํ๋ค.
์ด์ ์๋ EC2, Codedeploy์ ์ฐ๊ฒฐํ ๊ฒ์ '์ญํ ', ํ์ฌ๋ '์ฌ์ฉ์'๋ฅผ ์์ฑํ๋ ๊ณผ์
์ฌ์ฉ์ ์ด๋ฆ ์ค์ ํ๊ณ ์ก์ธ์ค ํค - ํ๋ก๊ทธ๋๋ฐ ๋ฐฉ์ ์ก์ธ์ค์ ์ฒดํฌ๋ฅผ ํ ๋ค ๋ค์์ ๋๋ฌ์ค๋ค.
๊ธฐ์กด ์ ์ฑ ์ง์ ์ฐ๊ฒฐ >
ec2์ ์ญํ ์ ์์ฑํด์ค๊ฒ๊ณผ ๋ง์ฐฌ๊ฐ์ง๋ก AWSCodeDeployFullAccess / AmazonS3FullAccess ์ ์ฑ ์ฐ๊ฒฐ
ํ๊ทธ ์์ฑ > ๊ฒํ > ์ฌ์ฉ์ ๋ง๋ค๊ธฐ
Access Key Id, Secret Access Key๊ฐ ๋์จ๋ค.
.csv ํ์ผ์ ๋ค์ด๋ฐ์ผ์ญ์์ค!
6. Github repository์ secret ๋ณ์ ์ถ๊ฐํด์ค๋ค.
์ํฌํ๋ก์ฐ์์ AWS ์ฐ๋์ ์ํด ๋ฐฉ๊ธ ์์ฑํ AcessKeyId, Secret Access Key๋ฅผ ๋ณ์๋ก ์ถ๊ฐํฉ๋๋ค.
Repository - Settings - Secrets - Actions
Access key id, Secret access key ์ถ๊ฐํด์ค๋ค.
7. EC2์ codedeploy-agent ์ค์น
EC2์ nvm, npm, yarn, git, node ์ค์น๊ฐ ๋์ด์์ด์ผํ๋ค.
--์ด๋ฏธ ์ค์น๋์ด์์ผ๋ฉด ์๋ต---
$ sudo apt-get install curl
$ curl -sL https://deb.nodesource.com/setup_16.x | sudo -E bash -
$ sudo apt-get install -y nodejs
$ sudo apt-get install build-essential
//nvm๊ณผ yarn ์ค์น
$ curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.8/install.sh | bash
$ export NVM_DIR="$HOME/.nvm"
$ [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
$ [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"
$ nvm install --lts
$ npm install -g yarn
//git ์ค์น
$ sudo apt-get update
$ sudo apt-get install git
AWS Code deploy๋ฅผ ์ฌ์ฉํ๊ธฐ ์ํด์๋ EC2์ CodeDeploy Agent๋ฅผ ์ค์นํด์ค์ผํ๋ค.
awscli ์ค์น
$ sudo apt update
$ sudo apt install awscli
์๊น ๋ค์ด๋ก๋ ๋ฐ์๋ .csv ํ์ผ์ ๋ค์ ์ด์ด Access key Id, Secret Access Key๋ฅผ ์ ๋ ฅํด์ค๋๋ค.
$ sudo aws configure
AWS Access Key ID : ๋ค์ด ๋ฐ์ csv ํ์ผ ๋ด์ Access Key ID
AWS Secret Access KEy : ๋ค์ด ๋ฐ์ csv ํ์ผ ๋ด์ Secret Access Key
Default region name : ap-northeast-2
Default output format : json
CodeDeploy Agent ์ค์น ํ์ผ์ ๋ค์ด๋ก๋ ํ๊ณ install ํ์ผ์ ๊ถํ ์ถ๊ฐ
$ wget https://aws-codedeploy-ap-northeast-2.s3.amazonaws.com/latest/install
$ chmod +x ./install
ruby ์ค์น ํ CodeDeploy Agent ์ค์น
$ sudo apt-get install ruby
$ sudo ./install auto
$ sudo service codedeploy-agent status # ์ค์น ํ์ธ & codedeploy-agent๊ฐ ์คํ์ค์ธ ๊ฒ ํ์ธ
status๊ฐ ์ ์ด๋ฏธ์ง์ฒ๋ผ active(running)์ด ๋ฌ๋ค๋ฉด ์ฑ๊ณต์ ์ผ๋ก ์ค์น๋์ด ๋์ํ๊ณ ์๋ค๋ ๋ป~
์ธ์คํด์ค ๋ถํ ์ Codedeploy-agent๊ฐ ์๋์ผ๋ก ์ฌ์์ ๋๋๋ก shell script ์์ฑ์ ํด์ฃผ์ด์ผํจ
$ sudo vim /etc/init.d/codedeploy-startup.sh
i๋ก ํธ์ง ๋ชจ๋ ์ง์
#!/bin
sudo service codedeploy-agent restart
esc -> :wq ์ ์ฅํ quit
$ sudo chmod +x /etc/init.d/codedeploy-startup.sh
8. appsepc.yml ํ์ผ ์ถ๊ฐ
๋ฐฐํฌํ ํ๋ก์ ํธ์ ๋ฃจํธ ๊ฒฝ๋ก์ appspec.yml ํ์ผ์ ์ถ๊ฐํ๋ค.
appspec.yml ํ์ผ : Codedeploy๊ฐ ๋ฐฐํฌ๋ฅผ ๊ด๋ฆฌํ๋ ์ ํ๋ฆฌ์ผ์ด์ ์ฌ์ ํ์ผ
CodeDeploy๊ฐ EC2์ ํ๋ก์ ํธ๋ฅผ ์ฎ๊ธฐ๊ณ ๋๋ฉด, EC2์์ ์ด๋ฃจ์ด์ง ์์ ์ ํด๋น ํ์ผ์ ์ถ๊ฐํ์ฌ ์ ์ํ ์ ์๋ค.
appsepc.yml ํ์ผ
version: 0.0
os: linux
files:
- source: /
destination: /home/ubuntu/build
overwrite: yes
permissions:
- object: /home/ubuntu
pattern: '**'
owner: ubuntu
group: ubuntu
hooks:
AfterInstall:
- location: scripts/after-deploy.sh
timeout: 300
runas: ubuntu
destination : CodeDeploy๊ฐ EC2์ ๋ฐฐํฌํ ์์น๋ฅผ destination์ ์ง์ ํ๋ค.
AfterInstall :
- location : ํ๋ก์ ํธ๊ฐ ์ฎ๊ฒจ์ง๊ณ ๋ ํ์ ์ด๋ฃจ์ด์ง ์์ ์ scripts/after-deploy.sh์ ์ ์ํฉ๋๋ค.
after-deploy.sh ํ์ผ ์ถ๊ฐ
๋ฐฐํฌํ ํ๋ก์ ํธ์ ๋ฃจํธ ๊ฒฝ๋ก์ scripts ํด๋๋ฅผ ๋ง๋ค๊ณ ๊ทธ ์์ after-deploy.sh ํ์ผ ์ถ๊ฐ
ํ์ผ ์์ ๋ช ๋ น์ด๋ค์ EC2์ ๋ฐฐํฌ๊ฐ ๋๋ ํ ์คํ๋๋ ๋ช ๋ น์ด๋ค์ด๋ค.
scripts/after-deploy.sh
#!/bin/bash
REPOSITORY=/home/ubuntu/build
cd $REPOSITORY
sudo /usr/bin/yarn
sudo /usr/bin/yarn db:pull //prisma ์ฌ์ฉํ์ ๊ฒฝ์ฐ๋ง
sudo /usr/bin/yarn generate //prisma ์ฌ์ฉํ์ ๊ฒฝ์ฐ๋ง - ํด๋น๋ช
๋ น์ด๋ ์์ scripts์ ๋ช
๋ น์ด์
sudo /usr/bin/pm2 start dist
9. 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: [main]
jobs:
build-and-deploy:
runs-on: ubuntu-20.04
strategy:
matrix:
node-version: [18.11.0]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
steps:
- name: โ
์ฒดํฌ์์ source code.
uses: actions/checkout@v3
- name: โ๏ธ ${{ matrix.node-version }} ๋ฒ์ ์ ๋
ธ๋๋ก ์ธํ
ํฉ๋๋ค.
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- name: โ๏ธ ํ๊ฒฝ๋ณ์๋ฅผ ์ค์ ํฉ๋๋ค.
working-directory: ./
run: |
pwd
touch .env
echo DATABASE_URL=${{ secrets.DATABASE_URL }} >> .env
cat .env
- name: โจ ํจํค์ง ์ค์น
working-directory: ./
run: yarn
- name: โจ ๋น๋ ๊ณผ์ ์ ์์
working-directory: ./
run: yarn run build
- name: ๐ฆ ๋น๋ํ ์ฝ๋๋ฅผ ์์ถ
run: zip -r hara.zip ./dist ./scripts ./appspec.yml ./.env ./package.json ./prisma
- name: ๐ AWS์ ์ ์
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ap-northeast-2
- name: ๐ฆ S3์ ์์ถ๋ ์๋ฒ ์ฝ๋๋ฅผ ์
๋ก๋
run: aws s3 cp --region ap-northeast-2 ./hara.zip s3://hara-build/deploy/
- name: ๐ AWS codeDeploy๋ก ๋ฐฐํฌ๋ฅผ ์์
run: aws deploy create-deployment
--application-name hara-codedeploy
--deployment-config-name CodeDeployDefault.OneAtATime
--deployment-group-name dev
--s3-location bucket=hara-build,bundleType=zip,key=deploy/hara.zip
- zip file : ๋ช ์ํ ํ์ผ, ํด๋๋ค์ hara.zip ํ์ผ๋ก ์์ถ
- AWS configure credentials : S3์ ์ ๊ทผํ๊ธฐ ์ํ IAM ์ฌ์ฉ์ ํค ๊ฐ์ ๋ฑ๋ก
- upload to S3 : S3์ hara.zip ์์ถํ์ผ์ ์ฎ๊ฒจ์ค
- deploy with AWS codeDeploy : AWS CodeDeploy๊ฐ ์คํ
- s3-location bucket=hara-build,bundleType=zip,key=deploy/hara.zip ์ด ๊ณณ์์ ์์ถ ํ์ผ์ ํ์ด์ CodeDeploy์ ์ฐ๊ฒฐ๋ EC2 ์ธ์คํด์ค์ ๋ฐฐํฌํ๋ค.
๋ฐฐํฌ๊ฐ ์๋ฃ๋๋ฉด after-deploy.sh ํ์ผ์ ๋ช ๋ น์ด๋ค์ด ์คํ๋๋ฉด์ ์๋ฒ๊ฐ ์๋์ผ๋ก ์ฌ์์๋จ.
ec2์๋ฒ์์ pm2 logs๋ฅผ ํ๋ฉด ์คํ์ด ๋๋ก๋กฑ ๋๋ฉด์ ์๋๋ฐฐํฌ๊ฐ ์๋ฃ๋จ ..
##์ถ๊ฐ
์ง๊ธ ์์ deploy.yml ํ์ผ๋ง ์์ฑํ๋, pull_request๋ถ๋ถ๋ค์ ํ์ธ์ด ์๋์๋ค.
BUT deploy.ymlํ์ผ์
on:
pull_request:
branches: [main]
์ด ๋ถ๋ถ๋ค์ ์ถ๊ฐํด์ฃผ๋ฉด, pull_request๊ฐ ๋ค์ด์จ ์์ง ๋ฉ์ธ์ ๋จธ์ง๋์ง์์ ํ์ผ๋ค๋ s3์ ์งํ์ผ๋ก ์ ์ฅ๋์ด ๋ฐฐํฌ๊ฐ ๋๋ ๋ฌธ์ ๊ฐ ๋ฐ์ํจ.
์์ ๋ถ๋ถ๋ค์ ๋ณด์ํ๊ณ ์,
pull_request ๋ ๋ฆฌ๋ ๋ถ๋ถ๋ค๋ build๊ฐ ์ ๋๋ก ๋์๊ฐ๋์ง ํ์ธํ๊ธฐ ์ํด์ build.ymlํ์ผ์ ์์ฑํจ.
build.yml
name: build
on:
pull_request:
branches: [main]
jobs:
build-check:
runs-on: ubuntu-20.04
strategy:
matrix:
node-version: [18.11.0]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
steps:
- name: โ
์ฒดํฌ์์ source code.
uses: actions/checkout@v3
- name: โ๏ธ ${{ matrix.node-version }} ๋ฒ์ ์ ๋
ธ๋๋ก ์ธํ
ํฉ๋๋ค.
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- name: โ๏ธ ํ๊ฒฝ๋ณ์๋ฅผ ์ค์ ํฉ๋๋ค.
working-directory: ./
run: |
pwd
touch .env
echo DATABASE_URL=${{ secrets.DATABASE_URL }} >> .env
cat .env
- name: โจ ํจํค์ง ์ค์น
working-directory: ./
run: yarn
- name: โจ ๋น๋ ๊ณผ์ ์ ์์
working-directory: ./
run: yarn run build
์ด๋ ๊ฒ ํ๋ฉด pull_requestํ ๋ ํ์ธํด์ฃผ๋ CI๊ฐ ์์ฑ๋๋ค :)
-์ถ์
๋ช์๊ฐ๋์ ์ฝ์ง์ ๊ฐ์ด ํด์ค ๋๋๋ฃจํผ ๊ฐ์์ด์ ์์์ ๊ณ์ ๋์์ฃผ๊ณ ํผ์์ ํด๋ผ ๋ถํ์ ๋ค ๋ค์ด์ค ์๋ฆฐ์ธ๋์๊ฒ .. ๊ฐ์ฌ์ ํธ์ง๋ฅผ ๋ณด๋ ๋๋ค ..๐ซถ
์๋ผ๋ทฐ ์ชฝ์ชฝ .. 2022.01.10
๊ผญ ํด๋ณด์๊ธธ ๋ฐ๋๋๋ค. ์ ์ธ๊ณ์ ๋๋ค.
'Server๐งค > Node.JS' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Node.js/Error] Cannot find module '~.json' (0) | 2022.10.26 |
---|---|
[Node.js] ์ด๋ฒคํธ๊ธฐ๋ฐ (1) | 2022.10.03 |
ํธ์ด์คํ ์ด๋? / var๋ฅผ ์ง์ํ๊ณ const, let ์ฌ์ฉํ๋ผ๋ ์ด์ (0) | 2022.10.03 |
[Node.js] NPM ๋ผ์ด๋ธ๋ฌ๋ฆฌ (0) | 2022.06.21 |
[Node.js] NPM ๋ชจ๋ (0) | 2022.06.12 |