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

Commit aa51b45

Browse files
authored
chore: docker e2e testing run on selfhosted runner (#1709)
* chore: docker e2e testing run on selfhosted runner * chore: Dockerfile with vcpkg cache --------- Co-authored-by: Hien To <tominhhien97@gmail.com>
1 parent adfbda1 commit aa51b45

File tree

4 files changed

+190
-76
lines changed

4 files changed

+190
-76
lines changed

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

Lines changed: 38 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -188,40 +188,42 @@ jobs:
188188
AWS_SECRET_ACCESS_KEY: "${{ secrets.MINIO_SECRET_ACCESS_KEY }}"
189189
AWS_DEFAULT_REGION: "${{ secrets.MINIO_REGION }}"
190190

191-
# build-docker-and-test:
192-
# runs-on: ubuntu-latest
193-
# steps:
194-
# - name: Getting the repo
195-
# uses: actions/checkout@v3
196-
# with:
197-
# submodules: 'recursive'
198-
199-
# - name: Set up QEMU
200-
# uses: docker/setup-qemu-action@v3
201-
202-
# - name: Set up Docker Buildx
203-
# uses: docker/setup-buildx-action@v3
191+
build-docker-and-test:
192+
runs-on: ubuntu-24-04-docker
193+
steps:
194+
- name: Getting the repo
195+
uses: actions/checkout@v3
196+
with:
197+
submodules: 'recursive'
204198

205-
# - name: Run Docker
206-
# run: |
207-
# docker build -t menloltd/cortex:test -f docker/Dockerfile .
208-
# docker run -it -d -p 3928:39281 --name cortex menloltd/cortex:test
209-
210-
# - name: use python
211-
# uses: actions/setup-python@v5
212-
# with:
213-
# python-version: "3.10"
214-
215-
# - name: Run e2e tests
216-
# run: |
217-
# cd engine
218-
# python -m pip install --upgrade pip
219-
# python -m pip install -r e2e-test/requirements.txt
220-
# pytest e2e-test/test_api_docker.py
221-
222-
# - name: Run Docker
223-
# continue-on-error: true
224-
# if: always()
225-
# run: |
226-
# docker stop cortex
227-
# docker rm cortex
199+
- name: Run Docker
200+
run: |
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
208+
sleep 20
209+
210+
- name: use python
211+
uses: actions/setup-python@v5
212+
with:
213+
python-version: "3.10"
214+
215+
- name: Run e2e tests
216+
run: |
217+
cd engine
218+
python -m pip install --upgrade pip
219+
python -m pip install -r e2e-test/requirements.txt
220+
pytest e2e-test/test_api_docker.py
221+
222+
- name: Run Docker
223+
continue-on-error: true
224+
if: always()
225+
run: |
226+
docker logs cortex
227+
docker stop cortex
228+
docker rm cortex
229+
echo "y\n" | docker system prune -af

docker/Dockerfile

Lines changed: 29 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
1-
FROM ubuntu:22.04 as base
2-
3-
FROM base as build
4-
5-
ARG CORTEX_CPP_VERSION=latest
6-
7-
ARG CMAKE_EXTRA_FLAGS=""
1+
# Stage 1: Base dependencies (common stage)
2+
FROM ubuntu:22.04 as common
83

94
ENV DEBIAN_FRONTEND=noninteractive
105

11-
# Install dependencies
6+
# Install common dependencies
127
RUN apt-get update && apt-get install -y --no-install-recommends \
138
ca-certificates \
9+
software-properties-common \
1410
curl \
1511
wget \
1612
jq \
@@ -20,71 +16,65 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
2016
apt-get clean && \
2117
rm -rf /var/lib/apt/lists/*
2218

23-
RUN apt-get update && apt-get install -y --no-install-recommends \
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 \
2429
git \
2530
uuid-dev \
2631
lsb-release \
27-
software-properties-common \
2832
gpg \
2933
zip \
3034
unzip \
3135
gcc \
3236
g++ \
3337
ninja-build \
3438
pkg-config \
39+
python3-pip \
3540
openssl && \
41+
pip3 install awscli && \
3642
apt-get clean && \
3743
rm -rf /var/lib/apt/lists/*
3844

39-
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 && \
40-
apt-add-repository "deb https://apt.kitware.com/ubuntu/ $(lsb_release -cs) main" && \
41-
apt-get update && \
42-
apt-get install -y cmake && \
43-
apt-get clean && \
44-
rm -rf /var/lib/apt/lists/*
45+
ARG CORTEX_CPP_VERSION=latest
46+
ARG CMAKE_EXTRA_FLAGS=""
4547

4648
WORKDIR /app
4749

50+
# Copy source code
4851
COPY ./engine /app/engine
49-
5052
COPY ./docs/static/openapi/cortex.json /app/docs/static/openapi/cortex.json
5153

54+
# Build project
55+
# Configure vcpkg binary sources
5256
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}"
5357

54-
FROM base as runtime
55-
56-
ENV DEBIAN_FRONTEND=noninteractive
57-
58-
# Install dependencies
59-
RUN apt-get update && apt-get install -y --no-install-recommends \
60-
ca-certificates \
61-
curl \
62-
wget \
63-
jq \
64-
tar \
65-
openmpi-bin \
66-
libopenmpi-dev && \
67-
apt-get clean && \
68-
rm -rf /var/lib/apt/lists/*
69-
70-
ARG CORTEX_LLAMACPP_VERSION=latest
58+
# Stage 3: Runtime
7159

60+
WORKDIR /app
7261
COPY --from=build /app/engine/build/cortex /usr/local/bin/cortex
7362
COPY --from=build /app/engine/build/cortex-server /usr/local/bin/cortex-server
7463

7564
COPY ./docker/download-cortex.llamacpp.sh /tmp/download-cortex.llamacpp.sh
65+
COPY ./docker/entrypoint.sh /usr/local/bin/entrypoint.sh
7666

77-
# Get the latest version of the Cortex Llama
67+
# Get the latest version of Cortex Llama
68+
ARG CORTEX_LLAMACPP_VERSION=latest
7869
RUN chmod +x /tmp/download-cortex.llamacpp.sh && /bin/bash /tmp/download-cortex.llamacpp.sh ${CORTEX_LLAMACPP_VERSION}
7970

80-
# Copy the entrypoint script
81-
COPY ./docker/entrypoint.sh /usr/local/bin/entrypoint.sh
82-
71+
# Configure entrypoint
8372
RUN chmod +x /usr/local/bin/entrypoint.sh
8473

8574
EXPOSE 39281
8675

76+
# Healthcheck
8777
HEALTHCHECK --interval=300s --timeout=30s --start-period=10s --retries=3 \
8878
CMD curl -f http://127.0.0.1:39281/healthz || exit 1
89-
79+
9080
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]

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/entrypoint.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@
55
echo "apiServerHost: 0.0.0.0" > /root/.cortexrc
66
echo "enableCors: true" >> /root/.cortexrc
77

8+
# Install the engine
89
cortex engines install llama-cpp -s /opt/cortex.llamacpp
10+
cortex engines list
911

1012
# Start the cortex server
11-
1213
cortex start
1314

1415
# Keep the container running by tailing the log files

0 commit comments

Comments
 (0)