Skip to content
This repository was archived by the owner on Jul 4, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 38 additions & 36 deletions .github/workflows/cortex-cpp-quality-gate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -188,40 +188,42 @@ jobs:
AWS_SECRET_ACCESS_KEY: "${{ secrets.MINIO_SECRET_ACCESS_KEY }}"
AWS_DEFAULT_REGION: "${{ secrets.MINIO_REGION }}"

# build-docker-and-test:
# runs-on: ubuntu-latest
# steps:
# - name: Getting the repo
# uses: actions/checkout@v3
# with:
# submodules: 'recursive'

# - name: Set up QEMU
# uses: docker/setup-qemu-action@v3

# - name: Set up Docker Buildx
# uses: docker/setup-buildx-action@v3
build-docker-and-test:
runs-on: ubuntu-24-04-docker
steps:
- name: Getting the repo
uses: actions/checkout@v3
with:
submodules: 'recursive'

# - name: Run Docker
# run: |
# docker build -t menloltd/cortex:test -f docker/Dockerfile .
# docker run -it -d -p 3928:39281 --name cortex menloltd/cortex:test

# - name: use python
# uses: actions/setup-python@v5
# with:
# python-version: "3.10"

# - name: Run e2e tests
# run: |
# cd engine
# python -m pip install --upgrade pip
# python -m pip install -r e2e-test/requirements.txt
# pytest e2e-test/test_api_docker.py

# - name: Run Docker
# continue-on-error: true
# if: always()
# run: |
# docker stop cortex
# docker rm cortex
- name: Run Docker
run: |
docker build \
--build-arg REMOTE_CACHE_URL="${{ secrets.MINIO_ENDPOINT }}/vcpkg-cache" \
--build-arg MINIO_ENDPOINT_URL="${{ secrets.MINIO_ENDPOINT }}" \
--build-arg MINIO_ACCESS_KEY="${{ secrets.MINIO_ACCESS_KEY_ID }}" \
--build-arg MINIO_SECRET_KEY="${{ secrets.MINIO_SECRET_ACCESS_KEY }}" \
-t menloltd/cortex:test -f docker/Dockerfile.cache .
docker run -it -d -p 3928:39281 --name cortex menloltd/cortex:test
sleep 20

- name: use python
uses: actions/setup-python@v5
with:
python-version: "3.10"

- name: Run e2e tests
run: |
cd engine
python -m pip install --upgrade pip
python -m pip install -r e2e-test/requirements.txt
pytest e2e-test/test_api_docker.py

- name: Run Docker
continue-on-error: true
if: always()
run: |
docker logs cortex
docker stop cortex
docker rm cortex
echo "y\n" | docker system prune -af
68 changes: 29 additions & 39 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
FROM ubuntu:22.04 as base

FROM base as build

ARG CORTEX_CPP_VERSION=latest

ARG CMAKE_EXTRA_FLAGS=""
# Stage 1: Base dependencies (common stage)
FROM ubuntu:22.04 as common

ENV DEBIAN_FRONTEND=noninteractive

# Install dependencies
# Install common dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
ca-certificates \
software-properties-common \
curl \
wget \
jq \
Expand All @@ -20,71 +16,65 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
apt-get clean && \
rm -rf /var/lib/apt/lists/*

RUN apt-get update && apt-get install -y --no-install-recommends \
# 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 \
software-properties-common \
gpg \
zip \
unzip \
gcc \
g++ \
ninja-build \
pkg-config \
python3-pip \
openssl && \
pip3 install awscli && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*

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 cmake && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
ARG CORTEX_CPP_VERSION=latest
ARG CMAKE_EXTRA_FLAGS=""

WORKDIR /app

# 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 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}"

FROM base as runtime

ENV DEBIAN_FRONTEND=noninteractive

# Install dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
ca-certificates \
curl \
wget \
jq \
tar \
openmpi-bin \
libopenmpi-dev && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*

ARG CORTEX_LLAMACPP_VERSION=latest
# Stage 3: Runtime

WORKDIR /app
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 the Cortex Llama
# 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}

# Copy the entrypoint script
COPY ./docker/entrypoint.sh /usr/local/bin/entrypoint.sh

# 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"]
121 changes: 121 additions & 0 deletions docker/Dockerfile.cache
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"]
3 changes: 2 additions & 1 deletion docker/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
echo "apiServerHost: 0.0.0.0" > /root/.cortexrc
echo "enableCors: true" >> /root/.cortexrc

# Install the engine
cortex engines install llama-cpp -s /opt/cortex.llamacpp
cortex engines list

# Start the cortex server

cortex start

# Keep the container running by tailing the log files
Expand Down
Loading