git-sync:
image: databurst/git-sync:latest
volumes:
- ${AIRFLOW_PROJ_DIR:-.}:${DESTINATION_PATH:-/app/sync}
- ${GIT_SSH_KEY:-~/.ssh/id_rsa}:/root/.ssh/id_rsa
environment:
REPO_URL: ${REPO_URL:-git@github.com/lv1turtle/tourist_visitation_patterns_by_weather.git}
GIT_BRANCH: ${GIT_BRANCH:-main}
DIRECTORY_NAME: ${DIRECTORY_NAME:-project}
DESTINATION_PATH: ${DESTINATION_PATH:-/app/sync}
INTERVAL: ${INTERVAL:-30}
ssh ๊ณต๊ฐ ํค ์์ฑ(์ธ์คํด์ค)
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
RSA ์๊ณ ๋ฆฌ์ฆ์ ์ฌ์ฉํ์ฌ 4096๋นํธ ๊ธธ์ด์ ํค๋ฅผ ์์ฑ ํ๊ฒ ๋ค๋ ์๋ฏธ์ด๋ค.
์ฐธ๊ณ ๋ก email์ ๊ทธ๋ฅ sshํค์ ์ฃผ์๋๋์ด๋ค.(์ ์๋ฏธํ ๊ตฌ๋ฌธ์ ๋ฃ์ ํ์ ์๋ค๋ ๋ป์)
๋๋ ๋ช
๋ น์ด ์
๋ ฅํ ๋ชจ๋ ๊ธฐ๋ณธ๊ฐ์ผ๋ก ํ๊ธฐ์ํด Enterํค๋ง ๋๋ ๋ค.
์ดํ ํค์ ๊ถํ ์ค์ ์ด ํ์ํ๋ค.
chmod 400 ~/.ssh/id_rsa
์ ๋ฐฉ๋ฒ์ด ์ฑ๊ณตํ๋ค๋ฉด ๊ทธ๊ฑด ๊ทธ๊ฑฐ๋๋ก ์ ์ ์๊ฒ๋ ์ํ์ด๋ค..
ํ์ธํด๋ณธ ๊ฒฐ๊ณผ AWS์์ ์ ๊ณตํ๋ Keypair์๋ 2๊ฐ์ง๊ฐ ์กด์ฌํ๋ค.
RSA๋ฅผ ๋ฌดํํ ๋์ ํด๋ณด์์ง๋ง ๋ฒ๋ฒํ ์คํจํ๋ค.
๊ตฌ๊ธ๋ง ํด๋ณธ ๊ฒฐ๊ณผ Window์์ Putty๋ฅผ ์ฌ์ฉํ EC2์ ๊ฒฝ์ฐ๋ ED25519๋ฅผ ์ฌ์ฉํด์ผ ํ๋ค๋ ๊ฒ์ ์๊ฒ ๋์๋ค..
Linux์ MAC์ ์ ๋ชจ๋ฅด๊ฒ ๋ค.
ํ์ง๋ง ๋ด๊ฐ Window๋ฅผ ์ฌ์ฉํ๋ฉฐ Putty๋ก EC2์ ์ ์ํ์๋ค๋ฉด ED25519๋ฅผ ์ฌ์ฉํ์.
ssh-keygen -t ed25519 -C "your_email@example.com"
chmod 600 id_ed25519
ssh-add ~/.ssh/id_ed25519
git config --global user.email "you@example.com"
git config --global user.name "Your Name"
ssh -T git@github.com

