🏗️ Added a builder step

This commit is contained in:
2025-02-25 15:36:44 -05:00
parent 58168b1a9c
commit a2eae27c31

View File

@@ -1,17 +1,14 @@
# Use a non-ARM image (x86_64) for Node.js # Stage 1: Build Stage (Builder)
FROM --platform=linux/amd64 node:21-alpine3.18 FROM node:21-alpine3.18 AS builder
# Set metadata for contact # Set environment variables for build
LABEL maintainer="Rishi Ghan <rishi.ghan@gmail.com>"
# Set environment variables
ENV NPM_CONFIG_LOGLEVEL=warn ENV NPM_CONFIG_LOGLEVEL=warn
ENV NODE_ENV=production ENV NODE_ENV=production
# Set the working directory # Set the working directory
WORKDIR /core-services WORKDIR /core-services
# Install required dependencies using apk # Install build dependencies using apk
RUN apk update && apk add --no-cache \ RUN apk update && apk add --no-cache \
bash \ bash \
wget \ wget \
@@ -46,10 +43,7 @@ RUN wget https://www.rarlab.com/rar/rarlinux-x64-621.tar.gz \
&& cp rar/unrar /usr/bin/ \ && cp rar/unrar /usr/bin/ \
&& rm -rf rarlinux-x64-621.tar.gz rar && rm -rf rarlinux-x64-621.tar.gz rar
# Verify Node.js installation # Copy application configuration files to build environment
RUN node -v && npm -v
# Copy application configuration files
COPY package.json package-lock.json ./ COPY package.json package-lock.json ./
COPY moleculer.config.ts ./ COPY moleculer.config.ts ./
COPY tsconfig.json ./ COPY tsconfig.json ./
@@ -57,18 +51,39 @@ COPY tsconfig.json ./
# Install application dependencies # Install application dependencies
RUN npm install RUN npm install
# Install sharp with proper platform configuration # Install sharp with platform-specific binaries
RUN npm install --force sharp --platform=linux/amd64 RUN npm install sharp --build-from-source
# Install global dependencies # Install global dependencies
RUN npm install -g typescript ts-node RUN npm install -g typescript ts-node
# Copy the rest of the application files # Stage 2: Final Stage (Run Environment)
COPY . . FROM node:21-alpine3.18 AS runtime
# Build and clean up # Set environment variables for runtime
RUN npm run build \ ENV NODE_ENV=production
&& npm prune ENV NPM_CONFIG_LOGLEVEL=warn
# Set the working directory
WORKDIR /core-services
# Install runtime dependencies using apk (keep only what is needed to run the app)
RUN apk update && apk add --no-cache \
bash \
imagemagick \
python3 \
xvfb \
p7zip \
curl \
git \
glib \
cairo-dev \
pango-dev \
icu-dev \
pkgconfig
# Copy only necessary files from the builder stage
COPY --from=builder /core-services /core-services
# Expose the application's port # Expose the application's port
EXPOSE 3000 EXPOSE 3000