58 lines
1.9 KiB
Python
58 lines
1.9 KiB
Python
"""서버 git clone remote URL 수정 (localhost:3000 → 127.0.0.1:9003)"""
|
|
import paramiko, sys
|
|
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=15)
|
|
|
|
def run(label, cmd, timeout=20):
|
|
print(f'\n[{label}]')
|
|
_, o, e = client.exec_command(cmd, timeout=timeout)
|
|
out = o.read().decode('utf-8', 'replace').strip()
|
|
if out: print(out[:400])
|
|
return out
|
|
|
|
GITEA_URL = 'http://zio:Zio%40Admin2026%21@127.0.0.1:9003/zio'
|
|
|
|
REPOS = {
|
|
'/opt/zioinfo/src': f'{GITEA_URL}/zioinfo-web.git',
|
|
'/opt/guardia/src': f'{GITEA_URL}/guardia-itsm.git',
|
|
'/opt/manager/src': f'{GITEA_URL}/guardia-manager.git',
|
|
'/opt/guardia-docs/src': f'{GITEA_URL}/guardia-docs.git',
|
|
}
|
|
|
|
for path, url in REPOS.items():
|
|
run(f'remote update {path}', f"""
|
|
if [ -d {path}/.git ]; then
|
|
git -C {path} remote set-url origin '{url}'
|
|
echo "updated: $(git -C {path} remote get-url origin)"
|
|
else
|
|
echo "no clone at {path} (will clone on first deploy)"
|
|
fi
|
|
""")
|
|
|
|
# zioinfo-web git pull 테스트
|
|
run('zioinfo-web git pull 테스트', f"""
|
|
if [ -d /opt/zioinfo/src/.git ]; then
|
|
git -C /opt/zioinfo/src pull origin main 2>&1 | tail -3
|
|
else
|
|
git clone '{GITEA_URL}/zioinfo-web.git' /opt/zioinfo/src 2>&1 | tail -3
|
|
fi
|
|
""", timeout=30)
|
|
|
|
# 배포 재트리거
|
|
run('zioinfo-web 재트리거', """
|
|
curl -sf -X POST http://localhost:9999 \
|
|
-H 'Content-Type: application/json' \
|
|
-H 'X-Gitea-Event: push' \
|
|
-d '{"repository":{"name":"zioinfo-web"},"ref":"refs/heads/main"}' \
|
|
2>/dev/null
|
|
""")
|
|
|
|
import time; time.sleep(8)
|
|
run('최종 배포 로그', 'tail -15 /var/log/zioinfo/deploy.log 2>/dev/null')
|
|
|
|
client.close()
|
|
print('\n=== git remote 수정 완료 ===')
|