Skip to content

Commit 2361771

Browse files
Rohit KumarRohit Kumar
authored andcommitted
Added restrictions on branch
1 parent a994eba commit 2361771

File tree

3 files changed

+19
-13
lines changed

3 files changed

+19
-13
lines changed

app.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from django import conf
12
from flask import Flask, jsonify, request
23
import os, yaml, requests, time
34

@@ -31,17 +32,18 @@ def SlackAlert(msg):
3132
def webhook():
3233
payload = request.get_json()
3334
branch = payload['ref'].split('/')[-1]
34-
## parse github webhook payload response and get event type and branch name
35-
SlackAlert("👀 A new commit has been detected to the {} branch, working on updating source code.".format(branch))
36-
os.system('cd ' + PROJECT_PATH + ' && git pull origin ' + branch)
37-
SlackAlert("🎉 The {} branch has been updated successfully.".format(branch))
38-
SlackAlert("🛠 Executing the build script.")
39-
ExecuteBashScript('build.sh', branch)
40-
SlackAlert("🎉 The build script has been executed successfully.")
41-
SlackAlert("🛠 Executing the deploy script.")
42-
ExecuteBashScript('deploy.sh', branch)
43-
SlackAlert("🎉 The deploy script has been executed successfully.")
44-
return jsonify(payload)
35+
if branch == config['BRANCH_TO_USE']:
36+
## parse github webhook payload response and get event type and branch name
37+
SlackAlert("👀 A new commit has been detected to the {} branch, working on updating source code.".format(branch))
38+
os.system('cd ' + PROJECT_PATH + ' && git pull origin ' + branch)
39+
SlackAlert("🎉 The {} branch has been updated successfully.".format(branch))
40+
SlackAlert("🛠 Executing the build script.")
41+
ExecuteBashScript('build.sh', branch)
42+
SlackAlert("🎉 The build script has been executed successfully.")
43+
SlackAlert("🛠 Executing the deploy script.")
44+
ExecuteBashScript('deploy.sh', branch)
45+
SlackAlert("🎉 The deploy script has been executed successfully.")
46+
return jsonify(payload)
4547

4648

4749
if __name__ == "__main__":

config.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
PROJECT_PATH: '/home/ubuntu/MyCoolApp/' # Your project source code location
22
SLACK_WEBHOOK: 'https://hooks.slack.com/services/XXXXXX/YYYYYY/ZZZZZZZZ' # Slack Webhook URL for getting alerts
3-
VERBOSE: 'enabled'
3+
VERBOSE: 'enabled'
4+
BRANCH_TO_USE: 'develop'

scripts/deploy.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,7 @@
44
- $1: the first argument ROOT_PATH of SexyDeployer
55
- $2: the second argument PROJECT_PATH, where you are storing your source code
66
- $3: the third argument BRANCH, the branch you are deploying or triggered
7-
'
7+
'
8+
// run node server.js with PROJECT_PATH
9+
cd $2
10+
npm start

0 commit comments

Comments
 (0)