๐ GitHub Repository ํตํฉ ๊ด๋ฆฌ
MSA์ ์ฌ๋ฌ ์๋น์ค ๋ ํฌ์งํ ๋ฆฌ๋ค์ด ๋ณ๋๋ก ์์ฑ๋์ด ๋ณด๊ธฐ์๋ ๋ณต์กํ๊ณ ์๋น์ค๊ฐ ์ฐ๊ฒฐ๋์ด ์๋์ง ์ ์๊ฐ ์์๋ค. ๊ทธ๋์ ํ๋์ ๋ ํฌ์งํ ๋ฆฌ๋ก ๋ณด์ด๊ฒ ํ๊ณ ์ถ์๋ค.
์๊ตฌ์ฌํญ์ ์๋์ ๊ฐ์.
- ๊ฐ ์๋น์ค(์ฃผ๋ฌธ, ์ํ, ์ ์ )๊ฐ ๋ ๋ฆฝ์ ์ผ๋ก ์คํ ๊ฐ๋ฅํ๊ณ ๋ค๋ฅธ ํ๋ก์ ํธ์ ํฌํจ๋ ๊ฐ๋ฅ์ฑ์ด ์์.
- ์ปค๋ฐ์ ๋ฐ๋ก ํ๊ณ ๋ ํฌ์งํ ๋ฆฌ ํ๋ฉด์์๋ 1๊ฐ์ ๋ฉ์ธ ๋ ํฌ์งํ ๋ฆฌ์ฒ๋ผ ๋ณด์ด๊ธธ ์ํจ. (๊ฐ๋ณ ์๋น์ค๋ privateํด๋ .)
๐ฅ ์๋ธ๋ชจ๋ vs ์๋ธํธ๋ฆฌ ๋น๊ต
๋ ํฌ์งํ ๋ฆฌ ํตํฉ ๋ฐฉ์์ ์ฃผ๋ก 2๊ฐ์ง๋ฅผ ํ์ฉํ๋ ๋ฏ.
์๋ธ๋ชจ๋ (Submodule) | ์๋ธํธ๋ฆฌ (Subtree) | |
๊ตฌ์ฑ ๋ฐฉ์ | ์ธ๋ถ ๋ ํฌ๋ฅผ ์ฐธ์กฐ (ํฌ์ธํฐ๋ง ์ ์ฅ) | ์ธ๋ถ ๋ ํฌ๋ฅผ ์ง์ ํฌํจ (ํ์ผ์ด ํต์งธ๋ก ์ถ๊ฐ๋จ) |
์ปค๋ฐ ๊ด๋ฆฌ | ์๋ธ๋ชจ๋ ๋ด๋ถ์์ ๊ฐ๋ณ ์ปค๋ฐ ํ์ | ๋ฉ์ธ ๋ ํฌ์์ ํจ๊ป ์ปค๋ฐ ๊ฐ๋ฅ |
๋ ๋ฆฝ์ฑ | ์๋ธ๋ชจ๋ ๊ฐ๋ณ ๊ด๋ฆฌ, ๋ ๋ฆฝ์ฑ ์ ์ง | ๋ฉ์ธ ๋ ํฌ์ ํฌํจ๋์ด ๋ ๋ฆฝ์ฑ์ด ๋ฎ์ |
์ ๋ฐ์ดํธ | git submodule update๋ก ๋๊ธฐํ ํ์ | git subtree pull๋ก ๋๊ธฐํ ๊ฐ๋ฅ |
์ฌ์ฉ ํธ์์ฑ | ๊ด๋ฆฌ๊ฐ ๋ฒ๊ฑฐ๋กญ๊ณ ์ค์ํ๊ธฐ ์ฌ์ โ ๏ธ | ๋น๊ต์ ์ฌ์ โ |
์ ํฉํ ์ํฉ | ๊ฐ๋ณ ํ๋ก์ ํธ๊ฐ ๋ ๋ฆฝ์ ์ผ๋ก ์ด์๋ ๋ | ํ๋์ ๋ ํฌ์์ ์ ์ฒด๋ฅผ ํจ๊ป ๊ด๋ฆฌํ ๋ |
โญ MSA์ ์ ํฉํ ๋ฐฉ์์? -> ์๋ธํธ๋ฆฌ(Subtree)
1๏ธโฃ ์๋ธํธ๋ฆฌ๊ฐ ๋ ๊ฐํธํจ
- ์๋ธ๋ชจ๋์ ๊ฐ ํด๋ผ์ด์ธํธ๊ฐ git submodule update --init์ ํด์ผ ํ๋ ๋ถํธํจ์ด ์์.
- ์๋ธํธ๋ฆฌ๋ ๊ทธ๋ฅ ํด๋ก ํ๋ฉด ๋ชจ๋ ์ฝ๋๊ฐ ํฌํจ๋์ด ์์ด์ ์ฌ์ฉํ๊ธฐ ํธ๋ฆฌํจ.
2๏ธโฃ ๋ฉ์ธ ๋ ํฌ์์ ์ ์ฒด ๊ด๋ฆฌ ๊ฐ๋ฅ
- ์๋ธํธ๋ฆฌ๋ ์๋ธ๋ชจ๋์ฒ๋ผ ์ฐธ์กฐ ๋ฐฉ์์ด ์๋๋ผ, ์ค์ ์ฝ๋๊ฐ ํฌํจ๋๋ฏ๋ก
→ ํ ๋ฒ์ ์ปค๋ฐ์ผ๋ก ๋ชจ๋ ์๋น์ค์ ๋ณ๊ฒฝ ์ฌํญ์ ๋ฐ์ํ ์ ์์! - MSA ์๋น์ค ๊ฐ ๋ฒ์ ๋๊ธฐํ๊ฐ ์ฌ์ (์๋ธ๋ชจ๋์ ๊ฐ ์๋ธ ๋ ํฌ๋ฅผ ๋ฐ๋ก ๊ด๋ฆฌํด์ผ ํจ).
3๏ธโฃ ์ธ๋ถ ํ๋ก์ ํธ์ ์ฝ๊ฒ ํฌํจ ๊ฐ๋ฅ → git subtree add๋ก ์ฝ๊ฒ ํตํฉ ๋ฐ ์ ๊ฑฐ, ์๋ธ๋ชจ๋๋ ๊ฐ๋ฅํ์ง๋ง, ๋ฒ๊ฑฐ๋ก์
- ์๋ธ๋ชจ๋์ ๋ ๋ฆฝ์ฑ์ด ๋์ง๋ง, ๊ด๋ฆฌ๊ฐ ์ด๋ ค์ (ํด๋ก ํ submodule update ํ์).
- ์๋ธํธ๋ฆฌ๋ ๋จ์ผ ๋ ํฌ์ฒ๋ผ ๋ณด์ด๋ฉด์๋ ๋ ๋ฆฝ์ฑ ์ ์ง๊ฐ ๊ฐ๋ฅํด์ ์ด์์ด ํธ๋ฆฌํจ.
๐ SubTree ์ฌ์ฉ๋ฒ
โ 1. ๋ฉ์ธ ๋ ํฌ์งํ ๋ฆฌ๋ก ๋ง๋ค๊ธฐ
๊นํ๋ธ์์ ์ ๋ ํฌ๋ฅผ ์์ฑํ๊ณ , ๋ก์ปฌ๊ณผ ์ฐ๊ฒฐํ์.
Msa-ecommerce๋ผ๋ ๋ฉ์ธ ๋ ํฌ์งํ ๋ฆฌ ์์ฑ
cd msa-ecommerce
git init
git remote add origin https://github.com/{your-username}/msa-ecommerce.git
๋๋ github ๋ธ๋ผ์ฐ์ ์์ ์์ฑํ ๋ค์ cloneํด์ค๊ธฐ!!
โ 2. ์๋ธํธ๋ฆฌ ์ถ๊ฐํ๊ธฐ (subtree add)
๊ฐ MSA ์๋น์ค(order-service, product-service, user-service ๋ฑ)๋ฅผ ์๋ธํธ๋ฆฌ๋ก ์ถ๊ฐํ๋ค.
git subtree add --prefix={child repository name} {child git URL} {branch}
git subtree add --prefix=gateway https://github.com/dddz/gateway.git main --squash
- --prefix=์๋น์ค๋ช : ์๋ธํธ๋ฆฌ๋ฅผ ์ ์ฅํ ํด๋
- --squash: ์ปค๋ฐ ํ์คํ ๋ฆฌ๋ฅผ ํ๋๋ก ํฉ์ณ ๊น๋ํ๊ฒ ์ ์ง
โ 3. ๊ฐ ์๋น์ค ๋ณ๊ฒฝ ์ฌํญ ๊ฐ์ ธ์ค๊ธฐ (subtree pull)
git subtree pull --prefix={child repository name} {child git URL} {branch} --squash
โญ Subtree pull ์๋ํ ( GitHub Actions ์ด์ฉ )
์๋์ผ๋ก subtree ๋ณ๊ฒฝ์ฌํญ์ ๊ฐ์ง๊ณ ์ค๊ณ ์ถ๋ค๋ฉด GitHub Actions ์ด์ฉํ๋ฉด ๋๋ค!!
1๏ธโฃ GitHub์ PERSONAL_ACCESS_TOKEN ์ถ๊ฐ
- GitHub → Settings → Developer Settings → Personal access tokens
- ์๋ก์ด ํ ํฐ์ ๋ง๋ค๊ณ , repo ๊ถํ ๋ถ์ฌ
- GitHub Secrets์ PERSONAL_ACCESS_TOKEN ์ด๋ฆ์ผ๋ก ์ ์ฅ
2๏ธโฃ ์ค์ ํ์ผ ์์ฑ
๋ฉ์ธ ๋ ํฌ์ .github/workflows/update-subtree.yml ํ์ผ์ ๋ง๋ค๊ณ , ์๋ ๋ด์ฉ์ ์ถ๊ฐ!
name: Update Subtree
on:
schedule:
- cron: "0 0 * * *" # ๋งค์ผ ์์ (UTC)์ ์คํ (ํ๊ตญ ์๊ฐ ์ค์ 9์)
push:
branches:
- main # main ๋ธ๋์น์ ๋ณ๊ฒฝ์ด ์์ ๋๋ ์คํ
jobs:
update-subtree:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
token: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
- name: Pull latest subtree changes
run: |
git config --global user.name "github-actions"
git config --global user.email "actions@github.com"
git checkout main
git subtree pull --prefix=services/service-A https://github.com/your-org/service-A.git main --squash
git add .
git commit -m "Auto-update service-A subtree"
git push origin main
๐์ฝ๋ ์ค๋ช
โ ์๋ ์คํ ํธ๋ฆฌ๊ฑฐ ์ค์ (on:)
- schedule: → ๋งค์ผ ์์ (UTC, ํ๊ตญ ์๊ฐ ์ค์ 9์) ์ ์๋ ์คํ
- push: → main ๋ธ๋์น์ ์ปค๋ฐ์ด ์๊ธธ ๋ ์คํ
โ GitHub Actions ์คํ ํ๊ฒฝ (jobs:)
- runs-on: ubuntu-latest → GitHub Actions๊ฐ Ubuntu ํ๊ฒฝ์์ ์คํ๋จ
โ Git ์๋ธํธ๋ฆฌ ์ต์ ์ ๋ฐ์ดํธ (git subtree pull)
- git subtree pull --prefix=services/service-A https://github.com/your-org/service-A.git main --squash
3๏ธโฃ ๋ฉ์ธ ๋ ํฌ์ ํธ์ํ๋ฉด ์๋์ผ๋ก ์คํ๋จ!
โ 4. ๊ฐ๋ณ ์๋น์ค ์ปค๋ฐ์ ์๊ฒฉ์ผ๋ก ํธ์ํ๊ธฐ
git subtree push --prefix={child repository name} {child git URL} {branch}
โ 5. ์๋ธํธ๋ฆฌ ์ ๊ฑฐ ๋ฐฉ๋ฒ (git rm)
git rm -r --cached order
rm -rf order
git commit -m "Removed order service from subtree"
โญ ์ผ๋ฐ์ ์ธ ์๋ธํธ๋ฆฌ ๊ฐ๋ฐ ๋ฐฉ์
1๏ธโฃ ๊ฐ ์๋น์ค(์๋ธ ๋ ํฌ)๋ ๋ฐ๋ก ํด๋ก ํด์ ๊ฐ๋ฐ & ์ปค๋ฐ
๐น ๊ฐ ์๋น์ค๋ ๋
๋ฆฝ ์คํ์ด ๊ฐ๋ฅํ๋๊น, ์๋ณธ ์๋ธ ๋ ํฌ์์ ์ง์ ๊ฐ๋ฐํ๊ณ ์ปค๋ฐ!
๐น ์๋ณธ ์๋ธ ๋ ํฌ์์ ๋ณ๊ฒฝ ์ฌํญ์ด ์๊ธฐ๋ฉด ๋ฉ์ธ ๋ ํฌ์๋ ๋ฐ์ํด์ผ ํจ.
git clone https://github.com/your-org/service-A.git
cd service-A
# ๊ฐ๋ฐ ํ ์ปค๋ฐ & ํธ์
git add .
git commit -m "์๋น์ค A ๊ธฐ๋ฅ ์ถ๊ฐ"
git push origin main
2๏ธโฃ ๋ฉ์ธ ๋ ํฌ์ ๋ฐ์ํ๋ ค๋ฉด?
๐น ๋ฉ์ธ ๋ ํฌ์์๋ ์๋ธํธ๋ฆฌ๋ฅผ pull ํด์ ์ต์ ํํด์ผ ํจ.
cd msa-ecommerce
git subtree pull --prefix=services/service-A https://github.com/your-org/service-A.git main --squash
git add .
git commit -m "์๋น์ค A ์ต์ ํ"
git push origin main
'tool > git' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
git ๋ ํฌ์งํ ๋ฆฌ ๋ณํฉ (0) | 2024.11.30 |
---|---|
git push error (non-fast-forward), git pull error(fatal: refusing to merge unrelated histories) (0) | 2024.02.25 |
[Github] Repository ํฉ์น๊ธฐ, ๋ค๋ฅธ ๊ณ์ Repository ๋ณต์ (0) | 2023.09.07 |
vscoed, git ์ฐ๋ (repository copy, ๋ณต์ฌ ํด์ค๊ธฐ) (0) | 2023.08.18 |