northwind-api-gateway / Dockerfile
mishrabp's picture
Upload folder using huggingface_hub
f8a3d63 verified
# Use an official Node.js runtime as a parent image
FROM node:20-alpine AS builder
# Create app directory and set permissions
RUN mkdir -p /app /app/logs && \
chown -R node:node /app
# Set working directory
WORKDIR /app
# Copy package files first for better caching
COPY --chown=node:node package*.json ./
COPY --chown=node:node ./apps/apigateway/package*.json ./apps/apigateway/
COPY --chown=node:node ./libs/proto ./libs/proto
# Switch to non-root user
USER node
# Install dependencies
RUN npm ci
# Copy the rest of the app's source code
COPY --chown=node:node . .
# Build the NestJS app
RUN npm run build:apigateway
# Create production image
FROM node:20-alpine
# Create app directory and set permissions
RUN mkdir -p /app /app/logs && \
chown -R node:node /app
WORKDIR /app
# Copy built files from builder
COPY --from=builder --chown=node:node /app/dist ./dist
COPY --from=builder --chown=node:node /app/libs/proto ./libs/proto
COPY --from=builder --chown=node:node /app/package*.json ./
COPY --from=builder --chown=node:node /app/node_modules ./node_modules
# Switch to non-root user
USER node
# Expose app port
EXPOSE 8080
# Start the application
CMD ["node", "dist/apps/apigateway/main.js"]