docker image to alpine, reduce size, compile scripts, entrypoint for alpine

This commit is contained in:
2025-09-28 20:47:23 +01:00
parent d4aa460f91
commit 43c0cf1359
4 changed files with 164 additions and 49 deletions
+19 -8
View File
@@ -14,8 +14,8 @@ RUN \
fi
# Rebuild the source code only when needed
FROM base AS builder
RUN apt-get update && apt-get install -y python3 make g++ && rm -rf /var/lib/apt/lists/*
FROM node:22-alpine AS builder
RUN apk add --no-cache python3 make g++ curl
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .
@@ -23,12 +23,21 @@ COPY . .
# Rebuild better-sqlite3 for Alpine Linux
RUN npm rebuild better-sqlite3
# Build TypeScript database scripts to JavaScript
RUN node build-scripts.js
# Build the application
RUN npm run build
# Remove development-only dependencies and dedupe after build
RUN npm prune --omit=dev && npm dedupe --prod \
&& find node_modules -type f \( -name "README" -o -name "README.*" -o -name "CHANGELOG*" -o -name "*.md" -o -name "*.map" \) -delete \
&& find node_modules -type d \( -name "__tests__" -o -name "test" -o -name "tests" -o -name "docs" -o -name "examples" \) -prune -exec rm -rf {} + \
&& npm cache clean --force
# Production image, copy all the files and run next
FROM base AS runner
RUN apt-get update && apt-get install -y curl && rm -rf /var/lib/apt/lists/*
FROM node:22-alpine AS runner
RUN apk add --no-cache curl
WORKDIR /app
ENV NODE_ENV=production
@@ -38,17 +47,19 @@ ENV NEXT_TELEMETRY_DISABLED=1
COPY --from=builder /app/.next/standalone ./
COPY --from=builder --chown=root:root /app/.next/static ./.next/static
# Copy full node_modules for database operations
# Copy compiled database scripts instead of TypeScript sources
COPY --from=builder /app/dist ./dist
# Copy minimal runtime dependencies for database operations
COPY --from=builder /app/node_modules ./node_modules
# Copy database setup scripts and package.json
COPY --from=builder /app/scripts ./scripts
# Copy database config and package.json
COPY --from=builder /app/lib ./lib
COPY --from=builder /app/drizzle.config.ts ./drizzle.config.ts
COPY --from=builder /app/package.json ./package.json
# Copy entrypoint script
COPY docker-entrypoint.sh /usr/local/bin/
COPY docker-entrypoint-alpine.sh /usr/local/bin/docker-entrypoint.sh
RUN chmod +x /usr/local/bin/docker-entrypoint.sh
# Create public directory if it doesn't exist