Skip to content
This repository was archived by the owner on Jul 4, 2025. It is now read-only.

Commit 9f105ae

Browse files
committed
chore: Dockerfile with vcpkg cache
1 parent 31da684 commit 9f105ae

File tree

3 files changed

+146
-20
lines changed

3 files changed

+146
-20
lines changed

.github/workflows/cortex-cpp-quality-gate.yml

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,13 @@ jobs:
198198

199199
- name: Run Docker
200200
run: |
201-
sudo docker build -t menloltd/cortex:test -f docker/Dockerfile .
202-
sudo docker run -it -d -p 3928:39281 --name cortex menloltd/cortex:test
201+
docker build \
202+
--build-arg REMOTE_CACHE_URL="${{ secrets.MINIO_ENDPOINT }}/vcpkg-cache" \
203+
--build-arg MINIO_ENDPOINT_URL="${{ secrets.MINIO_ENDPOINT }}" \
204+
--build-arg MINIO_ACCESS_KEY="${{ secrets.MINIO_ACCESS_KEY_ID }}" \
205+
--build-arg MINIO_SECRET_KEY="${{ secrets.MINIO_SECRET_ACCESS_KEY }}" \
206+
-t menloltd/cortex:test -f docker/Dockerfile.cache .
207+
docker run -it -d -p 3928:39281 --name cortex menloltd/cortex:test
203208
204209
- name: use python
205210
uses: actions/setup-python@v5
@@ -217,6 +222,6 @@ jobs:
217222
continue-on-error: true
218223
if: always()
219224
run: |
220-
sudo docker stop cortex
221-
sudo docker rm cortex
222-
echo "y\n" | sudo docker system prune -af
225+
docker stop cortex
226+
docker rm cortex
227+
echo "y\n" | docker system prune -af

