improve docker build

This commit is contained in:
Christian Kellner
2025-05-26 12:07:22 +02:00
parent 918c6ade36
commit 78a122b3ea
2 changed files with 39 additions and 15 deletions

View File

@@ -18,6 +18,10 @@ jobs:
contents: read
packages: write
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
steps:
- name: Checkout repository
uses: actions/checkout@v3
@@ -51,3 +55,5 @@ jobs:
platforms: linux/amd64,linux/arm64
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max

View File

@@ -1,28 +1,46 @@
FROM node:22
# Stage 1: build
FROM node:22-slim AS builder
WORKDIR /fredy
COPY . /fredy
RUN apt-get update && apt-get install -y chromium
# 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/*
ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true \
PUPPETEER_EXECUTABLE_PATH=/usr/bin/chromium
PUPPETEER_EXECUTABLE_PATH=/usr/bin/chromium
# Timeout fix für yarn hinzugefügt
RUN yarn config set network-timeout 600000
# Copy manifest for better cache usage
COPY package.json yarn.lock ./
RUN yarn install
RUN yarn global add pm2
# Increase yarn timeout, install deps and pm2 globally
RUN yarn config set network-timeout 600000 \
&& yarn install --frozen-lockfile \
&& yarn global add pm2
# Copy app sources and build production assets
COPY . .
RUN yarn run prod
RUN mkdir /db /conf && \
chown 1000:1000 /db /conf && \
chmod 777 -R /db/ && \
ln -s /db /fredy/db && ln -s /conf /fredy/conf
# 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
EXPOSE 9998
CMD pm2-runtime index.js
# Run with pm2-runtime for proper process management
CMD ["pm2-runtime", "index.js"]