zioinfo-mail/scripts/push/push_gitea_internal.py
DESKTOP-TKLFCPR\ython 28d3ba4836 refactor(cleanup): commit folder reorganization - scripts/, _archive/, docs/ restructure
- Move backend/frontend/messenger/ old paths to _archive/
- Reorganize scripts into scripts/deploy, check, push, setup, misc
- Move docs (pptx, docx) to docs/
- Add .claude agents and skills for fullstack/folder-cleanup harness
- workspace/ projects remain intact

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-01 19:43:09 +09:00

106 lines
3.9 KiB
Python

"""Gitea 내부 포트(9003) 직접 사용 + 저장소 생성 + push"""
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_INTERNAL = 'http://127.0.0.1:9003'
GITEA_AUTH = 'zio:Zio@Admin2026!'
def run(label, cmd, timeout=120):
print(f' [{label}]')
_, 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()
if out: print(f' {out[:300]}')
if err:
bad = [l for l in err.splitlines() if not any(k in l.lower() for k in ['warn','hint','cloning','into'])]
if bad: print(f' ERR: {bad[-1]}')
return out
# 1. 신규 Gitea 저장소 생성 (내부 포트)
print('[Gitea 저장소 생성 - 내부 포트 9003]')
run('저장소 목록', f"""
curl -sf '{GITEA_INTERNAL}/api/v1/repos/search?limit=20' \
-u '{GITEA_AUTH}' 2>/dev/null | \
python3 -c "import sys,json; [print(r['full_name']) for r in json.load(sys.stdin).get('data',[])]"
""")
for name, desc in [
("guardia-manager", "GUARDiA 통합 관리자 포털"),
("guardia-messenger","GUARDiA Messenger 모바일 앱"),
("guardia-docs", "GUARDiA 프로젝트 문서"),
]:
run(f'create {name}', f"""
curl -sf -X DELETE '{GITEA_INTERNAL}/api/v1/repos/zio/{name}' \
-u '{GITEA_AUTH}' 2>/dev/null
curl -sf -X POST '{GITEA_INTERNAL}/api/v1/user/repos' \
-H 'Content-Type: application/json' \
-u '{GITEA_AUTH}' \
-d '{{"name":"{name}","description":"{desc}","private":false,"auto_init":false}}' 2>/dev/null | \
python3 -c "import sys,json; d=json.load(sys.stdin); print('OK:', d.get('full_name','error: '+str(d.get('message',''))))" 2>/dev/null
""")
# 2. 번들 파일 전송 + 내부 포트로 push
REPOS = {
"zioinfo-web": "zio/zioinfo-web",
"guardia-itsm": "zio/guardia-itsm",
"guardia-manager": "zio/guardia-manager",
"guardia-messenger": "zio/guardia-messenger",
"guardia-docs": "zio/guardia-docs",
}
print('\n[번들 전송 + 내부 포트 push]')
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}')
# 번들 생성
r = subprocess.run(['git', '-C', local_path, 'bundle', 'create', bundle_path, 'HEAD', '--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)
print(f' 전송 완료')
os.remove(bundle_path)
# 내부 포트로 push
gitea_url = f"http://{GITEA_AUTH}@127.0.0.1:9003/{gitea}.git"
run(f'push {local}', f"""
rm -rf /tmp/{name}_work
git clone "{server_bundle}" /tmp/{name}_work 2>/dev/null
cd /tmp/{name}_work
# HEAD 브랜치를 main으로 설정
BRANCH=$(git branch | head -1 | tr -d '* ')
if [ "$BRANCH" != "main" ] && [ -n "$BRANCH" ]; then
git branch -m "$BRANCH" main
fi
git remote set-url origin '{gitea_url}'
git push origin main --force 2>&1 | tail -3
rm -rf /tmp/{name}_work {server_bundle}
echo "done"
""", timeout=300)
# 3. 최종 확인
run('최종 저장소 목록', f"""
curl -sf '{GITEA_INTERNAL}/api/v1/repos/search?limit=20' \
-u '{GITEA_AUTH}' 2>/dev/null | \
python3 -c "import sys,json; [print(r['full_name'], '-', r.get('default_branch','')) for r in json.load(sys.stdin).get('data',[])]"
""")
sftp.close()
client.close()
print('\n=== Phase 2 완료 ===')