-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
48 lines (40 loc) · 1.19 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import subprocess
from flask import Flask, jsonify, request
import os
app = Flask(__name__)
pullCommand = ["make", "pull"]
buildCommand = ["make", "build"]
tagCommand = ["make", "tag"]
pushCommand = ["make", "push"]
commands = [
"make pull",
"make build",
"make tag",
"make push",
]
@app.route("/", methods=["POST"])
def build():
data = request.get_json()
repo_url = data['repository']['ssh_url']
directory = data['repository']['name']
try:
if not os.path.exists(directory):
print("cloning")
process = subprocess.Popen("git clone {}".format(repo_url), shell=True)
process.wait()
print("building")
os.chdir(directory)
for cmd in commands:
process = subprocess.Popen(cmd , shell=True)
process.wait()
os.chdir("..")
return jsonify({"msg": "Deployed"}), 200
except FileNotFoundError:
print(f"La carpeta '{directory}' no existe.")
except Exception as e:
print(f"Ocurrió un error: {e}")
os.chdir("..")
return jsonify({"msg": "Deploy failed"}), 500
if __name__ == "__main__":
# Please do not set debug=True in production
app.run(host="0.0.0.0", port=5510, debug=False, threaded=True)