docker/Dockerfile.cache

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
# Stage 1: Base dependencies (common stage)
2+
FROM ubuntu:22.04 as common
3+
4+
ENV DEBIAN_FRONTEND=noninteractive
5+
6+
# Install common dependencies
7+
RUN apt-get update && apt-get install -y --no-install-recommends \
8+
ca-certificates \
9+
software-properties-common \
10+
curl \
11+
wget \
12+
jq \
13+
tar \
14+
openmpi-bin \
15+
libopenmpi-dev && \
16+
apt-get clean && \
17+
rm -rf /var/lib/apt/lists/*
18+
19+
# Stage 2: Build dependencies and compilation
20+
FROM common as build
21+
22+
# Install Dependencies
23+
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 && \
24+
apt-add-repository "deb https://apt.kitware.com/ubuntu/ $(lsb_release -cs) main" && \
25+
apt-get update && \
26+
apt-get install -y --no-install-recommends \
27+
cmake \
28+
make \
29+
git \
30+
uuid-dev \
31+
lsb-release \
32+
gpg \
33+
zip \
34+
unzip \
35+
gcc \
36+
g++ \
37+
ninja-build \
38+
pkg-config \
39+
python3-pip \
40+
openssl && \
41+
pip3 install awscli && \
42+
apt-get clean && \
43+
rm -rf /var/lib/apt/lists/*
44+
45+
ARG CORTEX_CPP_VERSION=latest
46+
ARG CMAKE_EXTRA_FLAGS=""
47+
48+
WORKDIR /app
49+
50+
# Build arguments for remote cache
51+
ARG REMOTE_CACHE_URL=""
52+
ARG MINIO_ENDPOINT_URL=""
53+
ARG MINIO_ACCESS_KEY=""
54+
ARG MINIO_SECRET_KEY=""
55+
56+
# Configure cache
57+
ENV LOCAL_CACHE_DIR="/vcpkg-cache"
58+
RUN mkdir -p ${LOCAL_CACHE_DIR}
59+
60+
# Configure MinIO alias (if remote cache is provided)
61+
RUN if [ -n "${REMOTE_CACHE_URL}" ]; then \
62+
echo "Setting up MinIO for remote cache..." && \
63+
aws configure set default.s3.signature_version s3v4 && \
64+
aws configure set aws_access_key_id ${MINIO_ACCESS_KEY} && \
65+
aws configure set aws_secret_access_key ${MINIO_SECRET_KEY} && \
66+
aws configure set default.region us-east-1; \
67+
else \
68+
echo "No remote cache provided, using local fallback..."; \
69+
fi
70+
71+
# Sync cache from MinIO (if remote cache is provided)
72+
RUN if [ -n "${REMOTE_CACHE_URL}" ]; then \
73+
echo "Downloading cache from MinIO..." && \
74+
aws --endpoint-url=${MINIO_ENDPOINT_URL} s3 sync s3://vcpkg-cache ${LOCAL_CACHE_DIR}; \
75+
else \
76+
echo "No remote cache provided, skipping download."; \
77+
fi
78+
79+
# Copy source code
80+
COPY ./engine /app/engine
81+
COPY ./docs/static/openapi/cortex.json /app/docs/static/openapi/cortex.json
82+
83+
# Build project
84+
# Configure vcpkg binary sources
85+
RUN export VCPKG_BINARY_SOURCES="files,${LOCAL_CACHE_DIR},readwrite;default"; \
86+
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}"
87+
88+
# Upload updated cache to MinIO (if remote cache is provided)
89+
RUN if [ -n "${REMOTE_CACHE_URL}" ]; then \
90+
echo "Uploading cache to MinIO..." && \
91+
aws --endpoint-url=${MINIO_ENDPOINT_URL} s3 sync ${LOCAL_CACHE_DIR} s3://vcpkg-cache; \
92+
else \
93+
echo "No remote cache provided, skipping upload."; \
94+
fi
95+
96+
# Stage 3: Runtime
97+
FROM common as runtime
98+
99+
WORKDIR /app
100+
101+
# Copy built binaries from the build stage
102+
COPY --from=build /app/engine/build/cortex /usr/local/bin/cortex
103+
COPY --from=build /app/engine/build/cortex-server /usr/local/bin/cortex-server
104+
105+
COPY ./docker/download-cortex.llamacpp.sh /tmp/download-cortex.llamacpp.sh
106+
COPY ./docker/entrypoint.sh /usr/local/bin/entrypoint.sh
107+
108+
# Get the latest version of Cortex Llama
109+
ARG CORTEX_LLAMACPP_VERSION=latest
110+
RUN chmod +x /tmp/download-cortex.llamacpp.sh && /bin/bash /tmp/download-cortex.llamacpp.sh ${CORTEX_LLAMACPP_VERSION}
111+
112+
# Configure entrypoint
113+
RUN chmod +x /usr/local/bin/entrypoint.sh
114+
115+
EXPOSE 39281
116+
117+
# Healthcheck
118+
HEALTHCHECK --interval=300s --timeout=30s --start-period=10s --retries=3 \
119+
CMD curl -f http://127.0.0.1:39281/healthz || exit 1
120+
121+
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]

docker/download-cortex.llamacpp.sh

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,18 @@ cd /opt/cortex.llamacpp
1313

1414
# Download the cortex.llamacpp engines
1515
echo -e "Downloading Cortex Llama version $VERSION"
16-
wget https://github.com/janhq/cortex.llamacpp/releases/download/v$VERSION/cortex.llamacpp-$VERSION-linux-amd64-avx-cuda-11-7.tar.gz
17-
wget https://github.com/janhq/cortex.llamacpp/releases/download/v$VERSION/cortex.llamacpp-$VERSION-linux-amd64-avx-cuda-12-0.tar.gz
18-
wget https://github.com/janhq/cortex.llamacpp/releases/download/v$VERSION/cortex.llamacpp-$VERSION-linux-amd64-avx.tar.gz
19-
wget https://github.com/janhq/cortex.llamacpp/releases/download/v$VERSION/cortex.llamacpp-$VERSION-linux-amd64-avx2-cuda-11-7.tar.gz
20-
wget https://github.com/janhq/cortex.llamacpp/releases/download/v$VERSION/cortex.llamacpp-$VERSION-linux-amd64-avx2-cuda-12-0.tar.gz
21-
wget https://github.com/janhq/cortex.llamacpp/releases/download/v$VERSION/cortex.llamacpp-$VERSION-linux-amd64-avx2.tar.gz
22-
wget https://github.com/janhq/cortex.llamacpp/releases/download/v$VERSION/cortex.llamacpp-$VERSION-linux-amd64-avx512-cuda-11-7.tar.gz
23-
wget https://github.com/janhq/cortex.llamacpp/releases/download/v$VERSION/cortex.llamacpp-$VERSION-linux-amd64-avx512-cuda-12-0.tar.gz
24-
wget https://github.com/janhq/cortex.llamacpp/releases/download/v$VERSION/cortex.llamacpp-$VERSION-linux-amd64-avx512.tar.gz
25-
wget https://github.com/janhq/cortex.llamacpp/releases/download/v$VERSION/cortex.llamacpp-$VERSION-linux-amd64-noavx-cuda-11-7.tar.gz
26-
wget https://github.com/janhq/cortex.llamacpp/releases/download/v$VERSION/cortex.llamacpp-$VERSION-linux-amd64-noavx-cuda-12-0.tar.gz
27-
wget https://github.com/janhq/cortex.llamacpp/releases/download/v$VERSION/cortex.llamacpp-$VERSION-linux-amd64-noavx.tar.gz
28-
wget https://github.com/janhq/cortex.llamacpp/releases/download/v$VERSION/cortex.llamacpp-$VERSION-linux-amd64-vulkan.tar.gz
29-
wget https://github.com/janhq/cortex.llamacpp/releases/download/v$VERSION/cuda-11-7-linux-amd64.tar.gz
30-
wget https://github.com/janhq/cortex.llamacpp/releases/download/v$VERSION/cuda-12-0-linux-amd64.tar.gz
16+
wget https://github.com/janhq/cortex.llamacpp/releases/download/v$VERSION/cortex.llamacpp-$VERSION-linux-amd64-avx-cuda-11-7.tar.gz > /dev/null
17+
wget https://github.com/janhq/cortex.llamacpp/releases/download/v$VERSION/cortex.llamacpp-$VERSION-linux-amd64-avx-cuda-12-0.tar.gz > /dev/null
18+
wget https://github.com/janhq/cortex.llamacpp/releases/download/v$VERSION/cortex.llamacpp-$VERSION-linux-amd64-avx.tar.gz > /dev/null
19+
wget https://github.com/janhq/cortex.llamacpp/releases/download/v$VERSION/cortex.llamacpp-$VERSION-linux-amd64-avx2-cuda-11-7.tar.gz > /dev/null
20+
wget https://github.com/janhq/cortex.llamacpp/releases/download/v$VERSION/cortex.llamacpp-$VERSION-linux-amd64-avx2-cuda-12-0.tar.gz > /dev/null
21+
wget https://github.com/janhq/cortex.llamacpp/releases/download/v$VERSION/cortex.llamacpp-$VERSION-linux-amd64-avx2.tar.gz > /dev/null
22+
wget https://github.com/janhq/cortex.llamacpp/releases/download/v$VERSION/cortex.llamacpp-$VERSION-linux-amd64-avx512-cuda-11-7.tar.gz > /dev/null
23+
wget https://github.com/janhq/cortex.llamacpp/releases/download/v$VERSION/cortex.llamacpp-$VERSION-linux-amd64-avx512-cuda-12-0.tar.gz > /dev/null
24+
wget https://github.com/janhq/cortex.llamacpp/releases/download/v$VERSION/cortex.llamacpp-$VERSION-linux-amd64-avx512.tar.gz > /dev/null
25+
wget https://github.com/janhq/cortex.llamacpp/releases/download/v$VERSION/cortex.llamacpp-$VERSION-linux-amd64-noavx-cuda-11-7.tar.gz > /dev/null
26+
wget https://github.com/janhq/cortex.llamacpp/releases/download/v$VERSION/cortex.llamacpp-$VERSION-linux-amd64-noavx-cuda-12-0.tar.gz > /dev/null
27+
wget https://github.com/janhq/cortex.llamacpp/releases/download/v$VERSION/cortex.llamacpp-$VERSION-linux-amd64-noavx.tar.gz > /dev/null
28+
wget https://github.com/janhq/cortex.llamacpp/releases/download/v$VERSION/cortex.llamacpp-$VERSION-linux-amd64-vulkan.tar.gz > /dev/null
29+
wget https://github.com/janhq/cortex.llamacpp/releases/download/v$VERSION/cuda-11-7-linux-amd64.tar.gz > /dev/null
30+
wget https://github.com/janhq/cortex.llamacpp/releases/download/v$VERSION/cuda-12-0-linux-amd64.tar.gz > /dev/null

0 commit comments

Comments
 (0)