Skip to content

Commit f2140ca

Browse files
committed
build: Consolidate dependencies and optimize Dockerfile
Consolidate server dependencies into root package.json. Refactor Dockerfile to use multi-stage build, build CSS, run as non-root user, and install production dependencies only. Update .gitignore and docker-compose.yml build context.
1 parent 6602588 commit f2140ca

File tree

7 files changed

+1169
-1503
lines changed

7 files changed

+1169
-1503
lines changed

.gitignore

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,34 @@ yarn-debug.log*
1313
yarn-error.log*
1414
lerna-debug.log*
1515

16+
# Diagnostic reports (https://nodejs.org/api/report.html)
17+
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
18+
19+
# Runtime data
20+
pids
21+
*.pid
22+
*.seed
23+
*.pid.lock
24+
25+
# Directory for instrumented libs generated by jscoverage/JSCover
26+
lib-cov
27+
28+
# Coverage directory used by tools like istanbul
29+
coverage
30+
*.lcov
31+
32+
# nyc test coverage
33+
.nyc_output
34+
35+
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
36+
.grunt
37+
38+
# node-waf configuration
39+
.lock-wscript
40+
41+
# Compiled binary addons (https://nodejs.org/api/addons.html)
42+
build/Release
43+
1644
# Build outputs
1745
build/
1846
dist/
@@ -49,4 +77,10 @@ jspm_packages/
4977
/coverage/
5078

5179
# Local configuration files
52-
RELEASE_CHECKLIST.md
80+
RELEASE_CHECKLIST.md
81+
82+
# Lockfiles
83+
# package-lock.json # Usually committed, but ignore if specified elsewhere
84+
server/package-lock.json
85+
yarn.lock
86+
pnpm-lock.yaml

Dockerfile

Lines changed: 45 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,57 @@
1-
# Use an official Node runtime as a parent image
2-
# Choose a version compatible with your application (e.g., LTS version like 18 or 20)
3-
FROM node:18-alpine
1+
# ---- Builder Stage ----
2+
FROM node:18-alpine AS builder
43

5-
# Set the working directory in the container
64
WORKDIR /usr/src/app
75

8-
# Copy package.json and package-lock.json for root dependencies
6+
# Install necessary build tools (if any, e.g., python, make for some native deps)
7+
# RUN apk add --no-cache ...
8+
9+
# Copy only necessary package files first
910
COPY package*.json ./
1011

11-
# Install root dependencies
12-
RUN npm install
12+
# Install ALL dependencies (including dev needed for build)
13+
# Using npm ci for faster, more reliable builds in CI/CD
14+
RUN npm ci
1315

14-
# Copy server package.json and package-lock.json
15-
COPY server/package*.json ./server/
16+
# Copy the rest of the application code
17+
# Important: Copy . before running build commands
18+
COPY . .
1619

17-
# Install server dependencies
18-
RUN cd server && npm install
20+
# Build the production CSS
21+
RUN npm run build:css
1922

20-
# Copy the rest of the application code
21-
# Copy server code first
22-
COPY server/ ./server/
23-
# Copy public directory into src/public to match server path expectations
24-
COPY src/public/ ./src/public/
23+
# Prune devDependencies after build
24+
RUN npm prune --production
25+
26+
# ---- Runner Stage ----
27+
FROM node:18-alpine
28+
29+
WORKDIR /usr/src/app
2530

26-
# Application listens on port 7655 by default (as per .env.example)
31+
# Create a non-root user and group
32+
RUN addgroup -S appgroup && adduser -S appuser -G appgroup
33+
34+
# Copy necessary files from builder stage
35+
# Copy node_modules first (can be large)
36+
COPY --from=builder /usr/src/app/node_modules ./node_modules
37+
# Copy built assets
38+
COPY --from=builder /usr/src/app/src/public ./src/public
39+
# Copy server code
40+
COPY --from=builder /usr/src/app/server ./server
41+
# Copy root package.json needed for npm start and potentially other metadata
42+
COPY --from=builder /usr/src/app/package.json ./
43+
# Optionally copy other root files if needed by the application (e.g., .env.example, README)
44+
# COPY --from=builder /usr/src/app/.env.example ./
45+
46+
# Ensure correct ownership of application files
47+
# Use /usr/src/app to cover everything copied
48+
RUN chown -R appuser:appgroup /usr/src/app
49+
50+
# Switch to non-root user
51+
USER appuser
52+
53+
# Expose port
2754
EXPOSE 7655
2855

29-
# Define the command to run the app using the start script from root package.json
30-
# This script should handle changing into the server directory
56+
# Run the application using the start script
3157
CMD [ "npm", "run", "start" ]

docker-compose.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
services:
22
pulse-server:
33
# Build context commented out - using pre-built image from Docker Hub
4-
# build:
5-
# context: .
6-
# dockerfile: Dockerfile
7-
image: rcourtman/pulse:latest # Use the pre-built image from Docker Hub
4+
build:
5+
context: .
6+
dockerfile: Dockerfile
7+
# image: rcourtman/pulse:latest # Use the pre-built image from Docker Hub
88
container_name: pulse
99
restart: unless-stopped
1010
ports:

0 commit comments

Comments
 (0)