abubasith86 commited on
Commit
ef11509
Β·
1 Parent(s): 4b421e2
Files changed (1) hide show
  1. deploy.py +14 -7
deploy.py CHANGED
@@ -3,22 +3,28 @@ import shutil
3
  import subprocess
4
 
5
  APP_DIR = "/app"
6
- TMP_DIR = "/tmp/repo_clone"
7
  REPO_URL = "https://github.com/abubasith456/Node-WLA.git"
8
 
9
 
10
  def remove_app_directory():
11
  if os.path.exists(APP_DIR):
12
  print("⚠️ Removing existing app directory...")
13
- shutil.rmtree(APP_DIR, ignore_errors=True)
 
 
 
 
 
 
 
 
 
 
14
 
15
 
16
  def clone_repository():
17
  print("πŸ”„ Cloning repository...")
18
- if os.path.exists(APP_DIR):
19
- shutil.rmtree(APP_DIR, ignore_errors=True)
20
-
21
- subprocess.run(["git", "clone", REPO_URL, TMP_DIR], check=True)
22
 
23
 
24
  def install_dependencies():
@@ -28,12 +34,13 @@ def install_dependencies():
28
 
29
  def start_application():
30
  print("πŸš€ Starting application...")
31
- subprocess.Popen(["npm", "start"], cwd=APP_DIR)
32
 
33
 
34
  def main():
35
  print("πŸš€ Deployment started...")
36
  remove_app_directory()
 
37
  clone_repository()
38
  install_dependencies()
39
  start_application()
 
3
  import subprocess
4
 
5
  APP_DIR = "/app"
 
6
  REPO_URL = "https://github.com/abubasith456/Node-WLA.git"
7
 
8
 
9
  def remove_app_directory():
10
  if os.path.exists(APP_DIR):
11
  print("⚠️ Removing existing app directory...")
12
+ try:
13
+ shutil.rmtree(APP_DIR)
14
+ except PermissionError:
15
+ print("⚠️ Permission denied. Changing ownership and retrying...")
16
+ subprocess.run(["chown", "-R", str(os.getuid()), APP_DIR], check=False)
17
+ shutil.rmtree(APP_DIR, ignore_errors=True)
18
+
19
+
20
+ def create_app_directory():
21
+ print("πŸ“ Creating app directory...")
22
+ os.makedirs(APP_DIR, exist_ok=True)
23
 
24
 
25
  def clone_repository():
26
  print("πŸ”„ Cloning repository...")
27
+ subprocess.run(["git", "clone", REPO_URL, APP_DIR], check=True)
 
 
 
28
 
29
 
30
  def install_dependencies():
 
34
 
35
  def start_application():
36
  print("πŸš€ Starting application...")
37
+ subprocess.run(["npm", "start"], cwd=APP_DIR, check=True)
38
 
39
 
40
  def main():
41
  print("πŸš€ Deployment started...")
42
  remove_app_directory()
43
+ create_app_directory()
44
  clone_repository()
45
  install_dependencies()
46
  start_application()