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

Commit 1c516f0

Browse files
authored
Feat cicd docker (#1646)
* feat: cicd docker * feat: cicd docker * fix: macos updater * docs: update docker docs * fix: macos updater --------- Co-authored-by: Hien To <tominhhien97@gmail.com>
1 parent 481dfb3 commit 1c516f0

File tree

13 files changed

+233
-86
lines changed

13 files changed

+233
-86
lines changed

.github/workflows/beta-build.yml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,17 @@ jobs:
8080
upload_url: ${{ needs.create-draft-release.outputs.upload_url }}
8181
cortex-llamacpp-version: ${{ needs.get-cortex-llamacpp-latest-version.outputs.cortex_llamacpp_latest_version }}
8282

83+
build-docker-x64:
84+
uses: ./.github/workflows/template-build-docker-x64.yml
85+
secrets: inherit
86+
needs: [get-update-version, get-cortex-llamacpp-latest-version]
87+
with:
88+
ref: ${{ github.ref }}
89+
new_version: ${{ needs.get-update-version.outputs.new_version }}
90+
runs-on: ubuntu-latest
91+
cmake-extra-flags: "-DCORTEX_VARIANT=prod"
92+
tags: "menloltd/cortex:${{ needs.get-update-version.outputs.new_version }}"
93+
8394
update_release:
8495
needs: [get-update-version, create-draft-release, build-macos, build-windows-x64, build-linux-x64]
8596
permissions:
@@ -96,7 +107,7 @@ jobs:
96107
run: |
97108
gh release edit v${{ needs.get-update-version.outputs.new_version }} --draft=false --prerelease
98109
env:
99-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
110+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
100111
101112
noti-discord:
102113
needs: [get-update-version, create-draft-release, build-macos, build-windows-x64, build-linux-x64, update_release]

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

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -97,20 +97,21 @@ jobs:
9797
cd engine
9898
make build CMAKE_EXTRA_FLAGS="${{ matrix.cmake-flags }}" BUILD_DEPS_CMAKE_EXTRA_FLAGS="${{ matrix.build-deps-cmake-flags }}"
9999
100-
# - name: Run setup config
101-
# run: |
102-
# rm ~/.cortexrc
103-
# cd engine
104-
# echo "huggingFaceToken: ${{ secrets.HUGGINGFACE_TOKEN_READ }}" > ~/.cortexrc
105-
# echo "gitHubToken: ${{ secrets.PAT_SERVICE_ACCOUNT }}" >> ~/.cortexrc
106-
# echo "apiServerPort: 3928" >> ~/.cortexrc
107-
# ./build/cortex
108-
# cat ~/.cortexrc
100+
- name: Run setup config
101+
run: |
102+
rm ~/.cortexrc
103+
cd engine
104+
echo "huggingFaceToken: ${{ secrets.HUGGINGFACE_TOKEN_READ }}" > ~/.cortexrc
105+
echo "gitHubToken: ${{ secrets.PAT_SERVICE_ACCOUNT }}" >> ~/.cortexrc
106+
./build/cortex
107+
cat ~/.cortexrc
109108
110109
- name: Run unit tests
111110
run: |
112111
cd engine
113112
make run-unit-tests
113+
env:
114+
GITHUB_TOKEN: ${{ secrets.PAT_SERVICE_ACCOUNT }}
114115

115116
- name: Run setup config
116117
run: |

.github/workflows/nightly-build.yml

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ jobs:
8585
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"
8686
channel: nightly
8787
cortex-llamacpp-version: ${{ needs.get-cortex-llamacpp-latest-version.outputs.cortex_llamacpp_latest_version }}
88-
88+
8989
update-latest-version:
9090
runs-on: ubuntu-latest
9191
if: needs.set-public-provider.outputs.public_provider == 'aws-s3'
@@ -104,16 +104,27 @@ jobs:
104104
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
105105
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
106106
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
107-
108107
109108
env:
110109
AWS_ACCESS_KEY_ID: ${{ secrets.DELTA_AWS_ACCESS_KEY_ID }}
111110
AWS_SECRET_ACCESS_KEY: ${{ secrets.DELTA_AWS_SECRET_ACCESS_KEY }}
112111
AWS_DEFAULT_REGION: ${{ secrets.DELTA_AWS_REGION }}
113112
AWS_EC2_METADATA_DISABLED: "true"
114113

114+
build-docker-x64:
115+
if: needs.set-public-provider.outputs.public_provider == 'aws-s3'
116+
uses: ./.github/workflows/template-build-docker-x64.yml
117+
secrets: inherit
118+
needs: [get-update-version, set-public-provider, get-cortex-llamacpp-latest-version, update-latest-version]
119+
with:
120+
ref: ${{ needs.set-public-provider.outputs.ref }}
121+
new_version: nightly-${{ needs.get-update-version.outputs.new_version }}
122+
runs-on: ubuntu-latest
123+
cmake-extra-flags: "-DCORTEX_VARIANT=prod"
124+
tags: menloltd/cortex:nightly-${{ needs.get-update-version.outputs.new_version }}
125+
115126
noti-discord-nightly-and-update-url-readme:
116-
needs: [build-macos, build-windows-x64, build-linux-x64, get-update-version, set-public-provider, get-cortex-llamacpp-latest-version, update-latest-version]
127+
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]
117128
secrets: inherit
118129
if: github.event_name == 'schedule'
119130
uses: ./.github/workflows/template-noti-discord.yaml
@@ -122,7 +133,7 @@ jobs:
122133
new_version: ${{ needs.get-update-version.outputs.new_version }}
123134

