Skip to content

Commit

Permalink
can't do timeout problem, need to change deploy.sh when the webhook u…
Browse files Browse the repository at this point in the history
…rl is approved
  • Loading branch information
LarryKwon committed Nov 29, 2024
1 parent c932779 commit 99557a7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 43 deletions.
18 changes: 0 additions & 18 deletions .github/workflows/cd-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,3 @@ jobs:
-d "$PAYLOAD" \
https://webhook.otl.dev.sparcs.org/server-webhook)
echo "response=$RESPONSE" >> $GITHUB_ENV
- name: Notify Slack
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
run: |
curl -X POST -H 'Content-type: application/json' --data \
'{
"text": "*Deployment Status:*",
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "Deployment Status: *${{ env.response }}*"
}
}
]
}' $SLACK_WEBHOOK_URL
41 changes: 16 additions & 25 deletions server_webhook.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#!/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 @@ -21,36 +22,26 @@ 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.get('X-Hub-Signature-256', ''))
print( request.headers['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)

# 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
abort(403)

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

@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 99557a7

Please sign in to comment.