49 lines
1.7 KiB
Python
49 lines
1.7 KiB
Python
"""git safe.directory + remote URL 전체 수정"""
|
|
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=30):
|
|
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 = 'http://zio:Zio%40Admin2026%21@127.0.0.1:9003/zio'
|
|
|
|
SRC_DIRS = {
|
|
'/opt/guardia/src': f'{GITEA}/guardia-itsm.git',
|
|
'/opt/zioinfo/src': f'{GITEA}/zioinfo-web.git',
|
|
'/opt/manager/src': f'{GITEA}/guardia-manager.git',
|
|
'/opt/guardia-docs/src': f'{GITEA}/guardia-docs.git',
|
|
}
|
|
|
|
# safe.directory 등록 + ownership 수정 + remote update
|
|
for path, url in SRC_DIRS.items():
|
|
run(f'fix {path}', f"""
|
|
git config --global --add safe.directory {path} 2>/dev/null
|
|
chown -R root:root {path} 2>/dev/null
|
|
if [ -d {path}/.git ]; then
|
|
git -C {path} remote set-url origin '{url}'
|
|
git -C {path} pull origin main 2>&1 | tail -3
|
|
else
|
|
echo "no clone yet"
|
|
fi
|
|
""", timeout=30)
|
|
|
|
# 배포 트리거
|
|
import time
|
|
for repo in ['guardia-itsm', 'zioinfo-web']:
|
|
run(f'{repo} 배포 트리거',
|
|
f'curl -sf -X POST http://localhost:9999 '
|
|
f'-H "Content-Type: application/json" '
|
|
f'-H "X-Gitea-Event: push" '
|
|
f'-d \'{{"repository":{{"name":"{repo}"}},"ref":"refs/heads/main"}}\' 2>/dev/null')
|
|
|
|
time.sleep(12)
|
|
run('최종 배포 로그', 'tail -20 /var/log/zioinfo/deploy.log 2>/dev/null')
|
|
client.close()
|