124135
noti-discord-manual:
125-
needs: [build-macos, build-windows-x64, build-linux-x64, get-update-version, set-public-provider, get-cortex-llamacpp-latest-version]
136+
needs: [build-macos, build-windows-x64, build-linux-x64, get-update-version, set-public-provider, get-cortex-llamacpp-latest-version, build-docker-x64]
126137
secrets: inherit
127138
if: github.event_name == 'workflow_dispatch' && github.event.inputs.public_provider == 'aws-s3'
128139
uses: ./.github/workflows/template-noti-discord.yaml

.github/workflows/stable-build.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,14 @@ jobs:
7979
channel: stable
8080
upload_url: ${{ needs.create-draft-release.outputs.upload_url }}
8181
cortex-llamacpp-version: ${{ needs.get-cortex-llamacpp-latest-version.outputs.cortex_llamacpp_latest_version }}
82+
83+
build-docker-x64:
84+
uses: ./.github/workflows/template-build-docker-x64.yml
85+
secrets: inherit
86+
needs: [get-update-version, get-cortex-llamacpp-latest-version]
87+
with:
88+
ref: ${{ github.ref }}
89+
new_version: ${{ needs.get-update-version.outputs.new_version }}
90+
runs-on: ubuntu-latest
91+
cmake-extra-flags: "-DCORTEX_VARIANT=prod"
92+
tags: "menloltd/cortex:latest,menloltd/cortex:${{ needs.get-update-version.outputs.new_version }}"
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
name: build-docker-x64
2+
on:
3+
workflow_call:
4+
inputs:
5+
ref:
6+
required: true
7+
type: string
8+
default: 'refs/heads/dev'
9+
new_version:
10+
required: true
11+
type: string
12+
default: ''
13+
runs-on:
14+
required: false
15+
type: string
16+
default: 'ubuntu-latest'
17+
description: 'The runner to use for this job'
18+
cmake-extra-flags:
19+
required: false
20+
type: string
21+
default: ''
22+
description: 'The cmake flags to use for this job'
23+
tags:
24+
required: false
25+
type: string
26+
default: 'menloltd/cortex:latest'
27+
description: 'The tags to use for docker build and push'
28+
29+
jobs:
30+
build-docker-x64:
31+
runs-on: ${{ inputs.runs-on }}
32+
permissions:
33+
contents: write
34+
steps:
35+
- name: Getting the repo
36+
uses: actions/checkout@v3
37+
with:
38+
ref: ${{ inputs.ref }}
39+
submodules: 'recursive'
40+
41+
- name: Set up QEMU
42+
uses: docker/setup-qemu-action@v3
43+
44+
- name: Set up Docker Buildx
45+
uses: docker/setup-buildx-action@v3
46+
47+
- name: Login to Docker Hub
48+
uses: docker/login-action@v3
49+
with:
50+
username: ${{ secrets.DOCKERHUB_USERNAME }}
51+
password: ${{ secrets.DOCKERHUB_TOKEN }}
52+
53+
- name: Build and push
54+
uses: docker/build-push-action@v6
55+
with:
56+
context: .
57+
file: ./docker/Dockerfile
58+
push: true
59+
tags: ${{ inputs.tags }}
60+
build-args: |
61+
CORTEX_CPP_VERSION=${{ inputs.new_version }}
62+
CMAKE_EXTRA_FLAGS=${{ inputs.cmake-extra-flags }}
63+
64+
- name: Update Docker Hub overview
65+
env:
66+
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
67+
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
68+
run: |
69+
README_CONTENT=$(cat docker/README.md | tr -d '\r' | sed ':a;N;$!ba;s/\n/\\n/g')
70+
JSON_PAYLOAD=$(printf '{"full_description": "%s"}' "$README_CONTENT")
71+
72+
curl -X PATCH \
73+
-H "Content-Type: application/json" \
74+
-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)" \
75+
-d "{\"full_description\": \"$JSON_PAYLOAD\"}" \
76+
https://hub.docker.com/v2/repositories/menloltd/cortex/

