# Build stage
FROM node:20-slim AS builder
# Create app directory
WORKDIR /app
# Install app dependencies
COPY package*.json ./
RUN npm ci
# Copy source code
COPY . .
# Build the application
RUN npm run build
# Production stage
FROM node:20-slim
# Install SQL Server tools
RUN apt-get update && apt-get install -y \
gnupg \
curl \
&& curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add - \
&& curl https://packages.microsoft.com/config/debian/11/prod.list > /etc/apt/sources.list.d/mssql-release.list \
&& apt-get update \
&& ACCEPT_EULA=Y apt-get install -y msodbcsql18 mssql-tools18 \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
# Create app directory
WORKDIR /app
# Copy package files
COPY package*.json ./
# Install production dependencies only
RUN npm ci --only=production
# Copy built application
COPY --from=builder /app/build ./build
# Set environment variables
ENV NODE_ENV=production
# Add node_modules/.bin to PATH
ENV PATH="/app/node_modules/.bin:${PATH}"
# Make the application executable
RUN chmod +x build/index.js
# Command to run the application
CMD ["node", "build/index.js"]