2024-09-29 10:52:11 +00:00
|
|
|
# syntax=docker/dockerfile:1
|
2024-11-24 05:13:51 +00:00
|
|
|
FROM ubuntu:jammy AS base
|
2024-09-29 10:52:11 +00:00
|
|
|
LABEL homepage="https://khoj.dev"
|
|
|
|
LABEL repository="https://github.com/khoj-ai/khoj"
|
2024-07-19 11:40:08 +00:00
|
|
|
LABEL org.opencontainers.image.source="https://github.com/khoj-ai/khoj"
|
2024-09-29 10:52:11 +00:00
|
|
|
LABEL org.opencontainers.image.description="Your second brain, containerized for multi-user, cloud deployment"
|
2023-10-26 20:15:31 +00:00
|
|
|
|
|
|
|
# Install System Dependencies
|
2024-09-29 10:52:11 +00:00
|
|
|
RUN apt update -y && apt -y install \
|
|
|
|
python3-pip \
|
|
|
|
libsqlite3-0 \
|
|
|
|
ffmpeg \
|
|
|
|
libsm6 \
|
|
|
|
libxext6 \
|
|
|
|
swig \
|
2024-11-24 05:05:30 +00:00
|
|
|
curl \
|
2024-11-24 04:47:41 +00:00
|
|
|
# Required by llama-cpp-python pre-built wheels. See #1628
|
2024-11-24 05:05:30 +00:00
|
|
|
musl-dev && \
|
2024-11-24 05:13:51 +00:00
|
|
|
ln -s /usr/lib/x86_64-linux-musl/libc.so /lib/libc.musl-x86_64.so.1 && \
|
|
|
|
# Clean up
|
|
|
|
apt clean && rm -rf /var/lib/apt/lists/*
|
2023-10-26 20:15:31 +00:00
|
|
|
|
2024-11-24 05:13:51 +00:00
|
|
|
# Build Server
|
|
|
|
FROM base AS server-deps
|
2024-09-29 10:52:11 +00:00
|
|
|
WORKDIR /app
|
2023-10-26 20:15:31 +00:00
|
|
|
COPY pyproject.toml .
|
|
|
|
COPY README.md .
|
2023-12-21 11:37:08 +00:00
|
|
|
ARG VERSION=0.0.0
|
2024-11-24 06:24:45 +00:00
|
|
|
# use the pre-built llama-cpp-python, torch cpu wheel
|
|
|
|
ENV PIP_EXTRA_INDEX_URL="https://download.pytorch.org/whl/cpu https://abetlen.github.io/llama-cpp-python/whl/cpu"
|
|
|
|
# avoid downloading unused cuda specific python packages
|
|
|
|
ENV CUDA_VISIBLE_DEVICES=""
|
2023-12-21 11:37:08 +00:00
|
|
|
RUN sed -i "s/dynamic = \\[\"version\"\\]/version = \"$VERSION\"/" pyproject.toml && \
|
2024-11-24 05:13:51 +00:00
|
|
|
pip install --no-cache-dir .[prod]
|
2023-10-26 20:15:31 +00:00
|
|
|
|
2024-11-24 05:13:51 +00:00
|
|
|
# Build Web App
|
|
|
|
FROM node:20-alpine AS web-app
|
2024-11-24 20:59:17 +00:00
|
|
|
# Set build optimization env vars
|
|
|
|
ENV NODE_ENV=production
|
|
|
|
ENV NEXT_TELEMETRY_DISABLED=1
|
2024-06-22 14:42:41 +00:00
|
|
|
WORKDIR /app/src/interface/web
|
2024-11-24 21:10:17 +00:00
|
|
|
# Install dependencies first (cache layer)
|
|
|
|
COPY src/interface/web/package.json src/interface/web/yarn.lock ./
|
|
|
|
RUN yarn install --frozen-lockfile
|
|
|
|
# Copy source and build
|
|
|
|
COPY src/interface/web/. ./
|
|
|
|
RUN yarn build
|
2024-11-24 05:13:51 +00:00
|
|
|
|
|
|
|
# Merge the Server and Web App into a Single Image
|
|
|
|
FROM base
|
|
|
|
ENV PYTHONPATH=/app/src
|
2024-06-22 14:42:41 +00:00
|
|
|
WORKDIR /app
|
2024-11-24 05:13:51 +00:00
|
|
|
COPY --from=server-deps /usr/local/lib/python3.10/dist-packages /usr/local/lib/python3.10/dist-packages
|
|
|
|
COPY --from=web-app /app/src/interface/web/out ./src/khoj/interface/built
|
|
|
|
COPY . .
|
|
|
|
RUN cd src && python3 khoj/manage.py collectstatic --noinput
|
2024-06-22 14:42:41 +00:00
|
|
|
|
2023-10-26 20:15:31 +00:00
|
|
|
# Run the Application
|
|
|
|
# There are more arguments required for the application to run,
|
2024-11-24 05:13:51 +00:00
|
|
|
# but those should be passed in through the docker-compose.yml file.
|
2023-10-26 20:15:31 +00:00
|
|
|
ARG PORT
|
|
|
|
EXPOSE ${PORT}
|
2024-09-29 10:52:11 +00:00
|
|
|
ENTRYPOINT ["gunicorn", "-c", "gunicorn-config.py", "src.khoj.main:app"]
|