-
Notifications
You must be signed in to change notification settings - Fork 0
Added multi stage docker file #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,16 +1,23 @@ | ||||||||||||||||||||||||||||
| FROM node:20.19.0 | ||||||||||||||||||||||||||||
| # ---------- Stage 1: Build ---------- | ||||||||||||||||||||||||||||
| FROM node:20.19.0 AS builder | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| WORKDIR /app | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| COPY package*.json ./ | ||||||||||||||||||||||||||||
| RUN npm install | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| COPY . . | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| # This will fail the Docker build if there are TypeScript/build errors | ||||||||||||||||||||||||||||
| RUN npm run build | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| # Verify that the build directory exists | ||||||||||||||||||||||||||||
| RUN test -d dist || (echo "Build failed - dist directory not found" && exit 1) | ||||||||||||||||||||||||||||
| # ---------- Stage 2: Production ---------- | ||||||||||||||||||||||||||||
| FROM nginx:alpine | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| # Remove default nginx static files | ||||||||||||||||||||||||||||
| RUN rm -rf /usr/share/nginx/html/* | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| # Copy build output from builder stage | ||||||||||||||||||||||||||||
| COPY --from=builder /app/dist /usr/share/nginx/html | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
| # Configure nginx for React SPA routing | |
| RUN printf 'server {\n\ | |
| listen 80;\n\ | |
| server_name _;\n\ | |
| root /usr/share/nginx/html;\n\ | |
| index index.html;\n\ | |
| \n\ | |
| location / {\n\ | |
| try_files $$uri $$uri/ /index.html;\n\ | |
| }\n\ | |
| }\n' > /etc/nginx/conf.d/default.conf |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The builder stage should explicitly use npm ci instead of npm install for more deterministic and faster builds in production environments. The npm ci command installs dependencies based on package-lock.json exactly, removes node_modules if it exists, and is optimized for CI/CD pipelines.