mirror of
https://github.com/xtrll/MusicMetaFinder.git
synced 2026-04-17 15:53:29 +02:00
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:
32
Dockerfile
32
Dockerfile
@@ -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"]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user