fixing some docker issues

This commit is contained in:
orangecoding
2026-03-22 09:41:20 +01:00
parent 8501fc7266
commit a1289acf15
4 changed files with 36 additions and 26 deletions

View File

@@ -1,50 +1,46 @@
FROM node:22-slim FROM node:22-slim
ARG TARGETARCH
# System deps for Chrome for Testing + build tools for native modules (better-sqlite3) # System deps for Chrome for Testing + build tools for native modules (better-sqlite3)
# Must run as root # On ARM64 we also install system Chromium (Chrome for Testing has no ARM64 binary)
RUN apt-get update && apt-get install -y --no-install-recommends \ RUN apt-get update && apt-get install -y --no-install-recommends \
curl ca-certificates fonts-liberation libasound2 \ curl ca-certificates fonts-liberation libasound2 \
libatk-bridge2.0-0 libatk1.0-0 libcups2 libdbus-1-3 \ libatk-bridge2.0-0 libatk1.0-0 libcups2 libdbus-1-3 \
libdrm2 libgbm1 libgtk-3-0 libnspr4 libnss3 \ libdrm2 libgbm1 libgtk-3-0 libnspr4 libnss3 \
libx11-xcb1 libxcomposite1 libxdamage1 libxrandr2 xdg-utils \ libx11-xcb1 libxcomposite1 libxdamage1 libxrandr2 xdg-utils \
python3 make g++ \ python3 make g++ \
&& if [ "$TARGETARCH" = "arm64" ]; then apt-get install -y --no-install-recommends chromium; fi \
&& rm -rf /var/lib/apt/lists/* \ && rm -rf /var/lib/apt/lists/* \
&& mkdir -p /db /conf /fredy \ && mkdir -p /db /conf /fredy
&& chown node:node /db /conf /fredy
WORKDIR /fredy WORKDIR /fredy
# Everything from here runs as the built-in non-root node user (UID 1000)
USER node
ENV NODE_ENV=production \ ENV NODE_ENV=production \
IS_DOCKER=true IS_DOCKER=true
COPY --chown=node:node package.json yarn.lock ./ COPY package.json yarn.lock ./
# Install dependencies and purge build tools (only needed to compile better-sqlite3) # Install dependencies and purge build tools (only needed to compile better-sqlite3)
RUN yarn config set network-timeout 600000 \ RUN yarn config set network-timeout 600000 \
&& yarn --frozen-lockfile \ && yarn --frozen-lockfile \
&& yarn cache clean && yarn cache clean
# Install Chrome for Testing in a separate layer — it's ~150MB and rarely changes, # on arm64 use the system Chromium installed above
# so keeping it separate avoids re-downloading on every code/dependency change RUN if [ "$TARGETARCH" != "arm64" ]; then npx puppeteer browsers install chrome; fi
RUN npx puppeteer browsers install chrome
# Purge build tools now that native modules are compiled # Purge build tools now that native modules are compiled
USER root
RUN apt-get purge -y python3 make g++ \ RUN apt-get purge -y python3 make g++ \
&& apt-get autoremove -y \ && apt-get autoremove -y \
&& rm -rf /var/lib/apt/lists/* && rm -rf /var/lib/apt/lists/*
USER node
COPY --chown=node:node index.html vite.config.js ./ COPY index.html vite.config.js ./
COPY --chown=node:node ui ./ui COPY ui ./ui
COPY --chown=node:node lib ./lib COPY lib ./lib
RUN yarn build:frontend RUN yarn build:frontend
COPY --chown=node:node index.js ./ COPY index.js ./
RUN ln -s /db /fredy/db \ RUN ln -s /db /fredy/db \
&& ln -s /conf /fredy/conf && ln -s /conf /fredy/conf

View File

@@ -42,19 +42,28 @@ for i in $(seq 1 30); do
sleep 2 sleep 2
done done
# Verify the process is NOT running as root # Verify the DB is readable/writable via the API.
RUNNING_USER=$(docker exec fredy id -u) # /api/demo is unauthenticated and reads the settings table — if SQLite is broken this returns an error.
if [ "$RUNNING_USER" = "0" ]; then echo "Testing DB via API (/api/demo)..."
echo "Process is running as root!" DEMO_RESPONSE=$(docker exec fredy curl -sf http://localhost:9998/api/demo 2>&1)
if echo "$DEMO_RESPONSE" | grep -q "demoMode"; then
echo "DB is readable (got demoMode from /api/demo)"
else
echo "DB check failed — unexpected response from /api/demo: $DEMO_RESPONSE"
docker logs fredy
exit 1 exit 1
fi fi
echo "Process runs as UID $RUNNING_USER (not root)"
# Verify Chrome launches without crashing # Verify Chrome launches without crashing.
# On amd64: Chrome for Testing lives in the puppeteer cache.
# On arm64: system Chromium is used instead.
echo "Testing Chrome..." echo "Testing Chrome..."
CHROME=$(docker exec fredy find /home/node/.cache/puppeteer -name chrome -type f 2>/dev/null | head -1) CHROME=$(docker exec fredy find /root/.cache/puppeteer /home -name chrome -type f 2>/dev/null | head -1)
if [ -z "$CHROME" ]; then if [ -z "$CHROME" ]; then
echo "Chrome binary not found" CHROME=$(docker exec fredy which chromium 2>/dev/null || true)
fi
if [ -z "$CHROME" ]; then
echo "Chrome/Chromium binary not found"
exit 1 exit 1
fi fi
if docker exec fredy "$CHROME" --headless --no-sandbox --disable-gpu --dump-dom https://example.com 2>&1 | grep -q "<html"; then if docker exec fredy "$CHROME" --headless --no-sandbox --disable-gpu --dump-dom https://example.com 2>&1 | grep -q "<html"; then

View File

@@ -47,12 +47,17 @@ export async function launchBrowser(url, options) {
removeUserDataDir = true; removeUserDataDir = true;
} }
// On ARM64 Docker, Chrome for Testing has no native binary — use system Chromium instead.
const executablePath =
options?.executablePath ||
(process.arch === 'arm64' && process.env.IS_DOCKER === 'true' ? '/usr/bin/chromium' : undefined);
const browser = await puppeteer.launch({ const browser = await puppeteer.launch({
headless: options?.puppeteerHeadless ?? true, headless: options?.puppeteerHeadless ?? true,
args: launchArgs, args: launchArgs,
timeout: options?.puppeteerTimeout || 45_000, timeout: options?.puppeteerTimeout || 45_000,
userDataDir, userDataDir,
executablePath: options?.executablePath, executablePath,
}); });
browser.__fredy_userDataDir = userDataDir; browser.__fredy_userDataDir = userDataDir;

View File

@@ -1,6 +1,6 @@
{ {
"name": "fredy", "name": "fredy",
"version": "20.0.7", "version": "20.0.8",
"description": "[F]ind [R]eal [E]states [d]amn eas[y].", "description": "[F]ind [R]eal [E]states [d]amn eas[y].",
"scripts": { "scripts": {
"prepare": "husky", "prepare": "husky",