chore(docker): reduce Docker image size by optimizing dependency installations

- Use multi-stage builds to prune development dependencies
- Achieve reduced final image size by installing only necessary runtime dependencies
This commit is contained in:
Xtrullor73
2024-06-18 01:23:27 -07:00
parent f3f79dfa5f
commit 7cee22ae7f

View File

@@ -1,24 +1,36 @@
# Use an official Node.js version as base image
FROM node:22-slim
# Stage 1: Setup Dependencies
FROM node:22-slim AS dependencies
WORKDIR /app
# Install dependencies, including ffmpeg
# Install runtime dependencies (ffmpeg and chromaprint-tools)
RUN apt-get update && \
apt-get install -y ffmpeg libchromaprint-tools && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
# Set the working directory inside the container
WORKDIR /app
# Copy package.json and package-lock.json to the working directory
# Copy package.json and package-lock.json to install Node.js dependencies
COPY package*.json ./
# Install Node.js dependencies
RUN npm install
# Copy the rest of the application files to the working directory
# Copy source files
COPY . .
# Stage 2: Final Stage
FROM node:22-slim
WORKDIR /app
# Install runtime dependencies again (ffmpeg and chromaprint-tools)
RUN apt-get update && \
apt-get install -y ffmpeg libchromaprint-tools && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
# Copy application files and dependencies from dependencies stage
COPY --from=dependencies /app /app
# Prune development dependencies
RUN npm prune --production
# Specify the command to run your CLI application
ENTRYPOINT ["node", "--env-file", ".env", "cli.js"]