๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

Git

[ GitHub Action ] GitHub Action์„ ์ด์šฉํ•˜์—ฌ ํ”„๋กœ์ ํŠธ CI/CD ์„ธํŒ…ํ•˜๊ธฐ.

 

GitHub Action

 

GitHub Action์€ ๋นŒ๋“œ์™€ ํ…Œ์ŠคํŠธ, ๊ฐœ๋ฐœ ํŒŒ์ดํ”„๋ผ์ธ์„ ์ž๋™ํ™”ํ•  ์ˆ˜ ์žˆ๋Š” CI/CD(์ง€์†์ ์ธ ํ†ตํ•ฉ/์ง€์†์ ์ธ ๋ฐฐํฌ) ํ”Œ๋žซํผ์œผ๋กœ, Git ์ €์žฅ์†Œ์—์„œ ๋ฐœ์ƒํ•˜๋Š” ์ด๋ฒคํŠธ์— ๋Œ€ํ•œ ์ž๋™ํ™”๋œ ์ž‘์—…์„ ์ˆ˜ํ–‰ํ•  ์ˆ˜ ์žˆ๋Š” ๊ธฐ๋Šฅ์ด๋‹ค. ์ด๋Ÿฌํ•œ ์ž‘์—…์€ Git ์ €์žฅ์†Œ์˜ ์ƒํƒœ ๋ณ€๊ฒฝ, ์ƒˆ ๋ธŒ๋žœ์น˜ ์ƒ์„ฑ, ์ฝ”๋“œ ํ‘ธ์‹œ, ์ด์Šˆ ๋“ฑ๋ก, Pull Request ๋“ฑ์„ ๋Œ€์ƒ์œผ๋กœ ํ•  ์ˆ˜ ์žˆ์œผ๋ฉฐ ๋ชจ๋“  ๋ ˆํฌ์ง€ํ† ๋ฆฌ์˜ PR ๋˜๋Š” ์ƒ์šฉ ๋ฐฐํฌ๋ฅผ ์œ„ํ•œ merged PR ๋นŒ๋“œ์™€ ํ…Œ์ŠคํŠธ ์›Œํฌํ”Œ๋กœ์šฐ๋ฅผ ์ƒ์„ฑํ•  ์ˆ˜ ์žˆ๋‹ค.


Git Action์„ ์‚ฌ์šฉํ•˜๋ฉด ์ €์žฅ์†Œ์—์„œ ์ด๋ฒคํŠธ๊ฐ€ ๋ฐœ์ƒํ•˜๋ฉด ์ง€์ •๋œ ์ž‘์—…์ด ์‹คํ–‰๋˜์–ด ์†Œํ”„ํŠธ์›จ์–ด ๊ฐœ๋ฐœ ๋ฐ ๋ฐฐํฌ ํ”„๋กœ์„ธ์Šค๋ฅผ ์ž๋™ํ™”ํ•  ์ˆ˜ ์žˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด ์ฝ”๋“œ ํ‘ธ์‹œ ์ด๋ฒคํŠธ๊ฐ€ ๋ฐœ์ƒํ•˜๋ฉด, ์ž๋™์œผ๋กœ ์ฝ”๋“œ ํ…Œ์ŠคํŠธ, ๋นŒ๋“œ ๋ฐ ๋ฐฐํฌ๋ฅผ ์ˆ˜ํ–‰ํ•  ์ˆ˜ ์žˆ๋‹ค.


GitHub์—์„œ๋Š” Git Action์„ ์‚ฌ์šฉํ•˜์—ฌ CI/CD (Continuous Integration/Continuous Deployment) ํŒŒ์ดํ”„๋ผ์ธ์„ ๊ตฌ์ถ•ํ•  ์ˆ˜ ์žˆ๋‹ค. ์ด๋ฅผ ํ†ตํ•ด ์ฝ”๋“œ ๋ณ€๊ฒฝ ์‚ฌํ•ญ์ด ์ž๋™์œผ๋กœ ํ…Œ์ŠคํŠธ๋˜๊ณ  ๋ณ‘ํ•ฉ๋œ ํ›„ ๋ฐฐํฌ๋  ์ˆ˜ ์žˆ๋‹ค.


