chore: Optimized Dockerfile and .dockerignore for faster deployments.
This commit is contained in:
@@ -1,12 +1,21 @@
|
|||||||
node_modules
|
node_modules/
|
||||||
build
|
build/
|
||||||
.svelte-kit
|
.svelte-kit/
|
||||||
.git
|
.git/
|
||||||
.env
|
.env
|
||||||
.env.*
|
.env.*
|
||||||
!.env.staging
|
!.env.staging
|
||||||
!.env.prod
|
!.env.prod
|
||||||
npm_deploy
|
npm_deploy/
|
||||||
test-results
|
test-results/
|
||||||
test_results
|
test_results/
|
||||||
documentation
|
documentation/
|
||||||
|
backups/
|
||||||
|
*.log
|
||||||
|
*.bak
|
||||||
|
.claude/
|
||||||
|
.vscode/
|
||||||
|
npm-debug.log*
|
||||||
|
yarn-debug.log*
|
||||||
|
yarn-error.log*
|
||||||
|
.pnpm-debug.log*
|
||||||
|
|||||||
16
Dockerfile
16
Dockerfile
@@ -1,10 +1,8 @@
|
|||||||
# Stage 1: Build the application
|
# Stage 1: Build the application
|
||||||
# node:22-alpine — Node 22 is the current Active LTS (supported through April 2027).
|
FROM node:24-alpine AS builder
|
||||||
FROM node:22-alpine AS builder
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
# Install dependencies first for better Docker layer caching.
|
# Install dependencies first for better Docker layer caching.
|
||||||
# This step only reruns if package.json or package-lock.json changes.
|
|
||||||
COPY package*.json ./
|
COPY package*.json ./
|
||||||
RUN npm install
|
RUN npm install
|
||||||
|
|
||||||
@@ -12,17 +10,13 @@ RUN npm install
|
|||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
# Build Argument to determine build environment (staging, prod, or production).
|
# Build Argument to determine build environment (staging, prod, or production).
|
||||||
# Defaults to "staging".
|
|
||||||
ARG BUILD_MODE=staging
|
ARG BUILD_MODE=staging
|
||||||
ENV NODE_ENV=production
|
ENV NODE_ENV=production
|
||||||
|
|
||||||
# Sync the SvelteKit project to generate ./.svelte-kit/tsconfig.json
|
# Sync the SvelteKit project to generate ./.svelte-kit/tsconfig.json
|
||||||
# and other required files, which avoids the build warning.
|
|
||||||
RUN npx svelte-kit sync
|
RUN npx svelte-kit sync
|
||||||
|
|
||||||
# Perform the build based on the BUILD_MODE argument.
|
# Perform the build based on the BUILD_MODE argument.
|
||||||
# This runs the existing scripts in package.json, which already
|
|
||||||
# handle copying the correct .env file to .env.production for Vite.
|
|
||||||
RUN if [ "$BUILD_MODE" = "prod" ] || [ "$BUILD_MODE" = "production" ]; then \
|
RUN if [ "$BUILD_MODE" = "prod" ] || [ "$BUILD_MODE" = "production" ]; then \
|
||||||
npm run build:prod; \
|
npm run build:prod; \
|
||||||
else \
|
else \
|
||||||
@@ -30,18 +24,18 @@ RUN if [ "$BUILD_MODE" = "prod" ] || [ "$BUILD_MODE" = "production" ]; then \
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# Stage 2: Final runtime image
|
# Stage 2: Final runtime image
|
||||||
FROM node:22-alpine AS deploy-node
|
FROM node:24-alpine AS deploy-node
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
# Copy only the built files and necessary scripts from the builder stage.
|
# Copy built files and package info.
|
||||||
COPY --from=builder /app/build .
|
COPY --from=builder /app/build .
|
||||||
COPY --from=builder /app/package.json .
|
COPY --from=builder /app/package.json .
|
||||||
|
COPY --from=builder /app/package-lock.json .
|
||||||
|
|
||||||
# Install only production dependencies for a smaller, cleaner image.
|
# Install only production dependencies.
|
||||||
RUN npm install --omit=dev
|
RUN npm install --omit=dev
|
||||||
|
|
||||||
# Copy the resulting .env.production file to .env.
|
# Copy the resulting .env.production file to .env.
|
||||||
# adapter-node reads from .env at runtime for non-PUBLIC_ variables.
|
|
||||||
COPY --from=builder /app/.env.production .env
|
COPY --from=builder /app/.env.production .env
|
||||||
|
|
||||||
# SvelteKit (via adapter-node) defaults to port 3000.
|
# SvelteKit (via adapter-node) defaults to port 3000.
|
||||||
|
|||||||
Reference in New Issue
Block a user