router / Dockerfile
waxiangzi's picture
Update Dockerfile
7cd6f06 verified
# Stage 1: Build stage
FROM oven/bun:1.1 as builder
# Set working directory
WORKDIR /app
# Copy package.json and other configuration files
COPY package.json bun.lockb* tsconfig.json ./
# Install dependencies including dev dependencies
RUN bun install --frozen-lockfile
# Copy source code
COPY src/ ./src/
# Stage 2: Production stage
FROM oven/bun:1.1-slim as production
# Set working directory
WORKDIR /app
# Copy package.json and other configuration files
COPY package.json bun.lockb* ./
# Install only production dependencies
RUN bun install --frozen-lockfile --production
# Copy source code from builder stage
COPY --from=builder /app/src ./src
# Create a non-root user and switch to it
RUN addgroup --system --gid 1001 bunuser \
&& adduser --system --uid 1001 --ingroup bunuser bunuser \
&& chown -R bunuser:bunuser /app
USER bunuser
# Expose the port the app runs on
EXPOSE 8000
# Set environment variables
ENV NODE_ENV=production
ENV PORT=8000
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
CMD curl -f http://localhost:8002/https://httpbin.org/status/200 || exit 1
# Run the application
CMD ["bun", "run", "start"]