forked from janhq/cortex.cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile.cache
More file actions
121 lines (99 loc) · 3.74 KB
/
Copy pathDockerfile.cache
File metadata and controls
121 lines (99 loc) · 3.74 KB
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
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"]