From 99557a79261cbece1fd165f77eaf37bc768b2007 Mon Sep 17 00:00:00 2001 From: larrykwon Date: Fri, 29 Nov 2024 19:31:32 +0000 Subject: [PATCH] can't do timeout problem, need to change deploy.sh when the webhook url is approved --- .github/workflows/cd-dev.yml | 18 ---------------- server_webhook.py | 41 ++++++++++++++---------------------- 2 files changed, 16 insertions(+), 43 deletions(-) diff --git a/.github/workflows/cd-dev.yml b/.github/workflows/cd-dev.yml index 3e964a2..379beaa 100644 --- a/.github/workflows/cd-dev.yml +++ b/.github/workflows/cd-dev.yml @@ -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 diff --git a/server_webhook.py b/server_webhook.py index f006490..705c505 100644 --- a/server_webhook.py +++ b/server_webhook.py @@ -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) @@ -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) \ No newline at end of file