Skip to content

Commit c9e8197

Browse files
authored
Merge pull request #2001 from janhq/chore/sync-dev
chore: sync dev to main
2 parents 0127d84 + bf28b3a commit c9e8197

File tree

106 files changed

+4021
-2387
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

106 files changed

+4021
-2387
lines changed

.devcontainer/Dockerfile

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
FROM mcr.microsoft.com/devcontainers/cpp:1-ubuntu-24.04
2+
3+
ARG REINSTALL_CMAKE_VERSION_FROM_SOURCE="none"
4+
5+
# Optionally install the cmake for vcpkg
6+
COPY ./reinstall-cmake.sh /tmp/
7+
8+
RUN if [ "${REINSTALL_CMAKE_VERSION_FROM_SOURCE}" != "none" ]; then \
9+
chmod +x /tmp/reinstall-cmake.sh && /tmp/reinstall-cmake.sh ${REINSTALL_CMAKE_VERSION_FROM_SOURCE}; \
10+
fi \
11+
&& rm -f /tmp/reinstall-cmake.sh
12+
13+
# [Optional] Uncomment this section to install additional vcpkg ports.
14+
# RUN su vscode -c "${VCPKG_ROOT}/vcpkg install <your-port-name-here>"
15+
16+
# [Optional] Uncomment this section to install additional packages.
17+
# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
18+
# && apt-get -y install --no-install-recommends <your-package-list-here>

.devcontainer/devcontainer.json

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
2+
// README at: https://github.com/devcontainers/templates/tree/main/src/cpp
3+
{
4+
"hostRequirements": {
5+
"cpus": 4,
6+
"memory": "8gb",
7+
"storage": "32gb"
8+
},
9+
"name": "C++",
10+
"build": {
11+
"dockerfile": "Dockerfile"
12+
},
13+
"features": {
14+
"ghcr.io/stuartleeks/dev-container-features/shell-history:0": {},
15+
"ghcr.io/sebst/devcontainer-features/pkgx:1": {},
16+
"ghcr.io/devcontainers-extra/features/apt-packages:1": {
17+
"clean_ppas": true,
18+
"preserve_apt_list": true,
19+
"packages": "build-essential linux-libc-dev",
20+
"ppas": "ppa:deadsnakes/ppa"
21+
}
22+
},
23+
// Features to add to the dev container. More info: https://containers.dev/features.
24+
// "features": {},
25+
// Use 'forwardPorts' to make a list of ports inside the container available locally.
26+
// "forwardPorts": [],
27+
// Use 'postCreateCommand' to run commands after the container is created.
28+
"postCreateCommand": "git submodule update --init",
29+
// Use 'postAttachCommand' to run commands after the container is attached.
30+
"postAttachCommand": "pkgx install npx && npx -y runme run --filename README.md -t devcontainer -y"
31+
// Configure tool-specific properties.
32+
// "customizations": {},
33+
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
34+
// "remoteUser": "root"
35+
}

.devcontainer/reinstall-cmake.sh

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#!/usr/bin/env bash
2+
#-------------------------------------------------------------------------------------------------------------
3+
# Copyright (c) Microsoft Corporation. All rights reserved.
4+
# Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information.
5+
#-------------------------------------------------------------------------------------------------------------
6+
#
7+
set -e
8+
9+
CMAKE_VERSION=${1:-"none"}
10+
11+
if [ "${CMAKE_VERSION}" = "none" ]; then
12+
echo "No CMake version specified, skipping CMake reinstallation"
13+
exit 0
14+
fi
15+
16+
# Cleanup temporary directory and associated files when exiting the script.
17+
cleanup() {
18+
EXIT_CODE=$?
19+
set +e
20+
if [[ -n "${TMP_DIR}" ]]; then
21+
echo "Executing cleanup of tmp files"
22+
rm -Rf "${TMP_DIR}"
23+
fi
24+
exit $EXIT_CODE
25+
}
26+
trap cleanup EXIT
27+
28+
29+
echo "Installing CMake..."
30+
apt-get -y purge --auto-remove cmake
31+
mkdir -p /opt/cmake
32+
33+
architecture=$(dpkg --print-architecture)
34+
case "${architecture}" in
35+
arm64)
36+
ARCH=aarch64 ;;
37+
amd64)
38+
ARCH=x86_64 ;;
39+
*)
40+
echo "Unsupported architecture ${architecture}."
41+
exit 1
42+
;;
43+
esac
44+
45+
CMAKE_BINARY_NAME="cmake-${CMAKE_VERSION}-linux-${ARCH}.sh"
46+
CMAKE_CHECKSUM_NAME="cmake-${CMAKE_VERSION}-SHA-256.txt"
47+
TMP_DIR=$(mktemp -d -t cmake-XXXXXXXXXX)
48+
49+
echo "${TMP_DIR}"
50+
cd "${TMP_DIR}"
51+
52+
curl -sSL "https://github.com/Kitware/CMake/releases/download/v${CMAKE_VERSION}/${CMAKE_BINARY_NAME}" -O
53+
curl -sSL "https://github.com/Kitware/CMake/releases/download/v${CMAKE_VERSION}/${CMAKE_CHECKSUM_NAME}" -O
54+
55+
sha256sum -c --ignore-missing "${CMAKE_CHECKSUM_NAME}"
56+
sh "${TMP_DIR}/${CMAKE_BINARY_NAME}" --prefix=/opt/cmake --skip-license
57+
58+
ln -s /opt/cmake/bin/cmake /usr/local/bin/cmake
59+
ln -s /opt/cmake/bin/ctest /usr/local/bin/ctest

