🐳 Updated Dockerfile to use a builder step
This commit is contained in:
35
Dockerfile
35
Dockerfile
@@ -1,20 +1,37 @@
|
|||||||
FROM node:12-alpine
|
# Use Node 21 as the base image for the builder stage
|
||||||
|
FROM node:21-alpine AS builder
|
||||||
LABEL maintainer="Rishi Ghan <rishi.ghan@gmail.com>"
|
LABEL maintainer="Rishi Ghan <rishi.ghan@gmail.com>"
|
||||||
|
|
||||||
# Working directory
|
# Set the working directory
|
||||||
WORKDIR /metadata-service
|
WORKDIR /metadata-service
|
||||||
# Install dependencies
|
|
||||||
|
# Copy and install dependencies
|
||||||
COPY package.json package-lock.json ./
|
COPY package.json package-lock.json ./
|
||||||
RUN npm ci --silent
|
RUN npm ci --silent
|
||||||
|
|
||||||
# Copy source
|
# Copy source code and build the application
|
||||||
COPY . .
|
COPY . .
|
||||||
|
RUN npm run build
|
||||||
|
|
||||||
# Build and cleanup
|
# Clean up development dependencies
|
||||||
|
RUN npm prune --production
|
||||||
|
|
||||||
|
# Final image using Node 21
|
||||||
|
FROM node:21-alpine
|
||||||
|
|
||||||
|
LABEL maintainer="Rishi Ghan <rishi.ghan@gmail.com>"
|
||||||
|
|
||||||
|
# Set the working directory
|
||||||
|
WORKDIR /metadata-service
|
||||||
|
|
||||||
|
# Copy the necessary files from the builder image
|
||||||
|
COPY --from=builder /metadata-service /metadata-service
|
||||||
|
|
||||||
|
# Set environment variables
|
||||||
ENV NODE_ENV=production
|
ENV NODE_ENV=production
|
||||||
RUN npm run build \
|
|
||||||
&& npm prune
|
|
||||||
|
|
||||||
|
# Expose the application's port
|
||||||
EXPOSE 3080
|
EXPOSE 3080
|
||||||
# Start server
|
|
||||||
CMD ["npm", "start"]
|
# Start the application
|
||||||
|
CMD ["npm", "start"]
|
||||||
|
|||||||
Reference in New Issue
Block a user