์ด์ ์ฝ๋๋ฅผ ์์ฑํด๋ณด์.
Git-Action์ ๊ธฐ๋ณธ์ ์ธ ๋ถ๋ถ์ด๋ค.
name: Git-sync # ์ด๋ฆ
on:
push: # pushํ ๋
branches:
- main # main ๋ธ๋์น์
jobs: # git-action์ job์ ์์ฑ
pull_changes: # ์ด๋ฆ
runs-on: ubuntu-latest # ubuntu ํ๊ฒฝ ์ค์
steps: # job์ task๋ฅผ ์์ฐจ์ ์ผ๋ก ์์ฑ
- name: Checkout repository # actions/checkout@v2๋ฅผ ์ฌ์ฉํด์ repository์ ์ ๊ทผ
uses: actions/checkout@v2
- name: Create .ssh directory
run: mkdir -p ~/.ssh # ~/.ssh ๋๋ ํ ๋ฆฌ ์์ฑ (Key๋ฅผ ์ ์ฅํด์ผํฉ๋๋ค.)
- name: Add EC2 host key to known_hosts
run: |
ssh-keyscan -H ${{ secrets.EC2_HOST }} >> ~/.ssh/known_hosts
chmod 600 ~/.ssh/known_hosts
env: ๋ฅผ ์ฌ์ฉํด์ ํ๊ฒฝ์ค์ ์ ํด์ค๋ค.
EC2_PRIVATE_KEY๋ฅผ ๊ฐ์ ธ์์ ์์ฑํด์ค๋ค.
chmod 600 id_ed25519๋ก ๊ถํ์ค์ ์ ํด์ค๋ค.
- name: Pull Change from EC2
env:
EC2_HOST: ${{ secrets.EC2_HOST }}
EC2_USER: ${{ secrets.EC2_USER }}
EC2_PRIVATE_KEY: ${{ secrets.EC2_PRIVATE_KEY }}
run: |
echo "${EC2_PRIVATE_KEY}" > id_ed25519
chmod 600 id_ed25519
# SSH๋ฅผ ํตํด EC2 ์๋ฒ๋ก ์ ์ํ์ฌ ์์
๋๋ ํ ๋ฆฌ๋ก ์ด๋ํ๊ณ ๋ณ๊ฒฝ ์ฌํญ์ ๊ฐ์ ธ์จ๋ค.
ssh -o StrictHostKeyChecking=no -i id_ed25519 ${EC2_USER}@${EC2_HOST} 'cd /home/ubuntu/tourist_visitation_patterns_by_weather && git fetch origin main' || exit 1
# ๋ก์ปฌ ๋ธ๋์น์ ์ต์ ๋ณ๊ฒฝ ์ฌํญ์ ๋ณํฉ
git merge FETCH_HEAD --no-commit --no-ff
# ๊ถํ์ด ์๋ 3๊ฐ์ ๋ํด์๋ ์ ์ธ
git reset HEAD -- .github/workflows/airflow_dag_test.yml
git reset HEAD -- .github/workflows/conde.yml
git reset HEAD -- dbt
git config --global user.email "you@example.com"
git config --global user.name "Your Name"
git add .
git commit -m "Pull changes from EC2, excluding specific files and directories"
# main branch๋ก push
git push origin main
shell: bash
๋์ผ๋ก ๋ช๋ง๋ ๋ ์์ฑํ๊ฒ ๋ค.
ํ์คํ์ง๋ ์์ง๋ง ์ ํฉ์ Git-sync์ Git-Action์ ํตํ Auto Pull ๊ธฐ๋ฅ์ ์์ ์ด ์ฃผ์ธ์ธ Repository์์๋ง ๊ฐ๋ฅํ๊ฒ ๊ฐ๋ค.
๋๋ ๊ถํ์ ๋ถ์ฌ๋ฐ์์ ๊ฒฝ์ฐ.
ํ์์ด ์ฃผ์ธ์ธ Repository์์๋ ๋์ํ์ง ์์ง๋ง ๋ณธ์ธ์ Repository์์๋ ๋์ํ๋ ๊ฒ์ผ๋ก ๋ฏธ๋ฃจ์ด ๋ณด์์ ๋ ์ด๋ฌํ ๊ฒฐ๋ก ์ด ๋ด๋ ค์ก๋ค.