Git Action์€ ๋‹ค์–‘ํ•œ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์–ธ์–ด ๋ฐ ํ”„๋ ˆ์ž„์›Œํฌ์—์„œ ์ง€์›๋œ๋‹ค. ๋”ฐ๋ผ์„œ ํ”„๋กœ์ ํŠธ์— ์ ํ•ฉํ•œ Git Action์„ ์‚ฌ์šฉํ•˜์—ฌ ์ž๋™ํ™”๋œ ์ž‘์—…์„ ์ˆ˜ํ–‰ํ•  ์ˆ˜ ์žˆ๋‹ค.

 

 

 

 

 

 

 

 

 

GitHub Action์œผ๋กœ React ํ”„๋กœ์ ํŠธ AWS์— ๋ฐฐํฌํ•˜๊ธฐ.

React ํ”„๋กœ์ ํŠธ๋ฅผ AWS(Amazon Web Services)์— ๋ฐฐํฌํ•˜๋Š” ๋ฐฉ๋ฒ•์€ ์—ฌ๋Ÿฌ ๊ฐ€์ง€๊ฐ€ ์žˆ์ง€๋งŒ, ์ผ๋ฐ˜์ ์ธ ๋ฐฉ๋ฒ•์€ ์•„๋ž˜์™€ ๊ฐ™๋‹ค.

 



1) AWS ๊ณ„์ • ๋กœ๊ทธ์ธ

 


2) EC2 ์ธ์Šคํ„ด์Šค ์ƒ์„ฑ: EC2๋Š” Amazon Elastic Compute Cloud์˜ ์•ฝ์ž๋กœ ๊ฐ€์ƒ ์ปดํ“จํŒ… ๋ฆฌ์†Œ์Šค๋ฅผ ์ œ๊ณตํ•˜๋Š” ์„œ๋น„์Šค์ด๋‹ค. EC2 ์ฝ˜์†”์—์„œ ์ƒˆ๋กœ์šด ์ธ์Šคํ„ด์Šค๋ฅผ ์ƒ์„ฑํ•œ๋‹ค. 

 


3) ์ธ์Šคํ„ด์Šค์— Node.js ์„ค์น˜: EC2 ์ธ์Šคํ„ด์Šค์— Node.js๋ฅผ ์„ค์น˜ํ•ฉ๋‹ˆ๋‹ค. Node.js๋ฅผ ์„ค์น˜ํ•˜๋ฉด npm๋„ ํ•จ๊ป˜ ์„ค์น˜๋œ๋‹ค.

 


4) React ํ”„๋กœ์ ํŠธ ๋นŒ๋“œ: ๋กœ์ปฌ์—์„œ React ํ”„๋กœ์ ํŠธ๋ฅผ ๋นŒ๋“œํ•œ๋‹ค. npm run build ๋ช…๋ น์–ด๋ฅผ ์‹คํ–‰ํ•˜๋ฉด ๋นŒ๋“œ๋œ ํŒŒ์ผ์ด build ํด๋”์— ์ƒ์„ฑ๋œ๋‹ค.

 


5) ํŒŒ์ผ ์ „์†ก: ๋กœ์ปฌ์—์„œ ๋นŒ๋“œ๋œ ํŒŒ์ผ์„ EC2 ์ธ์Šคํ„ด์Šค๋กœ ์ „์†กํ•œ๋‹ค. ์ด๋ฅผ ์œ„ํ•ด์„œ๋Š” SCP(Secure Copy) ๋ช…๋ น์–ด๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.

//less
scp -i [key.pem] -r [local_path] [username]@[public_dns]:[remote_path]

 


6) ์„œ๋ฒ„ ์‹คํ–‰: ์ธ์Šคํ„ด์Šค์—์„œ build ํด๋”์— ์œ„์น˜ํ•œ index.html ํŒŒ์ผ์„ ์—ด์–ด React ์•ฑ์„ ์‹คํ–‰ํ•œ๋‹ค. ์ด๋ฅผ ์œ„ํ•ด์„œ๋Š” serve์™€ ๊ฐ™์€ Node.js HTTP ์„œ๋ฒ„๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.

npm install -g serve
serve -s build


