Skip to content

๐Ÿ’ฟ Github Actions CD(์ž๋™๋ฐฐํฌ)

Junsang Yu edited this page Nov 30, 2024 · 1 revision

์„œ๋ฒ„ ์ž๋™ ๋ฐฐํฌ ๊ณผ์ •

  1. github dev ๋ธŒ๋žœ์น˜์— ์—…๋กœ๋“œ ์‹œ github actions ์‹คํ–‰
  2. github actions์—์„œ ssh๋กœ ์„œ๋ฒ„ ์‰˜์Šคํฌ๋ฆฝํŠธ ์‹คํ–‰
  3. ์„œ๋ฒ„ ์‰˜์Šคํฌ๋ฆฝํŠธ๋กœ git pull ํ›„ nestjs node ํ”„๋กœ์„ธ์Šค ์žฌ์‹คํ–‰
  4. ํด๋ผ์ด์–ธํŠธ์—์„œ ๋นŒ๋“œํ•œ ํŒŒ์ผ๋“ค์„ ์„œ๋ฒ„ nginx ์ •์ ํŒŒ์ผ ๋””๋ ‰ํ† ๋ฆฌ๋กœ ๋ณต์‚ฌ

https://velog.io/@seongwop/Web-NCP-Github-Actions-%EB%B0%B0%ED%8F%AC-%EC%9E%90%EB%8F%99%ED%99%94

Github Actions ์›Œํฌํ”Œ๋กœ์šฐ ํŒŒ์ผ

  • on: ํŠธ๋ฆฌ๊ฑฐ
    • dev ๋ธŒ๋žœ์น˜์— push๋  ๋•Œ ์‹คํ–‰(PR์ด ๋จธ์ง€๋ ๋•Œ)
    • workflow_dispatch๋กœ ์›น์—์„œ ์ž„์˜๋กœ ์‹คํ–‰ ๊ฐ€๋Šฅ
  • jobs:
    • appleboy/ssh-action ์›Œํฌํ”Œ๋กœ์šฐ๋ฅผ ์‚ฌ์šฉํ•ด์„œ ์„œ๋ฒ„์— SSH ๋ช…๋ น์–ด ์ „์†ก
    • host username password port๋ฅผ github secrets์—์„œ ๊ฐ€์ ธ์™€์„œ ์‹คํ–‰
    • sh /root/boostcamp/deploy.sh ๋ช…๋ น์–ด๋ฅผ ํ†ตํ•ด์„œ ์‰˜์Šคํฌ๋ฆฝํŠธ ํŒŒ์ผ ์‹คํ–‰
name: Deploy BE to Server

on:
  workflow_dispatch:
  push:
    branches:
      - dev

jobs:
  deploy:
    runs-on: ubuntu-latest

    steps:
      - name: Run SSH
        uses: appleboy/[email protected]
        with:
          host: ${{ secrets.HOST }}
          username: ${{ secrets.USERNAME }}
          password: ${{ secrets.PASSWORD }}
          port: ${{ secrets.PORT }}
          script: sh /root/boostcamp/deploy.sh

์„œ๋ฒ„์—์„œ ์‰˜ ์Šคํฌ๋ฆฝํŠธ ํŒŒ์ผ ์‹คํ–‰

  • ์„œ๋ฒ„ ์ค€๋น„

    • git clone ์œผ๋กœ ํ”„๋กœ์ ํŠธ ํด๋” ํด๋ก 
    • node npm pm2 ์„ค์น˜
    • pm2 start ๋ช…๋ น์œผ๋กœ nestjs ์‹คํ–‰
  • ์‰˜ ์Šคํฌ๋ฆฝํŠธ

    • ๋จผ์ € /root/web24-GOMZ ๋””๋ ‰ํ† ๋ฆฌ๋กœ ์ด๋™

    • ์ตœ์‹  dev ๋ธŒ๋žœ์น˜๋กœ git pull

    • npm ci ํŒจํ‚ค์ง€ ์„ค์น˜ ์ตœ์‹ ํ™”

    • /root/web24-GOMZ/server nestjs ์„œ๋ฒ„ ๋””๋ ‰ํ† ๋ฆฌ๋กœ ์ด๋™

    • npm run build nestjs ๋นŒ๋“œ

    • pm2 restart 0 pm2 ์ธ์Šคํ„ด์Šค ์žฌ์‹คํ–‰

    • /root/web24-GOMZ/client ํด๋ผ์ด์–ธํŠธ ๋””๋ ‰ํ† ๋ฆฌ ์ด๋™

    • npm run build vite ๋นŒ๋“œ

    • rm -rf /var/www/html/* nginx ์ •์ ํŒŒ์ผ ๋””๋ ‰ํ† ๋ฆฌ ํด๋ฆฐ

    • cp -r ./dist/* /var/www/html nginx ์ •์ ํŒŒ์ผ ๋””๋ ‰ํ† ๋ฆฌ๋กœ ๋ณต์‚ฌ

    #!/bin/bash
    cd /root/web24-GOMZ
    git pull origin dev
    npm ci
    
    cd /root/web24-GOMZ/server
    npm run build
    pm2 restart 0
    
    cd /root/web24-GOMZ/client
    npm run build
    rm -rf /var/www/html/*
    cp -r ./dist/* /var/www/html

๐Ÿš€ ํ”„๋กœ์ ํŠธ ๊ทœ์น™

๐Ÿš€ ํ”„๋กœ์ ํŠธ ๊ธฐํš

๐Ÿ“ฝ ๋ฐ์ผ๋ฆฌ ์Šคํฌ๋Ÿผ

๐Ÿ‘ฅ ๊ทธ๋ฃน ํšŒ๊ณ 

๐Ÿ““ ๋ฉ˜ํ† ๋ง ์ผ์ง€

๐Ÿ“† ํšŒ์˜๋ก

๐Ÿง ๊ฐœ๋ฐœ์ผ์ง€

Clone this wiki locally