Skip to content

Commit b200288

Browse files
committed
add readme
1 parent 58a9625 commit b200288

File tree

2 files changed

+53
-6
lines changed

2 files changed

+53
-6
lines changed

react/.dockerignore

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
node_modules
2+
dist
3+
.git
4+
.gitignore
5+
Dockerfile
6+
npm-debug.log
7+
*.md
8+
.vscode
9+
.env
10+
.dockerignore
11+
nginx-config
12+
Dockerfile.basic
13+
eslint.config.js
14+
README.md

react/Dockerfile

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,64 @@
11
# -------------------------------------------------------
2-
# 1) Build the React app using Vite
2+
# Multi-Stage Build: Builder Stage
3+
# - Reduces final image size
4+
# - Removes dev dependencies
5+
# - Improves CI/CD caching
36
# -------------------------------------------------------
47
FROM node:20-alpine AS builder
8+
9+
# Use WORKDIR early (cached)
510
WORKDIR /app
611

12+
# Layer Caching
13+
# Copy only package* first so npm install is cached unless deps change
714
COPY package*.json ./
8-
RUN npm install
915

16+
# Install dependencies (use ci for reproducibility)
17+
RUN npm ci --include=dev
18+
19+
# Copy the rest of the source code (last layer → faster caching)
1020
COPY . .
21+
22+
# Build the React/Vite app
1123
RUN npm run build
1224

1325

26+
1427
# -------------------------------------------------------
15-
# 2) Nginx stage (serves the compiled app)
28+
# Final Stage — Optimized Nginx Server
29+
# - Serves static files efficiently
30+
# - Small attack surface
31+
# - Production-grade caching
1632
# -------------------------------------------------------
1733
FROM nginx:1.27-alpine
1834

1935
# Remove default config
2036
RUN rm /etc/nginx/conf.d/default.conf
2137

22-
# Copy your optimized Nginx config
38+
# Copy your optimized Nginx configuration
2339
COPY nginx-config/app.conf /etc/nginx/conf.d/default.conf
2440

25-
# Copy build output
41+
# Copy only the optimized production build
2642
COPY --from=builder /app/dist /usr/share/nginx/html
2743

28-
# Expose port 80
44+
# -------------------------------------------------------
45+
# Expose Ports Explicitly
46+
# Helps readability & k8s ingress controllers
47+
# -------------------------------------------------------
2948
EXPOSE 80
3049

50+
# -------------------------------------------------------
51+
# Add Healthcheck (for Docker + Kubernetes)
52+
# Ensures container restart on failure
53+
# -------------------------------------------------------
54+
HEALTHCHECK --interval=30s --timeout=5s --start-period=10s \
55+
CMD wget -qO- http://localhost || exit 1
56+
57+
# -------------------------------------------------------
58+
# Metadata (optional but good practice)
59+
# -------------------------------------------------------
60+
LABEL maintainer="Firas Mosbahi"
61+
LABEL description="Optimized production-ready Docker image for a Vite/React application served via Nginx."
62+
63+
# Run NGINX in foreground
3164
CMD ["nginx", "-g", "daemon off;"]

0 commit comments

Comments
 (0)