Skip to content

Commit

Permalink
make flask server return
Browse files Browse the repository at this point in the history
  • Loading branch information
LarryKwon committed Nov 29, 2024
1 parent e413e27 commit 4e8d5b9
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 16 deletions.
Binary file modified __pycache__/server_webhook.cpython-312.pyc
Binary file not shown.
41 changes: 25 additions & 16 deletions server_webhook.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
#!/usr/bin/python3

from flask import *
from werkzeug.middleware.proxy_fix import ProxyFix
import os
from dotenv import load_dotenv
import hmac
import hashlib
import subprocess

FLASK_ENV = os.getenv("FLASK_ENV", "development")
print(FLASK_ENV)
Expand All @@ -22,26 +21,36 @@ def otlplus_redeploy():
webhook_secret = os.getenv("WEBHOOK_SECRET").encode()
signature = 'sha256=' + hmac.new(webhook_secret, request.data, hashlib.sha256).hexdigest()
print(signature)
print( request.headers['X-Hub-Signature-256'])
print(request.headers.get('X-Hub-Signature-256', ''))
if 'X-Hub-Signature-256' not in request.headers or not hmac.compare_digest(
signature, request.headers['X-Hub-Signature-256']
):
abort(403)

os.spawnl(
os.P_NOWAIT,
"/usr/bin/sudo",
"sudo",
"/bin/bash",
"/home/otlplus/server/deploy.sh",
"-e", "dev"
)
return "Done", 200
abort(403)

# deploy.sh 실행 및 결과 확인
try:
result = subprocess.run(
[
"sudo",
"/bin/bash",
"/home/otlplus/server/deploy.sh",
"-e",
"dev"
],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True,
check=True # 실패 시 예외 발생
)
print(result.stdout) # 성공 출력 로그
return {"status": "success", "message": "Deployment completed successfully."}, 200
except subprocess.CalledProcessError as e:
print(e.stderr) # 에러 로그
return {"status": "error", "message": "Deployment failed.", "details": e.stderr}, 500

@app.route('/server-webhook-status', methods=["GET"])
def clubs_stage_redeploy():
# os.spawnl(os.P_NOWAIT, "/bin/bash", "/bin/bash", "/home/otlplus/server/deploy.sh -e dev")
return "Done", 200

if __name__ == '__main__':
app.run(host="127.0.0.1", threaded=True, port=5000)
app.run(host="127.0.0.1", threaded=True, port=5000)

0 comments on commit 4e8d5b9

Please sign in to comment.