firecrawl / Dockerfile
vinzcyun's picture
Update Dockerfile
12014a6 verified
# ===== Build stage =====
FROM node:20-bullseye AS builder
# Cần git để clone
RUN apt-get update && apt-get install -y git && rm -rf /var/lib/apt/lists/*
# pnpm
RUN corepack enable && corepack prepare pnpm@9.0.0 --activate
WORKDIR /app
# Clone mã nguồn Firecrawl (pin theo default branch; có thể đổi sang tag/commit bằng ARG)
ARG FIRECRAWL_REPO=https://github.com/mendableai/firecrawl.git
RUN git clone --depth=1 ${FIRECRAWL_REPO} .
# Cài deps workspace và build 2 service
RUN pnpm install --frozen-lockfile
WORKDIR /app/apps/playwright-service
RUN pnpm build
WORKDIR /app/apps/api
RUN pnpm build
# ===== Runtime stage =====
FROM node:20-bullseye
# Chromium/Playwright deps (tối thiểu an toàn)
RUN apt-get update && apt-get install -y \
wget gnupg ca-certificates fonts-liberation libasound2 \
libatk1.0-0 libatk-bridge2.0-0 libatspi2.0-0 libcups2 libdbus-1-3 \
libdrm2 libgtk-3-0 libnspr4 libnss3 libxcomposite1 libxdamage1 \
libxfixes3 libxkbcommon0 libxrandr2 xdg-utils libpango-1.0-0 \
libxcursor1 libxi6 libxrender1 libxtst6 libjpeg62-turbo \
&& rm -rf /var/lib/apt/lists/*
ENV NODE_ENV=production
WORKDIR /app
# Copy toàn bộ repo đã build
COPY --from=builder /app /app
# Cài browser cho Playwright
RUN npx playwright install chromium && npx playwright install-deps
# Script chạy 2 tiến trình: playwright-service (3000) + api ($PORT)
RUN printf '#!/usr/bin/env bash\nset -e\n\
export PORT=${PORT:-7860}\n\
export HOST=${HOST:-0.0.0.0}\n\
# Bạn tự set các ENV khác trong Space Settings: USE_DB_AUTHENTICATION, REDIS_URL, v.v.\n\
export PLAYWRIGHT_MICROSERVICE_URL=${PLAYWRIGHT_MICROSERVICE_URL:-http://127.0.0.1:3000/html}\n\
node /app/apps/playwright-service/dist/index.js &\n\
node /app/apps/api/dist/main.js\n' > /app/run.sh && chmod +x /app/run.sh
EXPOSE 7860
CMD ["/app/run.sh"]