Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat cicd docker #1646

Merged
merged 9 commits into from
Nov 8, 2024
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
13 changes: 12 additions & 1 deletion .github/workflows/beta-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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]
Expand Down
19 changes: 10 additions & 9 deletions .github/workflows/cortex-cpp-quality-gate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
19 changes: 15 additions & 4 deletions .github/workflows/nightly-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -104,16 +104,27 @@ 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 }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.DELTA_AWS_SECRET_ACCESS_KEY }}
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
Expand All @@ -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
Expand Down
11 changes: 11 additions & 0 deletions .github/workflows/stable-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}"
76 changes: 76 additions & 0 deletions .github/workflows/template-build-docker-x64.yml
Original file line number Diff line number Diff line change
@@ -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/
1 change: 1 addition & 0 deletions .github/workflows/template-noti-discord.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
2 changes: 2 additions & 0 deletions .github/workflows/test-cortexso-model-hub.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ FROM base as build

ARG CORTEX_CPP_VERSION=latest

ARG CMAKE_EXTRA_FLAGS=""

ENV DEBIAN_FRONTEND=noninteractive

# Install dependencies
Expand Down Expand Up @@ -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

Expand Down
95 changes: 56 additions & 39 deletions docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
Loading
Loading