diff --git a/.github/workflows/beta-build.yml b/.github/workflows/beta-build.yml index 0a4d3c735..c9626c730 100644 --- a/.github/workflows/beta-build.yml +++ b/.github/workflows/beta-build.yml @@ -80,6 +80,17 @@ jobs: upload_url: ${{ needs.create-draft-release.outputs.upload_url }} cortex-llamacpp-version: ${{ needs.get-cortex-llamacpp-latest-version.outputs.cortex_llamacpp_latest_version }} + build-docker-x64: + uses: ./.github/workflows/template-build-docker-x64.yml + secrets: inherit + needs: [get-update-version, get-cortex-llamacpp-latest-version] + with: + ref: ${{ github.ref }} + new_version: ${{ needs.get-update-version.outputs.new_version }} + runs-on: ubuntu-latest + cmake-extra-flags: "-DCORTEX_VARIANT=prod" + tags: "menloltd/cortex:${{ needs.get-update-version.outputs.new_version }}" + update_release: needs: [get-update-version, create-draft-release, build-macos, build-windows-x64, build-linux-x64] permissions: @@ -96,7 +107,7 @@ jobs: run: | gh release edit v${{ needs.get-update-version.outputs.new_version }} --draft=false --prerelease env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} noti-discord: needs: [get-update-version, create-draft-release, build-macos, build-windows-x64, build-linux-x64, update_release] diff --git a/.github/workflows/cortex-cpp-quality-gate.yml b/.github/workflows/cortex-cpp-quality-gate.yml index 92852bb93..1194a453b 100644 --- a/.github/workflows/cortex-cpp-quality-gate.yml +++ b/.github/workflows/cortex-cpp-quality-gate.yml @@ -97,20 +97,21 @@ jobs: cd engine make build CMAKE_EXTRA_FLAGS="${{ matrix.cmake-flags }}" BUILD_DEPS_CMAKE_EXTRA_FLAGS="${{ matrix.build-deps-cmake-flags }}" - # - name: Run setup config - # run: | - # rm ~/.cortexrc - # cd engine - # echo "huggingFaceToken: ${{ secrets.HUGGINGFACE_TOKEN_READ }}" > ~/.cortexrc - # echo "gitHubToken: ${{ secrets.PAT_SERVICE_ACCOUNT }}" >> ~/.cortexrc - # echo "apiServerPort: 3928" >> ~/.cortexrc - # ./build/cortex - # cat ~/.cortexrc + - name: Run setup config + run: | + rm ~/.cortexrc + cd engine + echo "huggingFaceToken: ${{ secrets.HUGGINGFACE_TOKEN_READ }}" > ~/.cortexrc + echo "gitHubToken: ${{ secrets.PAT_SERVICE_ACCOUNT }}" >> ~/.cortexrc + ./build/cortex + cat ~/.cortexrc - name: Run unit tests run: | cd engine make run-unit-tests + env: + GITHUB_TOKEN: ${{ secrets.PAT_SERVICE_ACCOUNT }} - name: Run setup config run: | diff --git a/.github/workflows/nightly-build.yml b/.github/workflows/nightly-build.yml index de4a64e51..9a31ef5ff 100644 --- a/.github/workflows/nightly-build.yml +++ b/.github/workflows/nightly-build.yml @@ -85,7 +85,7 @@ jobs: cmake-flags: "-DCORTEX_VARIANT=nightly -DCORTEX_CPP_VERSION='v${{ needs.get-update-version.outputs.new_version }}' -DCMAKE_TOOLCHAIN_FILE=/home/runner/actions-runner/_work/cortex.cpp/cortex.cpp/engine/vcpkg/scripts/buildsystems/vcpkg.cmake" channel: nightly cortex-llamacpp-version: ${{ needs.get-cortex-llamacpp-latest-version.outputs.cortex_llamacpp_latest_version }} - + update-latest-version: runs-on: ubuntu-latest if: needs.set-public-provider.outputs.public_provider == 'aws-s3' @@ -104,7 +104,6 @@ jobs: aws s3 cp s3://${{ secrets.DELTA_AWS_S3_BUCKET_NAME }}/cortex/temp-latest/cortex-mac-universal-network-installer.pkg s3://${{ secrets.DELTA_AWS_S3_BUCKET_NAME }}/cortex/latest/mac-universal/cortex-mac-universal-network-installer.pkg aws s3 cp s3://${{ secrets.DELTA_AWS_S3_BUCKET_NAME }}/cortex/temp-latest/cortex-linux-amd64-network-installer.deb s3://${{ secrets.DELTA_AWS_S3_BUCKET_NAME }}/cortex/latest/linux-amd64/cortex-linux-amd64-network-installer.deb aws s3 cp s3://${{ secrets.DELTA_AWS_S3_BUCKET_NAME }}/cortex/temp-latest/cortex-windows-amd64-network-installer.exe s3://${{ secrets.DELTA_AWS_S3_BUCKET_NAME }}/cortex/latest/windows-amd64/cortex-windows-amd64-network-installer.exe - env: AWS_ACCESS_KEY_ID: ${{ secrets.DELTA_AWS_ACCESS_KEY_ID }} @@ -112,8 +111,20 @@ jobs: AWS_DEFAULT_REGION: ${{ secrets.DELTA_AWS_REGION }} AWS_EC2_METADATA_DISABLED: "true" + build-docker-x64: + if: needs.set-public-provider.outputs.public_provider == 'aws-s3' + uses: ./.github/workflows/template-build-docker-x64.yml + secrets: inherit + needs: [get-update-version, set-public-provider, get-cortex-llamacpp-latest-version, update-latest-version] + with: + ref: ${{ needs.set-public-provider.outputs.ref }} + new_version: nightly-${{ needs.get-update-version.outputs.new_version }} + runs-on: ubuntu-latest + cmake-extra-flags: "-DCORTEX_VARIANT=prod" + tags: menloltd/cortex:nightly-${{ needs.get-update-version.outputs.new_version }} + noti-discord-nightly-and-update-url-readme: - needs: [build-macos, build-windows-x64, build-linux-x64, get-update-version, set-public-provider, get-cortex-llamacpp-latest-version, update-latest-version] + needs: [build-macos, build-windows-x64, build-linux-x64, get-update-version, set-public-provider, get-cortex-llamacpp-latest-version, update-latest-version, build-docker-x64] secrets: inherit if: github.event_name == 'schedule' uses: ./.github/workflows/template-noti-discord.yaml @@ -122,7 +133,7 @@ jobs: new_version: ${{ needs.get-update-version.outputs.new_version }} noti-discord-manual: - needs: [build-macos, build-windows-x64, build-linux-x64, get-update-version, set-public-provider, get-cortex-llamacpp-latest-version] + needs: [build-macos, build-windows-x64, build-linux-x64, get-update-version, set-public-provider, get-cortex-llamacpp-latest-version, build-docker-x64] secrets: inherit if: github.event_name == 'workflow_dispatch' && github.event.inputs.public_provider == 'aws-s3' uses: ./.github/workflows/template-noti-discord.yaml diff --git a/.github/workflows/stable-build.yml b/.github/workflows/stable-build.yml index 2ffece895..2b0523771 100644 --- a/.github/workflows/stable-build.yml +++ b/.github/workflows/stable-build.yml @@ -79,3 +79,14 @@ jobs: channel: stable upload_url: ${{ needs.create-draft-release.outputs.upload_url }} cortex-llamacpp-version: ${{ needs.get-cortex-llamacpp-latest-version.outputs.cortex_llamacpp_latest_version }} + + build-docker-x64: + uses: ./.github/workflows/template-build-docker-x64.yml + secrets: inherit + needs: [get-update-version, get-cortex-llamacpp-latest-version] + with: + ref: ${{ github.ref }} + new_version: ${{ needs.get-update-version.outputs.new_version }} + runs-on: ubuntu-latest + cmake-extra-flags: "-DCORTEX_VARIANT=prod" + tags: "menloltd/cortex:latest,menloltd/cortex:${{ needs.get-update-version.outputs.new_version }}" diff --git a/.github/workflows/template-build-docker-x64.yml b/.github/workflows/template-build-docker-x64.yml new file mode 100644 index 000000000..429397ed8 --- /dev/null +++ b/.github/workflows/template-build-docker-x64.yml @@ -0,0 +1,76 @@ +name: build-docker-x64 +on: + workflow_call: + inputs: + ref: + required: true + type: string + default: 'refs/heads/dev' + new_version: + required: true + type: string + default: '' + runs-on: + required: false + type: string + default: 'ubuntu-latest' + description: 'The runner to use for this job' + cmake-extra-flags: + required: false + type: string + default: '' + description: 'The cmake flags to use for this job' + tags: + required: false + type: string + default: 'menloltd/cortex:latest' + description: 'The tags to use for docker build and push' + +jobs: + build-docker-x64: + runs-on: ${{ inputs.runs-on }} + permissions: + contents: write + steps: + - name: Getting the repo + uses: actions/checkout@v3 + with: + ref: ${{ inputs.ref }} + submodules: 'recursive' + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Build and push + uses: docker/build-push-action@v6 + with: + context: . + file: ./docker/Dockerfile + push: true + tags: ${{ inputs.tags }} + build-args: | + CORTEX_CPP_VERSION=${{ inputs.new_version }} + CMAKE_EXTRA_FLAGS=${{ inputs.cmake-extra-flags }} + + - name: Update Docker Hub overview + env: + DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} + DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} + run: | + README_CONTENT=$(cat docker/README.md | tr -d '\r' | sed ':a;N;$!ba;s/\n/\\n/g') + JSON_PAYLOAD=$(printf '{"full_description": "%s"}' "$README_CONTENT") + + curl -X PATCH \ + -H "Content-Type: application/json" \ + -H "Authorization: JWT $(curl -s -H "Content-Type: application/json" -X POST -d '{"username": "'"$DOCKERHUB_USERNAME"'", "password": "'"$DOCKERHUB_TOKEN"'"}' https://hub.docker.com/v2/users/login/ | jq -r .token)" \ + -d "{\"full_description\": \"$JSON_PAYLOAD\"}" \ + https://hub.docker.com/v2/repositories/menloltd/cortex/ \ No newline at end of file diff --git a/.github/workflows/template-noti-discord.yaml b/.github/workflows/template-noti-discord.yaml index 3752a2201..246f3abcb 100644 --- a/.github/workflows/template-noti-discord.yaml +++ b/.github/workflows/template-noti-discord.yaml @@ -42,4 +42,5 @@ jobs: - Network Installer: https://delta.jan.ai/cortex/v${{ env.VERSION }}/linux-amd64/cortex-${{ env.VERSION }}-linux-amd64-network-installer.deb - Local Installer: https://delta.jan.ai/cortex/v${{ env.VERSION }}/linux-amd64/cortex-${{ env.VERSION }}-linux-amd64-local-installer.deb - Binary: https://delta.jan.ai/cortex/v${{ env.VERSION }}/linux-amd64/cortex-nightly.tar.gz + - Docker: menloltd/cortex:${{ env.VERSION }} - Github action run: https://github.com/janhq/cortex.cpp/actions/runs/${{ env.RUNNER_ID }} diff --git a/.github/workflows/test-cortexso-model-hub.yml b/.github/workflows/test-cortexso-model-hub.yml index 320369235..6e1539420 100644 --- a/.github/workflows/test-cortexso-model-hub.yml +++ b/.github/workflows/test-cortexso-model-hub.yml @@ -59,6 +59,8 @@ jobs: run: | cd engine make run-unit-tests + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Run setup config for linux shell: bash diff --git a/docker/Dockerfile b/docker/Dockerfile index 98a87b1e1..4cbdbef29 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -4,6 +4,8 @@ FROM base as build ARG CORTEX_CPP_VERSION=latest +ARG CMAKE_EXTRA_FLAGS="" + ENV DEBIAN_FRONTEND=noninteractive # Install dependencies @@ -47,7 +49,7 @@ COPY ./engine /app/engine COPY ./docs/static/openapi/cortex.json /app/docs/static/openapi/cortex.json -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" +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 diff --git a/docker/README.md b/docker/README.md index a89686b1e..89b5c3365 100644 --- a/docker/README.md +++ b/docker/README.md @@ -2,47 +2,64 @@ This guide will help you set up and run Cortex using Docker. +For more information on how to use Cortex, please refer to the [Cortex Documentation](https://cortex.so/docs/) and [Cortex Docker](https://cortex.so/docs/installation/docker). + ### Prerequisites - Docker / Docker Desktop - nvidia-container-toolkit (for GPU support) ### Instructions -1. Clone the Cortex repository - ```bash - git clone https://github.com/janhq/cortex.cpp.git - cd cortex.cpp - git submodule update --init - ``` -2. Build the Docker image - ```bash - # Default always uses the latest cortex.cpp and cortex.llamacpp - docker build -t cortex --build-arg CORTEX_CPP_VERSION=$(git rev-parse HEAD) -f docker/Dockerfile . - - # Use specific version of cortex.cpp and cortex.llamacpp - docker build --build-arg CORTEX_LLAMACPP_VERSION=0.1.34 --build-arg CORTEX_CPP_VERSION=$(git rev-parse HEAD) -t cortex -f docker/Dockerfile . - ``` - -3. Run the Docker container - ```bash - # Create Volume to store models and data - docker volume create cortex_data - - # CPU mode - docker run -it -d --name cortex -v cortex_data:/root/cortexcpp -p 39281:39281 cortex - - # GPU mode - nvidia-docker required, it will automatically use all available GPUs - docker run --gpus all -it -d --name cortex -v cortex_data:/root/cortexcpp -p 39281:39281 cortex - ``` - -4. Check logs (Optional) - ```bash - docker logs cortex - ``` - -5. Access to http://localhost:39281 to check the cortex docs API. - -6. Execute to container and try out cortex cli - ```bash - docker exec -it cortex bash - cortex --help - ``` + +**Build Cortex Docker Image from source or Pull from Docker Hub** + +- Pull Cortex Docker Image from Docker Hub + +```bash +# Pull the latest image +docker pull menloltd/cortex:latest + +# Pull a specific version +docker pull menloltd/cortex:nightly-1.0.1-224 +``` + +- Build and Run Cortex Docker Container from Dockerfile + +```bash +git clone https://github.com/janhq/cortex.cpp.git +cd cortex.cpp +git submodule update --init + +# Default always uses the latest cortex.cpp and cortex.llamacpp +docker build -t menloltd/cortex --build-arg CORTEX_CPP_VERSION=$(git rev-parse HEAD) -f docker/Dockerfile . + +# Use specific version of cortex.cpp and cortex.llamacpp +docker build --build-arg CORTEX_LLAMACPP_VERSION=0.1.34 --build-arg CORTEX_CPP_VERSION=$(git rev-parse HEAD) -t menloltd/cortex -f docker/Dockerfile . +``` + +**Run Cortex Docker Container** + +```bash +# Create Volume to store models and data +docker volume create cortex_data + +# GPU mode - nvidia-docker required, it will automatically use all available GPUs +docker run --gpus all -it -d --name cortex -v cortex_data:/root/cortexcpp -p 39281:39281 menloltd/cortex + +# CPU mode +docker run -it -d --name cortex -v cortex_data:/root/cortexcpp -p 39281:39281 menloltd/cortex +``` + +**Check logs (Optional)** + +```bash +docker logs cortex +``` + +**Access to http://localhost:39281 to check the cortex docs API.** + +**Execute to container and try out cortex cli** + +```bash +docker exec -it cortex bash +cortex --help +``` diff --git a/docs/docs/installation/docker.mdx b/docs/docs/installation/docker.mdx index c736c6577..154281be5 100644 --- a/docs/docs/installation/docker.mdx +++ b/docs/docs/installation/docker.mdx @@ -22,6 +22,20 @@ This guide walks you through the setup and running of Cortex using Docker. ### Setup Instructions +#### Build Cortex Docker Image from source or Pull from Docker Hub + +##### Pull Cortex Docker Image from Docker Hub + + ```bash + # Pull the latest image + docker pull menloltd/cortex:latest + + # Pull a specific version + docker pull menloltd/cortex:nightly-1.0.1-224 + ``` + +##### Build and Run Cortex Docker Container from Dockerfile + 1. **Clone the Cortex Repository** ```bash git clone https://github.com/janhq/cortex.cpp.git @@ -31,48 +45,50 @@ This guide walks you through the setup and running of Cortex using Docker. 2. **Build the Docker Image** - - - ```sh - docker build -t cortex --build-arg CORTEX_CPP_VERSION=$(git rev-parse HEAD) -f docker/Dockerfile . - ``` - - - ```sh - docker build --build-arg CORTEX_LLAMACPP_VERSION=0.1.34 --build-arg CORTEX_CPP_VERSION=$(git rev-parse HEAD) -t cortex -f docker/Dockerfile . - ``` - - - -3. **Run the Docker Container** - - Create a Docker volume to store models and data: - ```bash - docker volume create cortex_data - ``` - - + ```sh - # requires nvidia-container-toolkit - docker run --gpus all -it -d --name cortex -v cortex_data:/root/cortexcpp -p 39281:39281 cortex + docker build -t cortex --build-arg CORTEX_CPP_VERSION=$(git rev-parse HEAD) -f docker/Dockerfile . ``` - + ```sh - docker run -it -d --name cortex -v cortex_data:/root/cortexcpp -p 39281:39281 cortex + docker build --build-arg CORTEX_LLAMACPP_VERSION=0.1.34 --build-arg CORTEX_CPP_VERSION=$(git rev-parse HEAD) -t cortex -f docker/Dockerfile . ``` -4. **Check Logs (Optional)** +#### Run Cortex Docker Container + +1. **Run the Docker Container** + - Create a Docker volume to store models and data: + ```bash + docker volume create cortex_data + ``` + + + + ```sh + # requires nvidia-container-toolkit + docker run --gpus all -it -d --name cortex -v cortex_data:/root/cortexcpp -p 39281:39281 cortex + ``` + + + ```sh + docker run -it -d --name cortex -v cortex_data:/root/cortexcpp -p 39281:39281 cortex + ``` + + + +2. **Check Logs (Optional)** ```bash docker logs cortex ``` -5. **Access the Cortex Documentation API** +3. **Access the Cortex Documentation API** - Open [http://localhost:39281](http://localhost:39281) in your browser. -6. **Access the Container and Try Cortex CLI** +4. **Access the Container and Try Cortex CLI** ```bash docker exec -it cortex bash cortex --help diff --git a/engine/cli/commands/cortex_upd_cmd.cc b/engine/cli/commands/cortex_upd_cmd.cc index 129b59405..e30271741 100644 --- a/engine/cli/commands/cortex_upd_cmd.cc +++ b/engine/cli/commands/cortex_upd_cmd.cc @@ -56,11 +56,10 @@ std::string GetNightlyInstallerName(const std::string& v, // C:\Users\vansa\AppData\Local\Temp\cortex\cortex-windows-amd64-network-installer.exe std::string GetInstallCmd(const std::string& exe_path) { #if defined(__APPLE__) && defined(__MACH__) - return "sudo touch /var/tmp/cortex_installer_skip_postinstall && sudo " - "installer " + return "sudo touch /var/tmp/cortex_installer_skip_postinstall_check && sudo installer " "-pkg " + exe_path + - " -target / && sudo rm /var/tmp/cortex_installer_skip_postinstall"; + " -target / && sudo rm /var/tmp/cortex_installer_skip_postinstall_check"; #elif defined(__linux__) return "echo -e \"n\\n\" | sudo SKIP_POSTINSTALL=true apt install -y " "--allow-downgrades " + diff --git a/engine/templates/macos/postinstall b/engine/templates/macos/postinstall index 38310a452..cb8b6dd6e 100644 --- a/engine/templates/macos/postinstall +++ b/engine/templates/macos/postinstall @@ -4,7 +4,7 @@ DESTINATION_BINARY_NAME=cortex DATA_FOLDER_NAME=.cortex CONFIGURATION_FILE_NAME=.cortexrc -if [ -f "/var/tmp/cortex_installer_skip_postinstall" ]; then +if [ -f "/var/tmp/cortex_installer_skip_postinstall_check" ]; then echo "Skipping postinstall script." exit 0 fi diff --git a/engine/templates/macos/postinstall_local b/engine/templates/macos/postinstall_local index 7a6af4090..20d951698 100644 --- a/engine/templates/macos/postinstall_local +++ b/engine/templates/macos/postinstall_local @@ -4,7 +4,7 @@ DESTINATION_BINARY_NAME=cortex DATA_FOLDER_NAME=.cortex CONFIGURATION_FILE_NAME=.cortexrc -if [ -f "/var/tmp/cortex_installer_skip_postinstall" ]; then +if [ -f "/var/tmp/cortex_installer_skip_postinstall_check" ]; then echo "Skipping postinstall script." exit 0 fi