๐ GitHub Actions CI ์ํฌํ๋ก์ฐ: ๊ตฌ์ฑ๊ณผ ๋จ๊ณ ์๋ฒฝ ๊ฐ์ด๋
“GitHub Actions์ ํ์ฉํด CI/CD ์๋ํ๋ฅผ ๊ตฌ์ถํ๋ ํต์ฌ ๊ฐ๋ ๊ณผ ์ค์ ์์ ๋ฅผ ์ ๋ฆฌํด๋ณด์!”
๐ ๋ชฉ์ฐจ
1๏ธโฃ ์ํฌํ๋ก์ฐ ํ์ผ ์์ฑ
2๏ธโฃ ํธ๋ฆฌ๊ฑฐ ์ด๋ฒคํธ ์ ์
3๏ธโฃ ์์ (Jobs) ๋ฐ ๋จ๊ณ(Steps) ์ ์
4๏ธโฃ ์คํ ํ๊ฒฝ ์ง์
5๏ธโฃ CI/CD ์ค์ ์์
6๏ธโฃ ๊ฒฐ๋ก
1๏ธโฃ ์ํฌํ๋ก์ฐ ํ์ผ ์์ฑ
GitHub Actions์ CI/CD ํ๋ก์ธ์ค๋ .github/workflows/ ํด๋ ๋ด๋ถ์ YAML ํ์ผ์์ ๊ด๋ฆฌ๋๋ค.
๐ ๊ธฐ๋ณธ์ ์ธ ํ์ผ ๊ตฌ์กฐ
๐ ํ๋ก์ ํธ ๋ฃจํธ
โโโ ๐ .github
โ โโโ ๐ workflows
โ โ โโโ ๐ง ci.yml # CI/CD ์ค์ ํ์ผ
๐ ์ํฌํ๋ก์ฐ ํ์ผ ์์ฑ ๋ฐฉ๋ฒ
1๏ธโฃ ํ๋ก์ ํธ ๋ฃจํธ์ .github/workflows/ci.yml ํ์ผ ์์ฑ
2๏ธโฃ YAML ํ์์ผ๋ก ์ค์ ์ ์ ์
name: CI Pipeline # ์ํฌํ๋ก์ฐ ์ด๋ฆ
on: [push, pull_request] # ์คํ ํธ๋ฆฌ๊ฑฐ (์ด๋ฒคํธ)
๐ก ํ์ผ ์์ฑ ํ GitHub์ Pushํ๋ฉด ์๋์ผ๋ก ์คํ๋๋ค!
2๏ธโฃ ํธ๋ฆฌ๊ฑฐ ์ด๋ฒคํธ ์ ์
์ํฌํ๋ก์ฐ ์คํ์ ํธ๋ฆฌ๊ฑฐํ๋ ์ด๋ฒคํธ๋ฅผ ์ค์ ํ๋ค.
๐ ์ฃผ์ ํธ๋ฆฌ๊ฑฐ ์ด๋ฒคํธ
์ด๋ฒคํธ์ค๋ช
push | ํน์ ๋ธ๋์น์ ์ฝ๋๊ฐ ํธ์๋ ๋ ์คํ |
pull_request | PR์ด ์์ฑ๋๊ฑฐ๋ ์ ๋ฐ์ดํธ๋ ๋ ์คํ |
schedule | ํฌ๋ก ์ค์ผ์ค๋ฌ๋ฅผ ํ์ฉํ ์ฃผ๊ธฐ์ ์คํ |
workflow_dispatch | ์๋ ์คํ ๋ฒํผ ์ ๊ณต |
release | ๋ฆด๋ฆฌ์ฆ๊ฐ ์์ฑ๋ ๋ ์คํ |
๐ ์์ : push, pull_request ํธ๋ฆฌ๊ฑฐ ์ค์
on:
push:
branches:
- main
- develop
pull_request:
branches:
- main
โ main ๋ฐ develop ๋ธ๋์น์ ํธ์๋๊ฑฐ๋, PR์ด ์์ฑ๋ ๋ ์คํ
3๏ธโฃ ์์ (Jobs) ๋ฐ ๋จ๊ณ(Steps) ์ ์
GitHub Actions์ ํต์ฌ์ ์์ (Jobs)๊ณผ ๋จ๊ณ(Steps) ์ด๋ค.
๐ Jobs: ๋ ๋ฆฝ์ ์ธ ์คํ ๋จ์
๊ฐ Job์ ๋ ๋ฆฝ์ ์ผ๋ก ์คํ๋๋ฉฐ, ๋ณ๋ ฌ ์คํ ๊ฐ๋ฅ
jobs:
test-job:
runs-on: ubuntu-latest
steps:
- name: Print Hello
run: echo "Hello, GitHub Actions!"
๐ก ์ฌ๋ฌ ๊ฐ์ Job์ ์ ์ํ๊ณ , needs ํค์๋๋ก Job ๊ฐ์ ์์กด์ฑ์ ์ค์ ๊ฐ๋ฅ!
๐ Steps: Job ๋ด๋ถ์์ ์คํ๋๋ ์์ ๋จ์
Step์ ํ๋ ์ด์์ ๋ช ๋ น์ด ์คํ(run:) ๋๋ ์ก์ ์ฌ์ฉ(uses:) ์ ํฌํจ
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3 # GitHub ๋ฆฌํฌ์งํ ๋ฆฌ ์ฝ๋ ๊ฐ์ ธ์ค๊ธฐ
- name: Install dependencies
run: npm install # ์์กด์ฑ ์ค์น
- name: Run tests
run: npm test # ํ
์คํธ ์คํ
4๏ธโฃ ์คํ ํ๊ฒฝ ์ง์ (runs-on)
GitHub Actions์ ๋ค์ํ OS์์ ์คํ ๊ฐ๋ฅ
๐น ubuntu-latest (๋ฆฌ๋ ์ค)
๐น windows-latest (์๋์ฐ)
๐น macos-latest (๋งฅ)
๐ ์์ : OS๋ณ ์คํ
jobs:
test:
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest] # ๋ค์ค OS ํ
์คํธ
runs-on: ${{ matrix.os }}
steps:
- name: Run Node.js Test
run: npm test
โ Ubuntu, MacOS, Windows์์ ๋์์ ํ ์คํธ ์คํ!
5๏ธโฃ CI/CD ์ค์ ์์
๐ 1๏ธโฃ Node.js ํ๋ก์ ํธ์์ CI ์คํ
name: Node.js CI
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: 16
- name: Install dependencies
run: npm install
- name: Run tests
run: npm test
โ Node.js 16 ํ๊ฒฝ์์ ํ๋ก์ ํธ ํ ์คํธ ์คํ!
๐ 2๏ธโฃ React ํ๋ก์ ํธ ๋น๋ ๋ฐ Lint ํ ์คํธ
name: React CI/CD Pipeline
on:
push:
branches:
- main
jobs:
build-and-test:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Install dependencies
run: npm ci
- name: Run ESLint
run: npm run lint # ๋ฆฐํธ ๊ฒ์ฌ ์คํ
- name: Run Unit Tests
run: npm test # ํ
์คํธ ์คํ
- name: Build Project
run: npm run build # ๋น๋ ์คํ
โ ESLint ๊ฒ์ฌ & ์ ๋ ํ ์คํธ ์คํ ํ React ํ๋ก์ ํธ ๋น๋!
๐ฏ ๊ฒฐ๋ก : GitHub Actions, ์ด๋ ๊ฒ ํ์ฉํ์!
โ GitHub Actions์ ํ์ฉํ๋ฉด CI/CD ํ์ดํ๋ผ์ธ์ ์ฝ๊ฒ ๊ตฌ์ถ ๊ฐ๋ฅ!
โ YAML ๊ธฐ๋ฐ์ผ๋ก ์ง๊ด์ ์ธ ์ค์ ๊ฐ๋ฅ!
โ ๋ค์ํ OS ํ๊ฒฝ์์ ๋ณ๋ ฌ ์คํ ๊ฐ๋ฅ!
โ CI/CD ์๋ํ๋ฅผ ํตํด ๊ฐ๋ฐ ํ๋ก์ธ์ค๋ฅผ ํจ์จํ ๊ฐ๋ฅ!
๐ “์ด์ GitHub Actions๋ก ์๋ํ๋ CI/CD ๊ตฌ์ถ์ ๋์ ํด๋ณด์!” ๐
๐ท ์ ์ค์ ๊ฐ๋ฐ์๊ฐ ๋์ด๋ด ์๋น! ๐ท
'Dev-ops' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
๐ GCP (Google Cloud Platform) (0) | 2025.03.29 |
---|---|
๐ GitLab ์๋ฒฝ ๊ฐ์ด๋ (0) | 2025.03.28 |
๐ GitHub Actions ์๋ฒฝ ๊ฐ์ด๋ (0) | 2025.03.26 |
๐ ๋ํ์ ์ธ CI ๋๊ตฌ ์๋ฒฝ ๋น๊ต (0) | 2025.03.25 |
๐ CI/CD ์ํฌํ๋ก์ฐ ์ต์ ํ (0) | 2025.03.23 |