# Single-stage build with Node.js 24 FROM node:24-slim WORKDIR /app # Install system dependencies required for Playwright/Camoufox browser, VNC, and git RUN apt-get update && apt-get install -y --no-install-recommends \ ca-certificates \ curl \ unzip \ git \ libasound2 \ libatk-bridge2.0-0 \ libatk1.0-0 \ libatspi2.0-0 \ libcups2 \ libdbus-1-3 \ libdrm2 \ libgbm1 \ libgtk-3-0 \ libnspr4 \ libnss3 \ && rm -rf /var/lib/apt/lists/* \ && apt-get clean # Clone the repository directly (replace with your actual repo URL) RUN git clone --depth 1 https://github.com/iBUHub/AIStudioToAPI.git /tmp/repo \ && cp -r /tmp/repo/* /tmp/repo/.[!.]* /app/ 2>/dev/null || true \ && rm -rf /tmp/repo # Copy package manifests and install all dependencies COPY package*.json ./ RUN npm install --no-audit --no-fund --ignore-scripts \ && npm cache clean --force # Download and extract Camoufox browser binary ARG CAMOUFOX_URL RUN ARCH=$(uname -m) && \ if [ -z "$CAMOUFOX_URL" ]; then \ if [ "$ARCH" = "x86_64" ]; then \ CAMOUFOX_URL="https://github.com/daijro/camoufox/releases/download/v135.0.1-beta.24/camoufox-135.0.1-beta.24-lin.x86_64.zip"; \ elif [ "$ARCH" = "aarch64" ]; then \ CAMOUFOX_URL="https://github.com/daijro/camoufox/releases/download/v135.0.1-beta.24/camoufox-135.0.1-beta.24-lin.arm64.zip"; \ else \ echo "Unsupported architecture: $ARCH" && exit 1; \ fi; \ fi && \ mkdir -p camoufox-linux && \ curl -sSL ${CAMOUFOX_URL} -o camoufox.zip && \ unzip -q camoufox.zip -d /tmp/cf || true && \ if [ -f /tmp/cf/camoufox ]; then \ mv /tmp/cf/* camoufox-linux/; \ else \ mv /tmp/cf/*/* camoufox-linux/; \ fi && \ rm -rf /tmp/cf camoufox.zip && \ chmod +x /app/camoufox-linux/camoufox # Build frontend assets with Vite ARG VERSION RUN VERSION=${VERSION} npm run build:ui || true # Remove dev dependencies after build to reduce image size RUN npm prune --omit=dev && npm cache clean --force USER root EXPOSE 7860 ENV NODE_ENV=production \ CAMOUFOX_EXECUTABLE_PATH=/app/camoufox-linux/camoufox HEALTHCHECK --interval=60s --timeout=30s --start-period=120s --retries=5 \ CMD node -e "const http = require('http'); const req = http.get('http://localhost:7860/', (res) => { process.exit(res.statusCode === 200 || res.statusCode === 404 ? 0 : 1); }); req.on('error', () => process.exit(1)); req.setTimeout(10000, () => { req.destroy(); process.exit(1); });" CMD ["node", "main.js"]