Compare commits

..

1 Commits

Author SHA1 Message Date
jango-blockchained
905339fb67 refactor(docker): switch to Node.js base image and optimize Bun installation
- Replace Bun base image with Node.js slim image
- Install Bun globally using npm in both builder and runner stages
- Simplify Docker build process and dependency management
- Remove unnecessary environment variables and build flags
- Update docker-build.sh to use BuildKit and remove lockfile before build
2025-02-04 20:18:46 +01:00
2 changed files with 18 additions and 14 deletions

View File

@@ -1,9 +1,12 @@
# Use Bun as the base image with specific platform for better optimization
FROM --platform=linux/amd64 oven/bun:1.2.2-slim as builder
# Use Node.js as base for building
FROM node:20-slim as builder
# Set working directory
WORKDIR /app
# Install bun
RUN npm install -g bun@1.0.25
# Install only the minimal dependencies needed and clean up in the same layer
RUN apt-get update && apt-get install -y --no-install-recommends \
ca-certificates \
@@ -14,30 +17,28 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
# Set build-time environment variables
ENV NODE_ENV=production \
NODE_OPTIONS="--max-old-space-size=2048" \
BUN_INSTALL_CACHE=false \
BUN_INSTALL_VERBOSE=true
NODE_OPTIONS="--max-old-space-size=2048"
# Copy only package files first
COPY package.json ./
COPY tsconfig*.json ./
# Install ALL dependencies (including devDependencies) for build
RUN bun install --no-cache \
--no-progress \
&& rm -rf ~/.bun/install/cache
# Install dependencies without lockfile
RUN bun install --no-cache
# Copy source files and build
COPY src ./src
COPY tsconfig*.json ./
RUN bun build ./src/index.ts --target=bun --minify --outdir=./dist
# Create a smaller production image
FROM --platform=linux/amd64 oven/bun:1.2.2-slim as runner
FROM node:20-slim as runner
# Install bun in production image
RUN npm install -g bun@1.0.25
# Set production environment variables
ENV NODE_ENV=production \
NODE_OPTIONS="--max-old-space-size=1024" \
BUN_INSTALL_CACHE=false
NODE_OPTIONS="--max-old-space-size=1024"
# Create a non-root user
RUN addgroup --system --gid 1001 nodejs && \

View File

@@ -28,9 +28,12 @@ CPU_QUOTA=$(( CPU_COUNT * 50000 )) # Allow 50% CPU usage per core
echo "Building with ${BUILD_MEM}MB memory limit and CPU quota ${CPU_QUOTA}"
# Remove any existing lockfile
rm -f bun.lockb
# Build with resource limits, optimizations, and timeout
echo "Building Docker image..."
timeout 15m docker build \
DOCKER_BUILDKIT=1 docker build \
--memory="${BUILD_MEM}m" \
--memory-swap="${BUILD_MEM}m" \
--cpu-quota="${CPU_QUOTA}" \