mirror of
https://github.com/ManInDark/HabitTrove.git
synced 2026-01-20 22:24:28 +01:00
feat: optimize Docker build performance and add version validation (#176)
This commit is contained in:
@@ -9,3 +9,15 @@ npm-debug.log
|
||||
data
|
||||
CLAUDE.md
|
||||
docs/
|
||||
Budfile
|
||||
PLAN.md
|
||||
/backups/
|
||||
/data.bak/
|
||||
/coverage/
|
||||
*.md
|
||||
!README.md
|
||||
!CHANGELOG.md
|
||||
tags
|
||||
tsconfig.tsbuildinfo
|
||||
.env.local
|
||||
.env.*.local
|
||||
|
||||
10
.husky/pre-commit
Normal file → Executable file
10
.husky/pre-commit
Normal file → Executable file
@@ -1 +1,11 @@
|
||||
#!/bin/sh
|
||||
# Check that package.json version exists in CHANGELOG.md
|
||||
VERSION=$(node -p "require('./package.json').version")
|
||||
if ! grep -q "## Version $VERSION" CHANGELOG.md; then
|
||||
echo "❌ Error: Version $VERSION from package.json not found in CHANGELOG.md"
|
||||
echo "Please add an entry for version $VERSION in CHANGELOG.md"
|
||||
exit 1
|
||||
fi
|
||||
echo "✅ Version $VERSION found in CHANGELOG.md"
|
||||
|
||||
npm run typecheck && npm run lint && npm run test
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
# Changelog
|
||||
|
||||
## Version 0.2.26
|
||||
|
||||
### Improved
|
||||
|
||||
* Docker build performance optimization with cache mounts
|
||||
|
||||
## Version 0.2.25
|
||||
|
||||
### Added
|
||||
|
||||
11
CLAUDE.md
11
CLAUDE.md
@@ -24,6 +24,15 @@ HabitTrove is a gamified habit tracking PWA built with Next.js 15, TypeScript, a
|
||||
- `docker compose up -d` - Run with docker-compose (recommended)
|
||||
- Requires `AUTH_SECRET` environment variable: `openssl rand -base64 32`
|
||||
|
||||
## Version Management
|
||||
|
||||
### Creating a New Version
|
||||
1. Update version in `package.json`
|
||||
2. Update `CHANGELOG.md` with new version and changes (follow existing patterns in the file)
|
||||
3. Run `npm run typecheck && npm run lint` to ensure code quality
|
||||
4. Commit changes: `git add . && git commit -m "feat: description"`
|
||||
* Follow Conventional Commits Standard: `<type>[scope]: <description>` (e.g., `feat(auth): add OAuth integration`, `fix: resolve memory leak in task loader`).
|
||||
|
||||
## Architecture Overview
|
||||
|
||||
### State Management (Jotai)
|
||||
@@ -88,4 +97,4 @@ Reference `CoinsManager.tsx:107-119` for admin user selection implementation. Si
|
||||
## Performance Considerations
|
||||
- State updates use immutable patterns
|
||||
- Large dataset filtering happens at hook level
|
||||
- Derived atoms prevent unnecessary re-renders
|
||||
- Derived atoms prevent unnecessary re-renders
|
||||
|
||||
29
Dockerfile
29
Dockerfile
@@ -1,18 +1,17 @@
|
||||
# syntax=docker.io/docker/dockerfile:1
|
||||
|
||||
FROM node:18-alpine AS base
|
||||
# Use build platform for base images to avoid emulation
|
||||
FROM --platform=$BUILDPLATFORM node:22-alpine AS base
|
||||
|
||||
# Install dependencies only when needed
|
||||
FROM base AS deps
|
||||
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
|
||||
RUN apk add --no-cache libc6-compat
|
||||
WORKDIR /app
|
||||
|
||||
# Install dependencies based on the preferred package manager
|
||||
# Use cache mounts for npm cache
|
||||
COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* .npmrc* ./
|
||||
RUN \
|
||||
RUN --mount=type=cache,target=/root/.npm \
|
||||
if [ -f yarn.lock ]; then yarn --frozen-lockfile; \
|
||||
# use --force flag until all deps supports react19
|
||||
elif [ -f package-lock.json ]; then npm ci --force; \
|
||||
elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm i --frozen-lockfile; \
|
||||
else echo "Lockfile not found." && exit 1; \
|
||||
@@ -26,32 +25,28 @@ COPY . .
|
||||
|
||||
ENV NEXT_TELEMETRY_DISABLED=1
|
||||
|
||||
RUN \
|
||||
# Use cache mount for Next.js cache
|
||||
RUN --mount=type=cache,target=/app/.next/cache \
|
||||
if [ -f yarn.lock ]; then yarn run build; \
|
||||
elif [ -f package-lock.json ]; then npm run build; \
|
||||
elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm run build; \
|
||||
else echo "Lockfile not found." && exit 1; \
|
||||
fi
|
||||
|
||||
# Production image, copy all the files and run next
|
||||
FROM base AS runner
|
||||
# Production image - use target platform
|
||||
FROM node:22-alpine AS runner
|
||||
WORKDIR /app
|
||||
|
||||
ENV NODE_ENV=production
|
||||
ENV NEXT_TELEMETRY_DISABLED=1
|
||||
|
||||
RUN addgroup --system --gid 1001 nodejs
|
||||
RUN adduser --system --uid 1001 nextjs
|
||||
|
||||
# Create data and backups directories and set permissions
|
||||
RUN mkdir -p /app/data /app/backups \
|
||||
&& chown nextjs:nodejs /app/data /app/backups
|
||||
RUN addgroup --system --gid 1001 nodejs && \
|
||||
adduser --system --uid 1001 nextjs && \
|
||||
mkdir -p /app/data /app/backups && \
|
||||
chown nextjs:nodejs /app/data /app/backups
|
||||
|
||||
COPY --from=builder /app/public ./public
|
||||
COPY --from=builder /app/CHANGELOG.md ./
|
||||
|
||||
# Automatically leverage output traces to reduce image size
|
||||
# https://nextjs.org/docs/advanced-features/output-file-tracing
|
||||
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
|
||||
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "habittrove",
|
||||
"version": "0.2.25",
|
||||
"version": "0.2.26",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"dev": "next dev --turbopack",
|
||||
|
||||
Reference in New Issue
Block a user