.github/workflows/beta-build.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,9 @@ jobs:
156156
- Network Installer: https://github.com/janhq/cortex.cpp/releases/download/v${{ env.VERSION }}/cortex-${{ env.VERSION }}-linux-amd64-network-installer.deb
157157
- Local Installer: https://github.com/janhq/cortex.cpp/releases/download/v${{ env.VERSION }}/cortex-${{ env.VERSION }}-linux-amd64-local-installer.deb
158158
- Binary: https://github.com/janhq/cortex.cpp/releases/download/v${{ env.VERSION }}/cortex-${{ env.VERSION }}-linux-amd64.tar.gz
159-
- Linux amd64 Deb:
159+
- Linux arm64 Deb:
160160
- Network Installer: https://github.com/janhq/cortex.cpp/releases/download/v${{ env.VERSION }}/cortex-${{ env.VERSION }}-linux-arm64-network-installer.deb
161161
- Local Installer: https://github.com/janhq/cortex.cpp/releases/download/v${{ env.VERSION }}/cortex-${{ env.VERSION }}-linux-arm64-local-installer.deb
162162
- Binary: https://github.com/janhq/cortex.cpp/releases/download/v${{ env.VERSION }}/cortex-${{ env.VERSION }}-linux-arm64.tar.gz
163163
- Docker: menloltd/cortex:beta-${{ env.VERSION }}
164-
- Github Release: https://github.com/janhq/cortex.cpp/releases/tag/v${{ env.VERSION }}
164+
- Github Release: https://github.com/janhq/cortex.cpp/releases/tag/v${{ env.VERSION }}

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

+248
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ env:
1414

1515
jobs:
1616
build-and-test:
17+
if: (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository) || github.event_name == 'workflow_dispatch'
1718
runs-on: ${{ matrix.runs-on }}
1819
timeout-minutes: 60
1920
strategy:
@@ -255,6 +256,7 @@ jobs:
255256
AWS_DEFAULT_REGION: "${{ secrets.MINIO_REGION }}"
256257

