From f337c0f3e6a7d192a171eab70ed11ebd17ad0e74 Mon Sep 17 00:00:00 2001 From: Rishi Ghan Date: Tue, 25 Feb 2025 16:20:44 -0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=B3=20Updated=20Dockerfile=20to=20use?= =?UTF-8?q?=20a=20builder=20step?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/Dockerfile b/Dockerfile index ca6a9b1..769dce7 100644 --- a/Dockerfile +++ b/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 " -# Working directory +# Set the working directory WORKDIR /metadata-service -# Install dependencies + +# Copy and install dependencies COPY package.json package-lock.json ./ RUN npm ci --silent -# Copy source +# Copy source code and build the application 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 " + +# 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 -RUN npm run build \ - && npm prune +# Expose the application's port EXPOSE 3080 -# Start server -CMD ["npm", "start"] \ No newline at end of file + +# Start the application +CMD ["npm", "start"]