diff --git a/.dockerignore b/.dockerignore index b7c8add..0dacae7 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,7 +1,6 @@ node_modules/ npm-debug.log test/ -conf/ db/ .git/ .github/ diff --git a/Dockerfile b/Dockerfile index ccc96f1..aebacc0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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"] \ No newline at end of file +# Start application using PM2 runtime +CMD ["pm2-runtime", "index.js"]