257258
build-docker-and-test:
259+
if: (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository) || github.event_name == 'workflow_dispatch'
258260
runs-on: ubuntu-24-04-docker
259261
steps:
260262
- name: Getting the repo
@@ -309,3 +311,249 @@ jobs:
309311
docker stop cortex
310312
docker rm cortex
311313
echo "y\n" | docker system prune -af
314+
315+
build-and-test-target-pr:
316+
permissions:
317+
contents: read
318+
if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.repository
319+
runs-on: ${{ matrix.runs-on }}
320+
timeout-minutes: 60
321+
strategy:
322+
fail-fast: false
323+
matrix:
324+
include:
325+
- os: "linux"
326+
name: "arm64"
327+
runs-on: "ubuntu-2004-arm64"
328+
cmake-flags: "-DCORTEX_CPP_VERSION=${{github.event.pull_request.head.sha}} -DCMAKE_BUILD_TEST=ON -DCMAKE_TOOLCHAIN_FILE=vcpkg/scripts/buildsystems/vcpkg.cmake"
329+
build-deps-cmake-flags: ""
330+
ccache-dir: ""
331+
- os: "linux"
332+
name: "amd64"
333+
runs-on: "ubuntu-20-04-cuda-12-0"
334+
cmake-flags: "-DCORTEX_CPP_VERSION=${{github.event.pull_request.head.sha}} -DCMAKE_BUILD_TEST=ON -DCMAKE_TOOLCHAIN_FILE=vcpkg/scripts/buildsystems/vcpkg.cmake"
335+
build-deps-cmake-flags: ""
336+
ccache-dir: ""
337+
- os: "mac"
338+
name: "amd64"
339+
runs-on: "macos-selfhosted-12"
340+
cmake-flags: "-DCORTEX_CPP_VERSION=${{github.event.pull_request.head.sha}} -DCMAKE_BUILD_TEST=ON -DCMAKE_TOOLCHAIN_FILE=vcpkg/scripts/buildsystems/vcpkg.cmake"
341+
build-deps-cmake-flags: ""
342+
ccache-dir: ""
343+
- os: "mac"
344+
name: "arm64"
345+
runs-on: "macos-selfhosted-12-arm64"
346+
cmake-flags: "-DCORTEX_CPP_VERSION=${{github.event.pull_request.head.sha}} -DCMAKE_BUILD_TEST=ON -DMAC_ARM64=ON -DCMAKE_TOOLCHAIN_FILE=vcpkg/scripts/buildsystems/vcpkg.cmake"
347+
build-deps-cmake-flags: ""
348+
ccache-dir: ""
349+
- os: "windows"
350+
name: "amd64"
351+
runs-on: "windows-cuda-12-0"
352+
cmake-flags: "-DCORTEX_CPP_VERSION=${{github.event.pull_request.head.sha}} -DCMAKE_BUILD_TEST=ON -DBUILD_SHARED_LIBS=OFF -DCMAKE_TOOLCHAIN_FILE=C:/w/cortex.cpp/cortex.cpp/engine/vcpkg/scripts/buildsystems/vcpkg.cmake -DVCPKG_TARGET_TRIPLET=x64-windows-static -DCMAKE_BUILD_TYPE=RELEASE -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CUDA_COMPILER_LAUNCHER=ccache -GNinja"
353+
build-deps-cmake-flags: "-DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CUDA_COMPILER_LAUNCHER=ccache -GNinja"
354+
ccache-dir: 'C:\Users\ContainerAdministrator\AppData\Local\ccache'
355+
steps:
356+
- name: Clone
357+
id: checkout
358+
uses: actions/checkout@v3
359+
with:
360+
submodules: recursive
361+
362+
- name: use python
363+
continue-on-error: true
364+
uses: actions/setup-python@v5
365+
with:
366+
python-version: "3.10"
367+
368+
- name: Install tools on Linux
369+
if: runner.os == 'Linux'
370+
run: |
371+
python3 -m pip install awscli
372+
373+
- name: Install choco on Windows
374+
if: runner.os == 'Windows'
375+
run: |
376+
choco install make pkgconfiglite ccache awscli 7zip ninja -y
377+
378+
- name: Configure vcpkg
379+
if: runner.os != 'Linux'
380+
run: |
381+
cd engine
382+
make configure-vcpkg
383+
384+
- name: Configure vcpkg linux amd64
385+
if: runner.os != 'Linux'
386+
run: |
387+
cd engine
388+
make configure-vcpkg
389+
390+
- name: Configure vcpkg linux arm64
391+
if: runner.os == 'Linux'
392+
run: |
393+
cd engine
394+
# Set env if arch is arm64
395+
if [ "${{ matrix.name }}" == "arm64" ]; then
396+
sudo apt install ninja-build pkg-config -y
397+
export VCPKG_FORCE_SYSTEM_BINARIES=1
398+
fi
399+
make configure-vcpkg
400+
401+
- name: Build
402+
if: runner.os != 'Linux'
403+
run: |
404+
cd engine
405+
make build CMAKE_EXTRA_FLAGS="${{ matrix.cmake-flags }}" BUILD_DEPS_CMAKE_EXTRA_FLAGS="${{ matrix.build-deps-cmake-flags }}"
406+
407+
- name: Build
408+
if: runner.os == 'Linux'
409+
run: |
410+
cd engine
411+
if [ "${{ matrix.name }}" == "arm64" ]; then
412+
export VCPKG_FORCE_SYSTEM_BINARIES=1
413+
fi
414+
make build CMAKE_EXTRA_FLAGS="${{ matrix.cmake-flags }}" BUILD_DEPS_CMAKE_EXTRA_FLAGS="${{ matrix.build-deps-cmake-flags }}"
415+
416+
- name: Run setup config
417+
run: |
418+
cd engine
419+
echo "gitHubToken: ${{ secrets.GITHUB_TOKEN }}" > ~/.cortexrc
420+
# ./build/cortex
421+
cat ~/.cortexrc
422+
423+
- name: Run unit tests
424+
run: |
425+
cd engine
426+
make run-unit-tests
427+
env:
428+
GITHUB_TOKEN: ${{ secrets.PAT_SERVICE_ACCOUNT }}
429+
430+
- name: Run setup config
431+
run: |
432+
cd engine
433+
echo "apiServerPort: 3928" > ~/.cortexrc
434+
echo "gitHubToken: ${{ secrets.GITHUB_TOKEN }}" > ~/.cortexrc
435+
# ./build/cortex
436+
cat ~/.cortexrc
437+
438+
- name: Run e2e tests
439+
if: github.event_name != 'schedule' && runner.os != 'Windows' && github.event.pull_request.draft == false
440+
run: |
441+
cd engine
442+
cp build/cortex build/cortex-nightly
443+
cp build/cortex build/cortex-beta
444+
python -m pip install --upgrade pip
445+
python -m pip install -r e2e-test/requirements.txt
446+
python e2e-test/main.py
447+
rm build/cortex-nightly
448+
rm build/cortex-beta
449+
env:
450+
GITHUB_TOKEN: ${{ secrets.PAT_SERVICE_ACCOUNT }}
451+
452+
- name: Run e2e tests
453+
if: github.event_name != 'schedule' && runner.os == 'Windows' && github.event.pull_request.draft == false
454+
run: |
455+
cd engine
456+
cp build/cortex.exe build/cortex-nightly.exe
457+
cp build/cortex.exe build/cortex-beta.exe
458+
python -m pip install --upgrade pip
459+
python -m pip install -r e2e-test/requirements.txt
460+
python e2e-test/main.py
461+
rm build/cortex-nightly.exe
462+
rm build/cortex-beta.exe
463+
env:
464+
GITHUB_TOKEN: ${{ secrets.PAT_SERVICE_ACCOUNT }}
465+
466+
- name: Run e2e tests
467+
if: github.event_name == 'schedule' && runner.os != 'Windows' && github.event.pull_request.draft == false
468+
run: |
469+
cd engine
470+
cp build/cortex build/cortex-nightly
471+
cp build/cortex build/cortex-beta
472+
python -m pip install --upgrade pip
473+
python -m pip install -r e2e-test/requirements.txt
474+
python e2e-test/cortex-llamacpp-e2e-nightly.py
475+
rm build/cortex-nightly
476+
rm build/cortex-beta
477+
env:
478+
GITHUB_TOKEN: ${{ secrets.PAT_SERVICE_ACCOUNT }}
479+
480+
- name: Run e2e tests
481+
if: github.event_name == 'schedule' && runner.os == 'Windows' && github.event.pull_request.draft == false
482+
run: |
483+
cd engine
484+
cp build/cortex.exe build/cortex-nightly.exe
485+
cp build/cortex.exe build/cortex-beta.exe
486+
python -m pip install --upgrade pip
487+
python -m pip install -r e2e-test/requirements.txt
488+
python e2e-test/cortex-llamacpp-e2e-nightly.py
489+
rm build/cortex-nightly.exe
490+
rm build/cortex-beta.exe
491+
env:
492+
GITHUB_TOKEN: ${{ secrets.PAT_SERVICE_ACCOUNT }}
493+
494+
- name: Pre-package
495+
run: |
496+
cd engine
497+
make pre-package DESTINATION_BINARY_NAME="cortex"
498+
499+
- name: Package
500+
run: |
501+
cd engine
502+
make package
503+
504+
- name: Upload Artifact
505+
uses: actions/upload-artifact@v4
506+
with:
507+
name: cortex-${{ matrix.os }}-${{ matrix.name }}
508+
path: ./engine/cortex
509+
510+
build-docker-and-test-target-pr:
511+
permissions:
512+
contents: read
513+
if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.repository
514+
runs-on: ubuntu-24-04-docker
515+
steps:
516+
- name: Getting the repo
517+
uses: actions/checkout@v3
518+
with:
519+
submodules: 'recursive'
520+
521+
- name: Run Docker
522+
if: github.event_name != 'schedule'
523+
run: |
524+
docker build \
525+
-t menloltd/cortex:test -f docker/Dockerfile .
526+
docker run -it -d -p 3928:39281 --name cortex menloltd/cortex:test
527+
sleep 20
528+
529+
- name: Run Docker
530+
if: github.event_name == 'schedule'
531+
run: |
532+
latest_prerelease=$(curl -s https://api.github.com/repos/cortexcpp/cortex.cpp/releases | jq -r '.[] | select(.prerelease == true) | .tag_name' | head -n 1)
533+
echo "cortex.llamacpp latest release: $latest_prerelease"
534+
docker build \
535+
--build-arg CORTEX_CPP_VERSION="${latest_prerelease}" \
536+
-t menloltd/cortex:test -f docker/Dockerfile .
537+
docker run -it -d -p 3928:39281 --name cortex menloltd/cortex:test
538+
sleep 20
539+
540+
- name: use python
541+
uses: actions/setup-python@v5
542+
with:
543+
python-version: "3.10"
544+
545+
- name: Run e2e tests
546+
run: |
547+
cd engine
548+
python -m pip install --upgrade pip
549+
python -m pip install -r e2e-test/requirements.txt
550+
pytest e2e-test/test_api_docker.py
551+
552+
- name: Run Docker
553+
continue-on-error: true
554+
if: always()
555+
run: |
556+
docker logs cortex
557+
docker stop cortex
558+
docker rm cortex
559+
echo "y\n" | docker system prune -af

0 commit comments

Comments
 (0)