Skip to content

Commit 900da40

Browse files
[feat] update dockerignore, docker compose, Dockerfile and Docker.serve node.js version.
1 parent 5d57c7b commit 900da40

5 files changed

Lines changed: 85 additions & 91 deletions

File tree

.dockerignore

Lines changed: 46 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,60 @@
1-
# Ignore dependencies and build output
2-
node_modules/
3-
dist/
4-
out/
5-
.tmp/
6-
.cache/
7-
8-
# Ignore Vite, Webpack, and React-specific build artifacts
9-
.vite/
10-
.vitepress/
1+
# Dependencies
2+
node_modules
3+
.pnpm-store
4+
.npm
5+
.yarn
6+
7+
# Build outputs
8+
dist
9+
out
10+
.tmp
11+
.cache
12+
13+
# Vite and React artifacts
14+
.vite
1115
.eslintcache
12-
.npm/
13-
coverage/
14-
jest/
15-
cypress/
16-
cypress/screenshots/
17-
cypress/videos/
18-
reports/
19-
20-
# Ignore environment and config files (sensitive data)
21-
*.env*
22-
*.log
23-
24-
# Ignore TypeScript build artifacts (if using TypeScript)
2516
*.tsbuildinfo
2617

27-
# Ignore lockfiles (optional if using Docker for package installation)
28-
npm-debug.log*
29-
yarn-debug.log*
30-
yarn-error.log*
31-
pnpm-debug.log*
18+
# Environment and secrets
19+
.env.*
20+
*.pem
21+
*.key
3222

33-
# Ignore local development files
34-
.git/
35-
.gitignore
36-
.vscode/
37-
.idea/
23+
# Logs
24+
*.log
25+
26+
# IDE and Editor files
27+
.idea
28+
.vscode
29+
.vs
3830
*.swp
31+
*.swo
3932
.DS_Store
4033
Thumbs.db
34+
.git
35+
.gitignore
36+
.editorconfig
4137

42-
# Ignore Docker-related files (to avoid copying unnecessary configs)
43-
Dockerfile
38+
# Docker
39+
Dockerfile*
40+
compose.yaml
4441
.dockerignore
45-
docker-compose.yml
46-
docker-compose.override.yml
4742

48-
# Ignore build-specific cache files
49-
*.lock
43+
# CI/CD and Tools
44+
.github
45+
Taskfile.yml
46+
47+
# Documentation and Assets
48+
*.md
49+
images/
50+
51+
# Test files
52+
**/*.test.ts
53+
**/*.test.tsx
54+
src/setupTests.ts
55+
5056

51-
# Ignore AI generated files
57+
# AI generated files
5258
.ai/
5359
.ai-temp/
5460
.cursor/

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# =========================================
22
# Stage 1: Build the React.js Application
33
# =========================================
4-
ARG NODE_VERSION=24.11.0-alpine
4+
ARG NODE_VERSION=24.11.1-alpine
55
ARG NGINX_VERSION=alpine3.22
66

77
# Use a lightweight Node.js image for building (customizable via ARG)

Dockerfile.serve

Lines changed: 22 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,49 @@
1-
# This Dockerfile is used to serve the React.js application using the Vercel serve npm package.
1+
# =============================
2+
# Stage 1: Build the application
3+
# =============================
4+
ARG NODE_VERSION=24.11.1
25

3-
# =========================================
4-
# Stage 1: Serve the React.js Application
5-
# =========================================
6+
# Use a lightweight Node.js Alpine image for building
7+
FROM node:${NODE_VERSION}-alpine AS build
68

7-
# Define Node.js version
8-
ARG NODE_VERSION=24.11.0
9-
10-
# -----------------------------------------------------------------------------
11-
# 1. BASE STAGE — Common setup
12-
# -----------------------------------------------------------------------------
13-
FROM node:${NODE_VERSION}-alpine AS base
14-
15-
# Set working directory
9+
# Set the working directory inside the container
1610
WORKDIR /app
1711

18-
# Copy dependency manifests
19-
COPY package*.json ./
12+
# Copy dependency manifests first to optimize Docker caching
13+
COPY package.json package-lock.json ./
2014

21-
# -----------------------------------------------------------------------------
22-
# Stage 2: DEPENDENCIES STAGE — Install only production dependencies
23-
# -----------------------------------------------------------------------------
24-
FROM base AS deps
25-
26-
# Use BuildKit cache to speed up npm installs
27-
RUN --mount=type=cache,target=/root/.npm \
28-
npm ci --omit=dev
29-
30-
# -----------------------------------------------------------------------------
31-
# Stage 3: BUILD STAGE — Install all dependencies and build the app
32-
# -----------------------------------------------------------------------------
33-
FROM base AS build
34-
35-
# Install all dependencies (including devDependencies)
15+
# Install all dependencies (including devDependencies) using BuildKit cache
3616
RUN --mount=type=cache,target=/root/.npm \
3717
npm ci
3818

39-
# Copy the rest of the project files
19+
# Copy the rest of the project files into the container
4020
COPY . .
4121

42-
# Build the production bundle
22+
# Build the React.js production bundle
4323
RUN npm run build
4424

45-
# -----------------------------------------------------------------------------
46-
# Stage 4: FINAL STAGE — Minimal runtime image
47-
# -----------------------------------------------------------------------------
25+
# =============================
26+
# Stage 2: Final Runtime Image
27+
# =============================
4828
FROM node:${NODE_VERSION}-alpine AS final
4929

50-
# Set environment variables for production
30+
# Set production environment
5131
ENV NODE_ENV=production
5232

53-
# Set working directory
33+
# Set working directory for the runtime container
5434
WORKDIR /app
5535

56-
# Installing globally requires root access, so do this before USER node
36+
# Install the Vercel "serve" package globally to serve static files
5737
RUN npm install -g serve
5838

59-
60-
# Switch to a non-root user for security
39+
# Drop root privileges and run as the non-root "node" user
6140
USER node
6241

63-
# Copy only the built app from the build stage
42+
# Copy the built production files from the build stage
6443
COPY --from=build /app/dist /app/build
6544

66-
# Expose port 8080 for the static server
45+
# Expose the port where the static server will run
6746
EXPOSE 8080
6847

69-
# Start the static file server
48+
# Start the static server to serve the built React app
7049
CMD ["serve", "-s", "build", "-l", "8080"]

compose.yaml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,36 @@ services:
44
context: .
55
dockerfile: Dockerfile
66
image: docker-reactjs-sample
7+
container_name: reactjs-sample-app-prod
78
ports:
89
- "8080:8080"
10+
911
react-dev:
1012
build:
1113
context: .
1214
dockerfile: Dockerfile.dev
15+
image: docker-reactjs-sample-dev
16+
container_name: reactjs-sample-app-prod
1317
ports:
1418
- "5173:5173"
1519
develop:
1620
watch:
1721
- action: sync
1822
path: .
1923
target: /app
24+
2025
react-test:
2126
build:
2227
context: .
2328
dockerfile: Dockerfile.dev
24-
command: ["npm", "run", "test:coverage"]
29+
image: docker-reactjs-sample-test
30+
container_name: reactjs-sample-app-test
31+
command: ["npm", "run", "test"]
2532

2633
react-lint:
2734
build:
2835
context: .
2936
dockerfile: Dockerfile.dev
37+
image: docker-reactjs-sample-lint
38+
container_name: reactjs-sample-app-lint
3039
command: ["npm", "run", "lint"]

package-lock.json

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)