Chandima Prabhath commited on
Commit
74791b6
·
1 Parent(s): f13d1d2

Add Dockerfile and Nginx configuration for React application deployment

Browse files
Files changed (3) hide show
  1. Dockerfile +31 -0
  2. frontend +1 -0
  3. nginx.conf +31 -0
Dockerfile ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Stage 1: Build the React application
2
+ FROM node:20-alpine AS builder
3
+ RUN apk add --no-cache libc6-compat
4
+
5
+ WORKDIR /app
6
+
7
+ # 1) Copy package files & install
8
+ COPY frontend/package.json frontend/package-lock.json ./
9
+ RUN npm install
10
+
11
+ # 2) Copy source & build into dist/
12
+ COPY frontend ./
13
+ RUN npm run build
14
+
15
+ # Stage 2: Serve the React build with Nginx
16
+ FROM bitnami/nginx:1.26.1
17
+
18
+ WORKDIR /app
19
+
20
+ # 1) Copy your custom Nginx config
21
+ # (make sure your nginx.conf listens on 7860 and points root to /usr/share/nginx/html)
22
+ COPY nginx.conf /opt/bitnami/nginx/conf/nginx.conf
23
+
24
+ # 2) Copy the static build from the builder
25
+ COPY --from=builder /app/dist /usr/share/nginx/html
26
+
27
+ # 3) Expose the HF Spaces port
28
+ EXPOSE 7860
29
+
30
+ # 4) Launch Nginx in the foreground
31
+ CMD ["nginx", "-g", "daemon off;"]
frontend ADDED
@@ -0,0 +1 @@
 
 
1
+ Subproject commit baf5d1a56279e810a15f870759dbe098af9b6a2d
nginx.conf ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ worker_processes 1;
2
+
3
+ events { worker_connections 1024; }
4
+
5
+ http {
6
+ include mime.types;
7
+ default_type application/octet-stream;
8
+ sendfile on;
9
+ keepalive_timeout 65;
10
+
11
+ server {
12
+ listen 7860;
13
+ server_name localhost;
14
+
15
+ root /usr/share/nginx/html;
16
+ index index.html;
17
+
18
+ # Serve files, fallback to index.html for client‑side routing
19
+ location / {
20
+ try_files $uri $uri/ /index.html;
21
+ }
22
+
23
+ # Optional: caching static assets
24
+ location ~* \.(js|css|png|jpg|jpeg|gif|svg|ico)$ {
25
+ expires 30d;
26
+ add_header Cache-Control "public";
27
+ }
28
+ }
29
+ }
30
+
31
+