abubasith86 commited on
Commit
cb666c5
Β·
1 Parent(s): ef11509
Files changed (2) hide show
  1. Dockerfile +31 -9
  2. deploy.py +10 -14
Dockerfile CHANGED
@@ -1,14 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  FROM node:23.7.0
2
 
3
- # Set working directory
4
- WORKDIR /app
 
 
 
 
 
 
5
 
6
- # Copy deployment script
7
- COPY deploy.py /deploy.py
8
 
9
- # Set non-root user
10
- RUN useradd -m appuser && chown -R appuser /app
11
- USER appuser
12
 
13
- # Run deployment script
14
- CMD ["python3", "/deploy.py"]
 
1
+ # FROM node:23.7.0
2
+
3
+ # # Set working directory
4
+ # WORKDIR /app
5
+
6
+ # # Copy deployment script
7
+ # COPY deploy.py /deploy.py
8
+
9
+ # # Set non-root user
10
+ # RUN useradd -m appuser && chown -R appuser /app
11
+ # USER appuser
12
+
13
+ # # Run deployment script
14
+ # CMD ["python3", "/deploy.py"]
15
+
16
+
17
+ # Use the official Node.js image as the base image
18
  FROM node:23.7.0
19
 
20
+ # Install git
21
+ RUN apt-get update && apt-get install -y git
22
+
23
+ # Clone the GitHub repository
24
+ RUN git clone https://github.com/abubasith456/Node-WLA.git /usr/src/app
25
+
26
+ # Set the working directory
27
+ WORKDIR /usr/src/app
28
 
29
+ # Install npm dependencies
30
+ RUN npm install
31
 
32
+ # Expose the port your application runs on
33
+ EXPOSE 5000
 
34
 
35
+ # Start the application
36
+ CMD ["npm", "start"]
deploy.py CHANGED
@@ -3,28 +3,25 @@ import shutil
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,13 +31,12 @@ 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()
 
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(TMP_DIR):
19
+ shutil.rmtree(TMP_DIR, ignore_errors=True)
20
+
21
+ subprocess.run(["git", "clone", REPO_URL, TMP_DIR], check=True)
22
+
23
+ print("πŸ“‚ Moving repository files to app directory...")
24
+ shutil.move(TMP_DIR, APP_DIR)
25
 
26
 
27
  def install_dependencies():
 
31
 
32
  def start_application():
33
  print("πŸš€ Starting application...")
34
+ subprocess.Popen(["npm", "start"], cwd=APP_DIR)
35
 
36
 
37
  def main():
38
  print("πŸš€ Deployment started...")
39
  remove_app_directory()
 
40
  clone_repository()
41
  install_dependencies()
42
  start_application()