playwright-ddg / Dockerfile
deepak191z's picture
Update Dockerfile
aa919fe verified
FROM node:20-alpine
# 设置工作目录
WORKDIR /app
# 安装系统依赖 (Playwright ke liye zaroori)
RUN apk add --no-cache \
# 基本构建工具
python3 \
make \
g++ \
# Playwright 依赖
chromium \
nss \
freetype \
freetype-dev \
harfbuzz \
ca-certificates \
ttf-freefont \
gcompat
# 复制 package.json 和 tsconfig.json
COPY package*.json tsconfig.json ./
# 安装 Node.js 依赖
RUN npm install
# Install Playwright without dependencies (since we installed them via apk)
RUN npm install playwright && \
npx playwright install chromium
# 设置 Playwright 的环境变量
ENV PLAYWRIGHT_BROWSERS_PATH=/root/.cache/playwright
ENV PLAYWRIGHT_CHROMIUM_EXECUTABLE_PATH=/root/.cache/playwright/chromium-*/chrome-linux/chrome
ENV PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=0
ENV PLAYWRIGHT_SKIP_BROWSER_VALIDATION=0
# 创建非 root 用户和用户组
RUN addgroup -S -g 1001 nodejs && \
adduser -S -D -H -u 1001 -G nodejs hono
# Create Playwright cache directory and set permissions
RUN mkdir -p /root/.cache/playwright && \
chown -R hono:nodejs /app && \
chown -R hono:nodejs /root/.cache/playwright
# 复制源代码和静态文件
COPY src/ ./src/
COPY public/ ./public/
# Compile TypeScript to JavaScript
#RUN npm run build
# 切换到非 root 用户
USER hono
# 声明容器要暴露的端口
EXPOSE 7860
ENV PORT=7860
# 启动应用
CMD ["ts-node", "src/index.ts"]