colpali-backend-api / Dockerfile
vk98's picture
Initial backend deployment - Hono proxy + ColPali embedding API
5dfbe50
raw
history blame
1.85 kB
FROM node:20-slim
# Install Python and system dependencies
RUN apt-get update && apt-get install -y \
python3.11 \
python3-pip \
python3.11-venv \
git \
build-essential \
&& rm -rf /var/lib/apt/lists/*
# Create a non-root user (required by HF Spaces)
RUN useradd -m -u 1000 user
USER user
ENV HOME=/home/user \
PATH=/home/user/.local/bin:$PATH
# Set working directory
WORKDIR $HOME/app
# Copy backend files only
COPY --chown=user embedding_api.py $HOME/app/
COPY --chown=user requirements_embedding.txt $HOME/app/
COPY --chown=user hono-proxy $HOME/app/hono-proxy
# Create Python virtual environment
RUN python3.11 -m venv $HOME/venv
ENV PATH="$HOME/venv/bin:$PATH"
# Install Python dependencies for embedding API
RUN pip install --upgrade pip
RUN pip install -r requirements_embedding.txt
# Install pnpm and Node dependencies for Hono proxy
RUN npm install -g pnpm
WORKDIR $HOME/app/hono-proxy
RUN pnpm install
# Copy Vespa certificates (these need to be included in the repo)
RUN mkdir -p $HOME/.vespa/il-infra.colpali-server.default
COPY --chown=user vespa-certs/* $HOME/.vespa/il-infra.colpali-server.default/ || true
# Create startup script for backend services only
WORKDIR $HOME/app
RUN cat > start-backend.sh << 'EOF'
#!/bin/bash
# Start embedding API on port 8001
echo "Starting ColPali embedding API on port 8001..."
python embedding_api.py &
EMBED_PID=$!
# Wait for embedding API to be ready
sleep 10
# Start Hono proxy on HF Spaces port 7860
echo "Starting Hono proxy on port 7860..."
cd hono-proxy && PORT=7860 CORS_ORIGIN="*" EMBEDDING_API_URL="http://localhost:8001" npx tsx src/index.ts
# If Hono exits, kill embedding service
kill $EMBED_PID
EOF
RUN chmod +x start-backend.sh
# Expose HF Spaces port (Hono proxy will run on this)
EXPOSE 7860
# Run the startup script
CMD ["./start-backend.sh"]