mirror of
https://github.com/orangecoding/fredy.git
synced 2026-06-16 12:31:07 +00:00
improve docker build
This commit is contained in:
@@ -1,7 +1,6 @@
|
|||||||
node_modules/
|
node_modules/
|
||||||
npm-debug.log
|
npm-debug.log
|
||||||
test/
|
test/
|
||||||
conf/
|
|
||||||
db/
|
db/
|
||||||
.git/
|
.git/
|
||||||
.github/
|
.github/
|
||||||
|
|||||||
47
Dockerfile
47
Dockerfile
@@ -1,46 +1,35 @@
|
|||||||
# Stage 1: build
|
FROM node:22-slim
|
||||||
FROM node:22-slim AS builder
|
|
||||||
|
|
||||||
WORKDIR /fredy
|
WORKDIR /fredy
|
||||||
|
|
||||||
# Install Chromium without extra recommended packages and clean apt cache
|
# Install Chromium without extra recommended packages and clean apt cache
|
||||||
RUN apt-get update && apt-get install -y --no-install-recommends chromium \
|
RUN apt-get update \
|
||||||
&& rm -rf /var/lib/apt/lists/*
|
&& apt-get install -y --no-install-recommends chromium \
|
||||||
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true \
|
ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true \
|
||||||
PUPPETEER_EXECUTABLE_PATH=/usr/bin/chromium
|
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 ./
|
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 \
|
RUN yarn config set network-timeout 600000 \
|
||||||
&& yarn install --frozen-lockfile \
|
&& yarn install --frozen-lockfile \
|
||||||
&& yarn global add pm2
|
&& yarn global add pm2
|
||||||
|
|
||||||
# Copy app sources and build production assets
|
# Copy application source and build production assets
|
||||||
COPY . .
|
COPY . ./
|
||||||
RUN yarn run prod
|
RUN yarn run prod
|
||||||
|
|
||||||
# Stage 2: runtime
|
# Prepare runtime directories and symlinks for data and config
|
||||||
FROM node:22-slim AS runner
|
RUN mkdir -p /db /conf \
|
||||||
|
&& chown 1000:1000 /db /conf \
|
||||||
WORKDIR /fredy
|
&& chmod 777 /db /conf \
|
||||||
|
&& ln -s /db /fredy/db \
|
||||||
# Copy entire build directory from builder instead of individual folders
|
&& ln -s /conf /fredy/conf
|
||||||
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
|
|
||||||
|
|
||||||
EXPOSE 9998
|
EXPOSE 9998
|
||||||
|
|
||||||
# Run with pm2-runtime for proper process management
|
# Start application using PM2 runtime
|
||||||
CMD ["pm2-runtime", "index.js"]
|
CMD ["pm2-runtime", "index.js"]
|
||||||
|
|||||||
Reference in New Issue
Block a user