improve docker build

This commit is contained in:
Christian Kellner
2025-05-26 13:20:12 +02:00
parent 78a122b3ea
commit 2fd03bce79
2 changed files with 18 additions and 30 deletions

View File

@@ -1,7 +1,6 @@
node_modules/
npm-debug.log
test/
conf/
db/
.git/
.github/

View File

@@ -1,46 +1,35 @@
# Stage 1: build
FROM node:22-slim AS builder
FROM node:22-slim
WORKDIR /fredy
# Install Chromium without extra recommended packages and clean apt cache
RUN apt-get update && apt-get install -y --no-install-recommends chromium \
&& rm -rf /var/lib/apt/lists/*
RUN apt-get update \
&& apt-get install -y --no-install-recommends chromium \
&& rm -rf /var/lib/apt/lists/*
ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true \
PUPPETEER_EXECUTABLE_PATH=/usr/bin/chromium
# Copy manifest for better cache usage
# Copy lockfiles first to leverage cache for dependencies
COPY package.json yarn.lock ./
# Increase yarn timeout, install deps and pm2 globally
# Set Yarn timeout, install dependencies and PM2 globally
RUN yarn config set network-timeout 600000 \
&& yarn install --frozen-lockfile \
&& yarn global add pm2
&& yarn install --frozen-lockfile \
&& yarn global add pm2
# Copy app sources and build production assets
COPY . .
# Copy application source and build production assets
COPY . ./
RUN yarn run prod
# Stage 2: runtime
FROM node:22-slim AS runner
WORKDIR /fredy
# Copy entire build directory from builder instead of individual folders
COPY --from=builder /fredy /fredy
# Copy Chromium executable
COPY --from=builder /usr/bin/chromium /usr/bin/chromium
# Create non-root user, prepare volumes and permissions
RUN groupadd -r app && useradd -r -g app app \
&& mkdir /db /conf \
&& chown app:app /db /conf \
&& chmod 777 /db /conf
USER app
# Prepare runtime directories and symlinks for data and config
RUN mkdir -p /db /conf \
&& chown 1000:1000 /db /conf \
&& chmod 777 /db /conf \
&& ln -s /db /fredy/db \
&& ln -s /conf /fredy/conf
EXPOSE 9998
# Run with pm2-runtime for proper process management
CMD ["pm2-runtime", "index.js"]
# Start application using PM2 runtime
CMD ["pm2-runtime", "index.js"]