75 lines
3.0 KiB
Python
75 lines
3.0 KiB
Python
"""deploy_server.py zioinfo-web에 /var/www/zioinfo 복사 단계 추가"""
|
|
import paramiko, sys, time
|
|
sys.stdout.reconfigure(encoding='utf-8', errors='replace')
|
|
c = paramiko.SSHClient(); c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
c.connect('101.79.17.164', username='root', password='1q2w3e!Q', timeout=15)
|
|
|
|
def run(label, cmd, timeout=60):
|
|
print(f'\n[{label}]')
|
|
_, o, _ = c.exec_command(cmd, timeout=timeout)
|
|
print(o.read().decode('utf-8','replace').strip()[:600])
|
|
|
|
# 현재 npm build 이후 단계 확인
|
|
run('현재 zioinfo npm build 이후 단계',
|
|
"grep -n 'npm build\\|mvn\\|deploy jar\\|www\\|static\\|copy\\|cp ' "
|
|
"/opt/zioinfo/deploy_server.py | head -15")
|
|
|
|
# deploy_server.py 수정: npm build 후 /var/www/zioinfo에 복사 추가
|
|
run('deploy_server.py 수정',
|
|
r"""python3 << 'PYEOF'
|
|
with open('/opt/zioinfo/deploy_server.py', 'r') as f:
|
|
content = f.read()
|
|
|
|
# npm build 다음에 copy to /var/www/zioinfo 추가
|
|
OLD = ''' ("npm build", ["bash", "-c",
|
|
f"cd {SRC}/frontend && npm ci --legacy-peer-deps 2>/dev/null || npm install --legacy-peer-deps && npm run build"]),
|
|
("mvn package", ["bash", "-c",'''
|
|
|
|
NEW = ''' ("npm build", ["bash", "-c",
|
|
f"cd {SRC}/frontend && npm ci --legacy-peer-deps 2>/dev/null || npm install --legacy-peer-deps && npm run build"]),
|
|
("copy to www", ["bash", "-c",
|
|
f"cp -r {SRC}/backend/src/main/resources/static/. /var/www/zioinfo/ && echo 'copied'"]),
|
|
("mvn package", ["bash", "-c",'''
|
|
|
|
if OLD in content:
|
|
content = content.replace(OLD, NEW)
|
|
with open('/opt/zioinfo/deploy_server.py', 'w') as f:
|
|
f.write(content)
|
|
print('수정 완료')
|
|
else:
|
|
# 이미 있거나 형식이 다름 - 직접 확인
|
|
idx = content.find('npm build')
|
|
print(f'npm build 위치: {idx}')
|
|
print(content[idx:idx+300])
|
|
PYEOF
|
|
""")
|
|
|
|
run('수정 결과 확인',
|
|
"grep -n 'npm build\\|copy to www\\|var/www\\|mvn package' /opt/zioinfo/deploy_server.py | head -10")
|
|
|
|
# 서비스 재시작
|
|
run('서비스 재시작',
|
|
'systemctl restart zioinfo-deploy && sleep 2 && systemctl is-active zioinfo-deploy')
|
|
|
|
# zioinfo-web 즉시 재배포 트리거
|
|
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")
|
|
|
|
# 배포 완료 대기 (npm build + mvn package는 시간이 걸림)
|
|
print('\n배포 진행 중 (최대 3분)...')
|
|
for i in range(20):
|
|
time.sleep(10)
|
|
_, o, _ = c.exec_command('tail -3 /var/log/zioinfo/deploy.log 2>/dev/null', timeout=10)
|
|
last = o.read().decode('utf-8','replace').strip()
|
|
print(f' [{i*10}s] {last.splitlines()[-1] if last else "..."}')
|
|
if '배포 완료' in last or 'health check' in last and '완료' in last:
|
|
break
|
|
|
|
run('배포 로그 최종', 'tail -15 /var/log/zioinfo/deploy.log 2>/dev/null')
|
|
run('/var/www/zioinfo 업데이트 확인', 'ls -la /var/www/zioinfo/assets/ | tail -3')
|
|
|
|
c.close()
|