Skip to content

Commit ee2821b

Browse files
authored
feat: optimize Docker build performance and add version validation (#176)
1 parent 8fb7cd1 commit ee2821b

File tree

6 files changed

+51
-19
lines changed

6 files changed

+51
-19
lines changed

.dockerignore

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,15 @@ npm-debug.log
99
data
1010
CLAUDE.md
1111
docs/
12+
Budfile
13+
PLAN.md
14+
/backups/
15+
/data.bak/
16+
/coverage/
17+
*.md
18+
!README.md
19+
!CHANGELOG.md
20+
tags
21+
tsconfig.tsbuildinfo
22+
.env.local
23+
.env.*.local

.husky/pre-commit

100644100755
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,11 @@
1+
#!/bin/sh
2+
# Check that package.json version exists in CHANGELOG.md
3+
VERSION=$(node -p "require('./package.json').version")
4+
if ! grep -q "## Version $VERSION" CHANGELOG.md; then
5+
echo "❌ Error: Version $VERSION from package.json not found in CHANGELOG.md"
6+
echo "Please add an entry for version $VERSION in CHANGELOG.md"
7+
exit 1
8+
fi
9+
echo "✅ Version $VERSION found in CHANGELOG.md"
10+
111
npm run typecheck && npm run lint && npm run test

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## Version 0.2.26
4+
5+
### Improved
6+
7+
* Docker build performance optimization with cache mounts
8+
39
## Version 0.2.25
410

511
### Added

CLAUDE.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,15 @@ HabitTrove is a gamified habit tracking PWA built with Next.js 15, TypeScript, a
2424
- `docker compose up -d` - Run with docker-compose (recommended)
2525
- Requires `AUTH_SECRET` environment variable: `openssl rand -base64 32`
2626

27+
## Version Management
28+
29+
### Creating a New Version
30+
1. Update version in `package.json`
31+
2. Update `CHANGELOG.md` with new version and changes (follow existing patterns in the file)
32+
3. Run `npm run typecheck && npm run lint` to ensure code quality
33+
4. Commit changes: `git add . && git commit -m "feat: description"`
34+
* Follow Conventional Commits Standard: `<type>[scope]: <description>` (e.g., `feat(auth): add OAuth integration`, `fix: resolve memory leak in task loader`).
35+
2736
## Architecture Overview
2837

2938
### State Management (Jotai)
@@ -88,4 +97,4 @@ Reference `CoinsManager.tsx:107-119` for admin user selection implementation. Si
8897
## Performance Considerations
8998
- State updates use immutable patterns
9099
- Large dataset filtering happens at hook level
91-
- Derived atoms prevent unnecessary re-renders
100+
- Derived atoms prevent unnecessary re-renders

Dockerfile

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
# syntax=docker.io/docker/dockerfile:1
22

3-
FROM node:18-alpine AS base
3+
# Use build platform for base images to avoid emulation
4+
FROM --platform=$BUILDPLATFORM node:22-alpine AS base
45

56
# Install dependencies only when needed
67
FROM base AS deps
7-
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
88
RUN apk add --no-cache libc6-compat
99
WORKDIR /app
1010

11-
# Install dependencies based on the preferred package manager
11+
# Use cache mounts for npm cache
1212
COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* .npmrc* ./
13-
RUN \
13+
RUN --mount=type=cache,target=/root/.npm \
1414
if [ -f yarn.lock ]; then yarn --frozen-lockfile; \
15-
# use --force flag until all deps supports react19
1615
elif [ -f package-lock.json ]; then npm ci --force; \
1716
elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm i --frozen-lockfile; \
1817
else echo "Lockfile not found." && exit 1; \
@@ -26,32 +25,28 @@ COPY . .
2625

2726
ENV NEXT_TELEMETRY_DISABLED=1
2827

29-
RUN \
28+
# Use cache mount for Next.js cache
29+
RUN --mount=type=cache,target=/app/.next/cache \
3030
if [ -f yarn.lock ]; then yarn run build; \
3131
elif [ -f package-lock.json ]; then npm run build; \
3232
elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm run build; \
3333
else echo "Lockfile not found." && exit 1; \
3434
fi
3535

36-
# Production image, copy all the files and run next
37-
FROM base AS runner
36+
# Production image - use target platform
37+
FROM node:22-alpine AS runner
3838
WORKDIR /app
3939

4040
ENV NODE_ENV=production
4141
ENV NEXT_TELEMETRY_DISABLED=1
4242

43-
RUN addgroup --system --gid 1001 nodejs
44-
RUN adduser --system --uid 1001 nextjs
45-
46-
# Create data and backups directories and set permissions
47-
RUN mkdir -p /app/data /app/backups \
48-
&& chown nextjs:nodejs /app/data /app/backups
43+
RUN addgroup --system --gid 1001 nodejs && \
44+
adduser --system --uid 1001 nextjs && \
45+
mkdir -p /app/data /app/backups && \
46+
chown nextjs:nodejs /app/data /app/backups
4947

5048
COPY --from=builder /app/public ./public
5149
COPY --from=builder /app/CHANGELOG.md ./
52-
53-
# Automatically leverage output traces to reduce image size
54-
# https://nextjs.org/docs/advanced-features/output-file-tracing
5550
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
5651
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
5752

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "habittrove",
3-
"version": "0.2.25",
3+
"version": "0.2.26",
44
"private": true,
55
"scripts": {
66
"dev": "next dev --turbopack",

0 commit comments

Comments
 (0)