bhavikprit commited on
Commit
679f2be
·
unverified ·
1 Parent(s): cd0dfc3

fix: improve Docker build reliability and layer caching (#137)

Browse files

- Fix deps stage: copy only package.json + pnpm-lock.yaml* for proper
layer caching instead of COPY . . which invalidates cache on any change
- Copy node_modules from deps into build stage separately from source
- Copy schema.sql into runtime stage (migration 001_init reads it at
runtime via process.cwd(), but standalone output omits source files)
- Remove broken public* glob COPY (no public/ dir exists; Docker COPY
fails silently with incorrect glob syntax)
- docker-compose: add container_name, configurable port via MC_PORT,
mark .env as optional to avoid startup failure if missing

Fixes #129

Files changed (2) hide show
  1. Dockerfile +7 -5
  2. docker-compose.yml +5 -2
Dockerfile CHANGED
@@ -3,19 +3,21 @@ RUN corepack enable && corepack prepare pnpm@latest --activate
3
  WORKDIR /app
4
 
5
  FROM base AS deps
 
6
  COPY package.json ./
7
- COPY . .
8
  # better-sqlite3 requires native compilation tools
9
  RUN apt-get update && apt-get install -y python3 make g++ --no-install-recommends && rm -rf /var/lib/apt/lists/*
10
  RUN if [ -f pnpm-lock.yaml ]; then \
11
  pnpm install --frozen-lockfile; \
12
  else \
13
- echo "WARN: pnpm-lock.yaml not found in build context; running non-frozen install"; \
14
  pnpm install --no-frozen-lockfile; \
15
  fi
16
 
17
  FROM base AS build
18
- COPY --from=deps /app ./
 
19
  RUN pnpm build
20
 
21
  FROM node:20-slim AS runtime
@@ -24,8 +26,8 @@ ENV NODE_ENV=production
24
  RUN addgroup --system --gid 1001 nodejs && adduser --system --uid 1001 nextjs
25
  COPY --from=build /app/.next/standalone ./
26
  COPY --from=build /app/.next/static ./.next/static
27
- # Copy public directory if it exists (may not exist in all setups)
28
- COPY --from=build /app/public* ./public/
29
  # Create data directory with correct ownership for SQLite
30
  RUN mkdir -p .data && chown nextjs:nodejs .data
31
  RUN apt-get update && apt-get install -y curl --no-install-recommends && rm -rf /var/lib/apt/lists/*
 
3
  WORKDIR /app
4
 
5
  FROM base AS deps
6
+ # Copy only dependency manifests first for better layer caching
7
  COPY package.json ./
8
+ COPY pnpm-lock.yaml* ./
9
  # better-sqlite3 requires native compilation tools
10
  RUN apt-get update && apt-get install -y python3 make g++ --no-install-recommends && rm -rf /var/lib/apt/lists/*
11
  RUN if [ -f pnpm-lock.yaml ]; then \
12
  pnpm install --frozen-lockfile; \
13
  else \
14
+ echo "WARN: pnpm-lock.yaml not found in build context; running non-frozen install" && \
15
  pnpm install --no-frozen-lockfile; \
16
  fi
17
 
18
  FROM base AS build
19
+ COPY --from=deps /app/node_modules ./node_modules
20
+ COPY . .
21
  RUN pnpm build
22
 
23
  FROM node:20-slim AS runtime
 
26
  RUN addgroup --system --gid 1001 nodejs && adduser --system --uid 1001 nextjs
27
  COPY --from=build /app/.next/standalone ./
28
  COPY --from=build /app/.next/static ./.next/static
29
+ # Copy schema.sql needed by migration 001_init at runtime
30
+ COPY --from=build /app/src/lib/schema.sql ./src/lib/schema.sql
31
  # Create data directory with correct ownership for SQLite
32
  RUN mkdir -p .data && chown nextjs:nodejs .data
33
  RUN apt-get update && apt-get install -y curl --no-install-recommends && rm -rf /var/lib/apt/lists/*
docker-compose.yml CHANGED
@@ -1,9 +1,12 @@
1
  services:
2
  mission-control:
3
  build: .
 
4
  ports:
5
- - "3000:3000"
6
- env_file: .env
 
 
7
  volumes:
8
  - mc-data:/app/.data
9
  restart: unless-stopped
 
1
  services:
2
  mission-control:
3
  build: .
4
+ container_name: mission-control
5
  ports:
6
+ - "${MC_PORT:-3000}:3000"
7
+ env_file:
8
+ - path: .env
9
+ required: false
10
  volumes:
11
  - mc-data:/app/.data
12
  restart: unless-stopped