refactor(docker): optimize Dockerfiles for multi-stage builds and production deployment

- Implement multi-stage builds for main and speech Dockerfiles
- Reduce image size by using slim base images
- Improve dependency installation with frozen lockfile and production flags
- Add resource constraints and healthcheck to speech service Dockerfile
- Enhance build caching and separation of build/runtime dependencies
This commit is contained in:
jango-blockchained
2025-02-04 19:41:23 +01:00
parent 3a6f79c9a8
commit f8bbe4af6f
2 changed files with 60 additions and 30 deletions

View File

@@ -1,14 +1,14 @@
# Use Bun as the base image
FROM oven/bun:1.0.25
FROM oven/bun:1.0.25 as builder
# Set working directory
WORKDIR /app
# Copy package files
COPY package.json ./
# Copy only package files first for better layer caching
COPY package.json bun.lockb ./
# Install dependencies
RUN bun install
# Install dependencies with production flag
RUN bun install --frozen-lockfile --production
# Copy source code
COPY . .
@@ -16,6 +16,19 @@ COPY . .
# Build TypeScript
RUN bun run build
# Create production image
FROM oven/bun:1.0.25-slim
WORKDIR /app
# Copy only the necessary files from builder
COPY --from=builder /app/dist ./dist
COPY --from=builder /app/node_modules ./node_modules
COPY package.json ./
# Set production environment
ENV NODE_ENV=production
# Expose port
EXPOSE 4000