abubasith86 commited on
Commit
73046d5
·
1 Parent(s): 58b31c8
Files changed (1) hide show
  1. Dockerfile +52 -27
Dockerfile CHANGED
@@ -1,42 +1,67 @@
1
- # Stage 1: Build Node.js App
2
- FROM node:23.7.0 as builder
3
 
4
- # Install git and other dependencies
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
  RUN apt-get update && apt-get install -y git
6
 
7
- # Clone the GitHub repository (Main Project)
8
- RUN git clone https://github.com/abubasith456/Node-WLA.git /usr/src/app
9
 
10
  # Set working directory
11
  WORKDIR /usr/src/app
12
 
13
- # Install dependencies
14
- RUN npm install
15
 
16
- # Stage 2: Set Up Nginx with Node.js
17
- FROM nginx:alpine
18
 
19
- # Install necessary dependencies
20
- RUN apk add --no-cache bash git nodejs npm
21
 
22
- # Set working directory for Nginx
23
- WORKDIR /etc/nginx
24
-
25
- # Remove default Nginx config
26
- RUN rm /etc/nginx/conf.d/default.conf
27
-
28
- # Copy custom Nginx config from main project
29
- COPY --from=builder /usr/src/app/nginx.conf /etc/nginx/conf.d/default.conf
30
 
31
- # Copy Node.js app to /app directory
32
- COPY --from=builder /usr/src/app /app
33
 
34
- # Set working directory for Node.js
35
- WORKDIR /app
36
 
37
- # Expose necessary ports
38
- EXPOSE 80 5000
39
 
40
- # Start Node.js & Nginx together
41
- CMD ["sh", "-c", "git pull origin main && npm install && npm start & nginx -g 'daemon off;'"]
42
 
 
 
 
1
+ # FROM node:23.7.0 as builder
 
2
 
3
+ # # Install git
4
+ # RUN apt-get update && apt-get install -y git
5
+
6
+ # # Clone the GitHub repository (if not already cloned)
7
+ # RUN rm -rf /usr/src/app && git clone https://github.com/abubasith456/Node-WLA.git /usr/src/app
8
+
9
+ # # Set the working directory
10
+ # WORKDIR /usr/src/app
11
+
12
+ # # Change ownership of the directory to the current user (node)
13
+ # RUN chown -R node:node /usr/src/app
14
+
15
+ # # Mark the repository directory as safe
16
+ # USER node
17
+ # RUN git config --global --add safe.directory /usr/src/app
18
+
19
+ # # Install npm dependencies
20
+ # RUN npm install
21
+
22
+ # # Expose the port your application runs on
23
+ # EXPOSE 5000
24
+
25
+ # # Ensure that the latest code is pulled before starting the app
26
+ # CMD git pull origin main && npm install && npm start
27
+
28
+
29
+
30
+ # First stage: Node.js application build
31
+ FROM node:23.7.0 AS builder
32
+
33
+ # Install git
34
  RUN apt-get update && apt-get install -y git
35
 
36
+ # Clone the GitHub repository
37
+ RUN rm -rf /usr/src/app && git clone https://github.com/abubasith456/Node-WLA.git /usr/src/app
38
 
39
  # Set working directory
40
  WORKDIR /usr/src/app
41
 
42
+ # Change ownership of the directory to node user
43
+ RUN chown -R node:node /usr/src/app
44
 
45
+ # Switch to node user
46
+ USER node
47
 
48
+ # Mark the repository directory as safe
49
+ RUN git config --global --add safe.directory /usr/src/app
50
 
51
+ # Install npm dependencies
52
+ RUN npm install
 
 
 
 
 
 
53
 
54
+ # Second stage: Nginx setup
55
+ FROM nginx:latest
56
 
57
+ # Copy built Node.js app from builder stage
58
+ COPY --from=builder /usr/src/app /usr/src/app
59
 
60
+ # Copy Nginx configuration file
61
+ COPY nginx.conf /etc/nginx/nginx.conf
62
 
63
+ # Expose ports
64
+ EXPOSE 80 443 5000
65
 
66
+ # Start Nginx in the foreground
67
+ CMD ["nginx", "-g", "daemon off;"]