"""최종 push v3 - bundle --all + clone 방식""" import paramiko, sys, os, subprocess sys.stdout.reconfigure(encoding='utf-8', errors='replace') client = paramiko.SSHClient() client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) client.connect('101.79.17.164', username='root', password='1q2w3e!Q', timeout=30) sftp = client.open_sftp() GITEA_AUTH_URL = 'zio:Zio%40Admin2026%21' def run_raw(cmd, timeout=300): _, o, e = client.exec_command(cmd, timeout=timeout) out = o.read().decode('utf-8', errors='replace').strip() err = e.read().decode('utf-8', errors='replace').strip() return out, err REPOS = { "zioinfo-web": "zio/zioinfo-web", "guardia-itsm": "zio/guardia-itsm", "guardia-manager": "zio/guardia-manager", "guardia-docs": "zio/guardia-docs", } for local, gitea in REPOS.items(): local_path = f"C:/GUARDiA/repos/{local}" bundle_path = f"C:/GUARDiA/repos/{local}.bundle" server_bundle = f"/tmp/{local}.bundle" name = gitea.split('/')[1] print(f'\n [{local} → {gitea}]') # 번들 생성 (HEAD 포함, --all) r = subprocess.run( ['git', '-C', local_path, 'bundle', 'create', bundle_path, 'HEAD', 'main'], capture_output=True, text=True, timeout=120 ) if r.returncode != 0: # HEAD가 없으면 --all 로 재시도 r = subprocess.run( ['git', '-C', local_path, 'bundle', 'create', bundle_path, '--all'], capture_output=True, text=True, timeout=120 ) if r.returncode != 0: print(f' bundle 실패: {r.stderr[:100]}') continue size_mb = os.path.getsize(bundle_path) // (1024*1024) print(f' bundle: {size_mb}MB') sftp.put(bundle_path, server_bundle) os.remove(bundle_path) gitea_url = f"http://{GITEA_AUTH_URL}@127.0.0.1:9003/{gitea}.git" # bundle 내용 확인 out, _ = run_raw(f"git bundle list-heads {server_bundle} 2>/dev/null") print(f' refs: {out[:100]}') # clone + push cmd = f""" set -e rm -rf /tmp/{name}_w git clone {server_bundle} /tmp/{name}_w 2>&1 cd /tmp/{name}_w BRANCH=$(git branch --show-current) echo "브랜치: $BRANCH" if [ "$BRANCH" != "main" ] && [ -n "$BRANCH" ]; then git branch -m "$BRANCH" main fi git log --oneline -2 git remote set-url origin '{gitea_url}' git push origin main --force 2>&1 rm -rf /tmp/{name}_w {server_bundle} echo "push 완료" """ out, err = run_raw(cmd, timeout=300) print(f' {out[-300:]}') if err and 'error' in err.lower(): print(f' ERR: {err[-200:]}') # 최종 확인 out, _ = run_raw(""" curl -sf 'http://127.0.0.1:9003/api/v1/repos/search?limit=20' \ -u 'zio:Zio@Admin2026!' 2>/dev/null | \ python3 -c " import sys,json for r in json.load(sys.stdin).get('data',[]): print(r['full_name'], r.get('size',0), 'KB') " """) print(f'\n[Gitea 저장소]\n{out}') sftp.close() client.close()