-
Notifications
You must be signed in to change notification settings - Fork 137
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' of https://github.com/janhq/cortex.cpp into feat/m…
…odel_estimation
- Loading branch information
Showing
90 changed files
with
2,109 additions
and
1,102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
# Stage 1: Base dependencies (common stage) | ||
FROM ubuntu:22.04 as common | ||
|
||
ENV DEBIAN_FRONTEND=noninteractive | ||
|
||
# Install common dependencies | ||
RUN apt-get update && apt-get install -y --no-install-recommends \ | ||
ca-certificates \ | ||
software-properties-common \ | ||
curl \ | ||
wget \ | ||
jq \ | ||
tar \ | ||
openmpi-bin \ | ||
libopenmpi-dev && \ | ||
apt-get clean && \ | ||
rm -rf /var/lib/apt/lists/* | ||
|
||
# Stage 2: Build dependencies and compilation | ||
FROM common as build | ||
|
||
# Install Dependencies | ||
RUN wget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc 2>/dev/null | gpg --dearmor - | tee /etc/apt/trusted.gpg.d/kitware.gpg >/dev/null && \ | ||
apt-add-repository "deb https://apt.kitware.com/ubuntu/ $(lsb_release -cs) main" && \ | ||
apt-get update && \ | ||
apt-get install -y --no-install-recommends \ | ||
cmake \ | ||
make \ | ||
git \ | ||
uuid-dev \ | ||
lsb-release \ | ||
gpg \ | ||
zip \ | ||
unzip \ | ||
gcc \ | ||
g++ \ | ||
ninja-build \ | ||
pkg-config \ | ||
python3-pip \ | ||
openssl && \ | ||
pip3 install awscli && \ | ||
apt-get clean && \ | ||
rm -rf /var/lib/apt/lists/* | ||
|
||
ARG CORTEX_CPP_VERSION=latest | ||
ARG CMAKE_EXTRA_FLAGS="" | ||
|
||
WORKDIR /app | ||
|
||
# Build arguments for remote cache | ||
ARG REMOTE_CACHE_URL="" | ||
ARG MINIO_ENDPOINT_URL="" | ||
ARG MINIO_ACCESS_KEY="" | ||
ARG MINIO_SECRET_KEY="" | ||
|
||
# Configure cache | ||
ENV LOCAL_CACHE_DIR="/vcpkg-cache" | ||
RUN mkdir -p ${LOCAL_CACHE_DIR} | ||
|
||
# Configure MinIO alias (if remote cache is provided) | ||
RUN if [ -n "${REMOTE_CACHE_URL}" ]; then \ | ||
echo "Setting up MinIO for remote cache..." && \ | ||
aws configure set default.s3.signature_version s3v4 && \ | ||
aws configure set aws_access_key_id ${MINIO_ACCESS_KEY} && \ | ||
aws configure set aws_secret_access_key ${MINIO_SECRET_KEY} && \ | ||
aws configure set default.region us-east-1; \ | ||
else \ | ||
echo "No remote cache provided, using local fallback..."; \ | ||
fi | ||
|
||
# Sync cache from MinIO (if remote cache is provided) | ||
RUN if [ -n "${REMOTE_CACHE_URL}" ]; then \ | ||
echo "Downloading cache from MinIO..." && \ | ||
aws --endpoint-url=${MINIO_ENDPOINT_URL} s3 sync s3://vcpkg-cache ${LOCAL_CACHE_DIR}; \ | ||
else \ | ||
echo "No remote cache provided, skipping download."; \ | ||
fi | ||
|
||
# Copy source code | ||
COPY ./engine /app/engine | ||
COPY ./docs/static/openapi/cortex.json /app/docs/static/openapi/cortex.json | ||
|
||
# Build project | ||
# Configure vcpkg binary sources | ||
RUN export VCPKG_BINARY_SOURCES="files,${LOCAL_CACHE_DIR},readwrite;default"; \ | ||
cd engine && make configure-vcpkg && make build CMAKE_EXTRA_FLAGS="-DCORTEX_CPP_VERSION=${CORTEX_CPP_VERSION} -DCMAKE_BUILD_TEST=OFF -DCMAKE_TOOLCHAIN_FILE=vcpkg/scripts/buildsystems/vcpkg.cmake ${CMAKE_EXTRA_FLAGS}" | ||
|
||
# Upload updated cache to MinIO (if remote cache is provided) | ||
RUN if [ -n "${REMOTE_CACHE_URL}" ]; then \ | ||
echo "Uploading cache to MinIO..." && \ | ||
aws --endpoint-url=${MINIO_ENDPOINT_URL} s3 sync ${LOCAL_CACHE_DIR} s3://vcpkg-cache; \ | ||
else \ | ||
echo "No remote cache provided, skipping upload."; \ | ||
fi | ||
|
||
# Stage 3: Runtime | ||
FROM common as runtime | ||
|
||
WORKDIR /app | ||
|
||
# Copy built binaries from the build stage | ||
COPY --from=build /app/engine/build/cortex /usr/local/bin/cortex | ||
COPY --from=build /app/engine/build/cortex-server /usr/local/bin/cortex-server | ||
|
||
COPY ./docker/download-cortex.llamacpp.sh /tmp/download-cortex.llamacpp.sh | ||
COPY ./docker/entrypoint.sh /usr/local/bin/entrypoint.sh | ||
|
||
# Get the latest version of Cortex Llama | ||
ARG CORTEX_LLAMACPP_VERSION=latest | ||
RUN chmod +x /tmp/download-cortex.llamacpp.sh && /bin/bash /tmp/download-cortex.llamacpp.sh ${CORTEX_LLAMACPP_VERSION} | ||
|
||
# Configure entrypoint | ||
RUN chmod +x /usr/local/bin/entrypoint.sh | ||
|
||
EXPOSE 39281 | ||
|
||
# Healthcheck | ||
HEALTHCHECK --interval=300s --timeout=30s --start-period=10s --retries=3 \ | ||
CMD curl -f http://127.0.0.1:39281/healthz || exit 1 | ||
|
||
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.