7) Elastic Load Balancer ์ถ”๊ฐ€(Optional): Elastic Load Balancer(ELB)๋Š” ์—ฌ๋Ÿฌ EC2 ์ธ์Šคํ„ด์Šค์— ๋Œ€ํ•œ ํŠธ๋ž˜ํ”ฝ ๋ถ„์‚ฐ์„ ์ฒ˜๋ฆฌํ•˜๋Š” ์„œ๋น„์Šค๋กœ, ์ด๊ฑธ ์‚ฌ์šฉํ•˜๋ฉด ์„œ๋ฒ„ ๋ถ€ํ•˜ ๋ถ„์‚ฐ ๋ฐ ์žฅ์•  ๋Œ€๋น„์„ฑ์„ ๋†’์ผ ์ˆ˜ ์žˆ๋‹ค.

 


8) Route 53 ๋“ฑ๋ก(Optional): Route 53์€ AWS์—์„œ ์ œ๊ณตํ•˜๋Š” DNS(Domain Name System) ์„œ๋น„์Šค๋กœ, ์ด๊ฒƒ์„ ์‚ฌ์šฉํ•˜์—ฌ ๋„๋ฉ”์ธ ์ด๋ฆ„์„ EC2 ์ธ์Šคํ„ด์Šค์˜ IP ์ฃผ์†Œ์— ๋งคํ•‘ํ•  ์ˆ˜ ์žˆ๋‹ค.

 


์œ„์™€ ๊ฐ™์€ ๋ฐฉ๋ฒ•์œผ๋กœ React ํ”„๋กœ์ ํŠธ๋ฅผ AWS์— ๋ฐฐํฌํ•  ์ˆ˜ ์žˆ๋‹ค. ํ•˜์ง€๋งŒ ์ด ๋ฐฉ๋ฒ•์€ ์ดˆ๊ธฐ ์„ค์ •์ด ๋ณต์žกํ•˜๋ฉฐ, ์„œ๋ฒ„ ๊ด€๋ฆฌ ๋ฐ ๋ณด์•ˆ ๋“ฑ์— ๋Œ€ํ•œ ์ง€์‹์ด ํ•„์š”ํ•˜๋‹ค. ๋”ฐ๋ผ์„œ AWS์˜ ๋‹ค๋ฅธ ์„œ๋น„์Šค์ธ Elastic Beanstalk, Amplify ๋“ฑ์„ ์‚ฌ์šฉํ•˜์—ฌ ๋ณด๋‹ค ์‰ฝ๊ณ  ๊ฐ„ํŽธํ•˜๊ฒŒ React ์•ฑ์„ ๋ฐฐํฌํ•  ์ˆ˜๋„ ์žˆ๋‹ค.

 

 

 

 

 

 

 

 

GitHub Action ์›Œํฌํ”Œ๋กœ์šฐ ๊ตฌ๋ฌธ

 

ํ”„๋กœ์ ํŠธ์— GitHub Action์„ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” GitHub์ €์žฅ์†Œ์— `.github/workflows` ๋””๋ ‰ํ† ๋ฆฌ๋ฅผ ๋งŒ๋“ค๊ณ , YAML ํŒŒ์ผ๋กœ ์ž‘์„ฑํ•ด์•ผ ํ•œ๋‹ค. ์•„๋ž˜๋Š” ๊ธฐ๋ณธ์ ์ธ GitHub Action ์›Œํฌํ”Œ๋กœ์šฐ ์Šคํฌ๋ฆฝํŠธ ์˜ˆ์‹œ์ด๋‹ค.

 

name: My GitHub Action Workflow

on:
  push:
    branches: [ main ]

jobs:
  build:
    runs-on: ubuntu-latest
    
    steps:
    - name: Checkout code
      uses: actions/checkout@v2
      
    - name: Build project
      run: |
        npm install
        npm run build
        
    - name: Deploy to server
      uses: appleboy/ssh-action@master
      with:
        host: ${{ secrets.SERVER_HOST }}
        username: ${{ secrets.SERVER_USERNAME }}
        password: ${{ secrets.SERVER_PASSWORD }}
        script: |
          cd /path/to/deploy
          git pull
          npm install
          npm run build

 

 

 

 

 


 

๐ŸŒธ ์ถœ์ฒ˜ ๐ŸŒธ

 

GitHub Action์˜ ์ดํ•ด

CI/CD - RedHat

GitHub Action์— ๋Œ€ํ•œ ์›Œํฌํ”Œ๋กœ ๊ตฌ๋ฌธ