File size: 2,062 Bytes
75ec748 83b59f1 75ec748 b04a7d3 161b63e 75ec748 1dc0b58 75ec748 1dc0b58 75ec748 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# Build frontend
FROM node:18 as frontend-build
WORKDIR /app/frontend
COPY frontend/package*.json ./
RUN npm install
COPY frontend/ ./
RUN npm run build
# Build backend
FROM python:3.12-slim as backend
WORKDIR /app
# Install dependencies including nginx
RUN apt-get update && apt-get install -y nginx \
&& rm -rf /var/lib/apt/lists/*
COPY src/docker_requirements.txt /app/src/
RUN pip install --upgrade pip wheel
RUN pip install --cache-dir=~/.cache/pip --prefer-binary pyarrow pandas numpy scipy fsspec aiohttp tqdm --progress-bar off -v
RUN pip install --cache-dir=~/.cache/pip -r /app/src/docker_requirements.txt -v --prefer-binary && rm -rf ~/.cache/pip
COPY src/ /app/src/
# Copy Nginx config (adjust path if needed)
COPY nginx.conf /etc/nginx/nginx.conf
COPY --from=frontend-build /app/frontend /app/frontend
# Create non-root user
RUN useradd -m -u 1000 user
# Create and configure cache directory
RUN mkdir -p /app/.cache && \
chown -R user:user /app
# Environment variables
ENV HF_HOME=/app/.cache \
HF_DATASETS_CACHE=/app/.cache \
INTERNAL_API_PORT=7861 \
PORT=7860
WORKDIR /app
COPY nginx.conf /etc/nginx/nginx.conf
COPY start.sh /start.sh
RUN chmod +x /start.sh
RUN chown -R user:user /var/lib/nginx
RUN apt-get update && apt-get install -y nginx \
&& groupadd -r nginx && useradd -r -g nginx nginx
#Give user nginx write permissions
RUN mkdir -p /var/lib/nginx && chown -R user:user /var/lib/nginx
RUN mkdir -p /var/log/nginx && chown -R user:user /var/log/nginx
RUN mkdir -p /app/logs && chown -R user:user /app/logs
RUN mkdir -p /run && touch /run/nginx.pid && chown -R user:user /run
RUN apt-get update && apt-get install -y \
curl \
netcat-openbsd \
&& curl -fsSL https://deb.nodesource.com/setup_18.x | bash - \
&& apt-get install -y nodejs \
&& rm -rf /var/lib/apt/lists/*
# Note: HF_TOKEN should be provided at runtime, not build time
USER user
EXPOSE 7860
# Start both servers with wait-for
CMD ["sh", "/start.sh"] |