.github/workflows/template-noti-discord.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,5 @@ jobs:
4242
- Network Installer: https://delta.jan.ai/cortex/v${{ env.VERSION }}/linux-amd64/cortex-${{ env.VERSION }}-linux-amd64-network-installer.deb
4343
- Local Installer: https://delta.jan.ai/cortex/v${{ env.VERSION }}/linux-amd64/cortex-${{ env.VERSION }}-linux-amd64-local-installer.deb
4444
- Binary: https://delta.jan.ai/cortex/v${{ env.VERSION }}/linux-amd64/cortex-nightly.tar.gz
45+
- Docker: menloltd/cortex:${{ env.VERSION }}
4546
- Github action run: https://github.com/janhq/cortex.cpp/actions/runs/${{ env.RUNNER_ID }}

.github/workflows/test-cortexso-model-hub.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ jobs:
5959
run: |
6060
cd engine
6161
make run-unit-tests
62+
env:
63+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6264

6365
- name: Run setup config for linux
6466
shell: bash

docker/Dockerfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ FROM base as build
44

55
ARG CORTEX_CPP_VERSION=latest
66

7+
ARG CMAKE_EXTRA_FLAGS=""
8+
79
ENV DEBIAN_FRONTEND=noninteractive
810

911
# Install dependencies
@@ -47,7 +49,7 @@ COPY ./engine /app/engine
4749

4850
COPY ./docs/static/openapi/cortex.json /app/docs/static/openapi/cortex.json
4951

50-
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"
52+
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}"
5153

5254
FROM base as runtime
5355

docker/README.md

Lines changed: 56 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2,47 +2,64 @@
22

33
This guide will help you set up and run Cortex using Docker.
44

5+
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).
6+
57
### Prerequisites
68
- Docker / Docker Desktop
79
- nvidia-container-toolkit (for GPU support)
810

911
### Instructions
10-
1. Clone the Cortex repository
11-
```bash
12-
git clone https://github.com/janhq/cortex.cpp.git
13-
cd cortex.cpp
14-
git submodule update --init
15-
```
16-
2. Build the Docker image
17-
```bash
18-
# Default always uses the latest cortex.cpp and cortex.llamacpp
19-
docker build -t cortex --build-arg CORTEX_CPP_VERSION=$(git rev-parse HEAD) -f docker/Dockerfile .
20-
21-
# Use specific version of cortex.cpp and cortex.llamacpp
22-
docker build --build-arg CORTEX_LLAMACPP_VERSION=0.1.34 --build-arg CORTEX_CPP_VERSION=$(git rev-parse HEAD) -t cortex -f docker/Dockerfile .
23-
```
24-
25-
3. Run the Docker container
26-
```bash
27-
# Create Volume to store models and data
28-
docker volume create cortex_data
29-
30-
# CPU mode
31-
docker run -it -d --name cortex -v cortex_data:/root/cortexcpp -p 39281:39281 cortex
32-
33-
# GPU mode - nvidia-docker required, it will automatically use all available GPUs
34-
docker run --gpus all -it -d --name cortex -v cortex_data:/root/cortexcpp -p 39281:39281 cortex
35-
```
36-
37-
4. Check logs (Optional)
38-
```bash
39-
docker logs cortex
40-
```
41-
42-
5. Access to http://localhost:39281 to check the cortex docs API.
43-
44-
6. Execute to container and try out cortex cli
45-
```bash
46-
docker exec -it cortex bash
47-
cortex --help
48-
```
12+
13+
**Build Cortex Docker Image from source or Pull from Docker Hub**
14+
15+
- Pull Cortex Docker Image from Docker Hub
16+
17+
```bash
18+
# Pull the latest image
19+
docker pull menloltd/cortex:latest
20+
21+
# Pull a specific version
22+
docker pull menloltd/cortex:nightly-1.0.1-224
23+
```
24+
25+
- Build and Run Cortex Docker Container from Dockerfile
26+
27+
```bash
28+
git clone https://github.com/janhq/cortex.cpp.git
29+
cd cortex.cpp
30+
git submodule update --init
31+
32+
# Default always uses the latest cortex.cpp and cortex.llamacpp
33+
docker build -t menloltd/cortex --build-arg CORTEX_CPP_VERSION=$(git rev-parse HEAD) -f docker/Dockerfile .
34+
35+
# Use specific version of cortex.cpp and cortex.llamacpp
36+
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 .
37+
```
38+
39+
**Run Cortex Docker Container**
40+
41+
```bash
42+
# Create Volume to store models and data
43+
docker volume create cortex_data
44+
45+
# GPU mode - nvidia-docker required, it will automatically use all available GPUs
46+
docker run --gpus all -it -d --name cortex -v cortex_data:/root/cortexcpp -p 39281:39281 menloltd/cortex
47+
48+
# CPU mode
49+
docker run -it -d --name cortex -v cortex_data:/root/cortexcpp -p 39281:39281 menloltd/cortex
50+
```
51+
52+
**Check logs (Optional)**
53+
54+
```bash
55+
docker logs cortex
56+
```
57+
58+
**Access to http://localhost:39281 to check the cortex docs API.**
59+
60+
**Execute to container and try out cortex cli**
61+
62+
```bash
63+
docker exec -it cortex bash
64+
cortex --help
65+
```

0 commit comments

Comments
 (0)