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

ci: package rag engine without cuda (cpu only) #18

Merged
merged 9 commits into from
Apr 11, 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
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/custom.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
name: Custom issue template
about: Describe this issue template's objective.
about: Use this template for any issue not covered by the other templates.
title: ''
labels: ''
assignees: ''
Expand Down
39 changes: 20 additions & 19 deletions .github/workflows/package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,21 @@ name: Package Nesis
on:
workflow_dispatch:
inputs:
branch:
description: 'Branch'
required: true
default: main
tag:
description: 'Tag'
required: true
default: latest

jobs:
package_api:
name: API
name: Package API
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
steps:
- name: Check out the repo
uses: actions/checkout@v3
with:
ref: ${{ github.event.inputs.branch }}
uses: actions/checkout@v4

- name: Log in to Docker Hub
uses: docker/login-action@v2
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_PASSWORD }}
Expand All @@ -34,19 +28,22 @@ jobs:
context: .
push: true
file: ./nesis/api/Dockerfile
tags: ametnes/nesis:${{ github.event.inputs.tag }}-api
tags: ametnes/nesis:${{ github.event.inputs.tag }}-api,ametnes/nesis:latest-api
build-args: |
NESIS_VERSION=${{ github.event.inputs.tag }}

package_frontend:
name: Frontend
name: Package Frontend
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
steps:
- name: Check out the repo
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
ref: ${{ github.event.inputs.dockerfile_branch }}

- name: Log in to Docker Hub
uses: docker/login-action@v2
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_PASSWORD }}
Expand All @@ -57,22 +54,24 @@ jobs:
context: .
push: true
file: ./nesis/frontend/Dockerfile
tags: ametnes/nesis:${{ github.event.inputs.tag }}-frontend
tags: ametnes/nesis:${{ github.event.inputs.tag }}-frontend, ametnes/nesis:latest-frontend
build-args: |
PUBLIC_URL=/
PROFILE=PROD
NESIS_VERSION=${{ github.event.inputs.tag }}

package_rag:
name: RAG
name: Package RAG Engine
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
steps:
- name: Check out the repo
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
ref: ${{ github.event.inputs.dockerfile_branch }}

- name: Log in to Docker Hub
uses: docker/login-action@v2
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_PASSWORD }}
Expand All @@ -83,4 +82,6 @@ jobs:
context: .
push: true
file: ./nesis/rag/Dockerfile
tags: ametnes/nesis:${{ github.event.inputs.tag }}-rag
tags: ametnes/nesis:${{ github.event.inputs.tag }}-rag, ametnes/nesis:latest-rag
build-args: |
NESIS_VERSION=${{ github.event.inputs.tag }}
4 changes: 2 additions & 2 deletions .github/workflows/test_api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ jobs:
- 11211:11211
steps:
- name: Check out source
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: "3.11"

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test_rag.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ jobs:
- 11211:11211
steps:
- name: Check out source
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: "3.11"

Expand Down
12 changes: 8 additions & 4 deletions compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,16 @@ services:
environment:
NESIS_RAG_SERVER_PORT: "8080"
NESIS_RAG_PGVECTOR_URL: postgresql://postgres:password@database:5432/nesis
# local mode uses hugging face. Other options
# 1. openai - for OpenAI Embeddings
# 2. sagemaker - for Sagemaker
# 1. local mode uses hugging face. Other options
NESIS_RAG_EMBEDDING_MODE: local
NESIS_RAG_EMBEDDING_DIMENSIONS: "384"

# 2. openai - for OpenAI Embeddings
# NESIS_RAG_EMBEDDING_MODE: openai
# NESIS_RAG_EMBEDDING_DIMENSIONS: "1536"

# 3. sagemaker - for Sagemaker
OPENAI_API_KEY: <your-api-key>
NESIS_RAG_EMBEDDING_DIMENSIONS: "1536"
# OPENAI_API_BASE: <your-api-base>
networks:
- nesis
Expand Down
4 changes: 3 additions & 1 deletion nesis/api/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ RUN apt-get update \
&& pip install -r /app/nesis/api/requirements.txt \
&& pip install flask==3.0.0

ARG UNAME=nesis
ARG NESIS_VERSION
ENV UNAME=nesis
FROM python:3.11.6-slim-bookworm
RUN apt-get update \
&& apt-get clean \
Expand All @@ -26,6 +27,7 @@ ARG PORT="8080"
EXPOSE ${PORT}

ENV PYTHONPATH="/app:${PYTHONPATH}"
ENV NESIS_VERSION=$NESIS_VERSION
USER nesis

CMD /bin/bash /app/nesis/api/start.sh
Expand Down
15 changes: 12 additions & 3 deletions nesis/api/tests/core/controllers/test_management_roles.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def test_create_role_as_user(client):
f"/v1/sessions", headers=tests.get_header(), data=json.dumps(user_data)
).json

# A role as a regular user
# Create a role as a regular user, fails due to permissions
role = {
"name": f"document-manager{random.randint(3, 19)}",
"policy": {"items": [{"action": "create", "resource": "roles"}]},
Expand All @@ -142,20 +142,31 @@ def test_create_role_as_user(client):
)
assert 403 == response.status_code, response.json

# Admin creates the role
roles_response = client.post(
f"/v1/roles",
headers=tests.get_header(token=admin_session["token"]),
data=json.dumps(role),
)
assert 200 == roles_response.status_code, response.json

# And assigns it to the user
response = client.post(
f"/v1/users/{regular_user['id']}/roles",
headers=tests.get_header(token=admin_session["token"]),
data=json.dumps(roles_response.json),
)
assert 200 == response.status_code, response.json

# Getting that user's roles should return the created role
response = client.get(
f"/v1/users/{regular_user['id']}/roles",
headers=tests.get_header(token=admin_session["token"]),
data=json.dumps(roles_response.json),
)
assert 200 == response.status_code, response.json
assert 1 == len(response.json["items"])

role["name"] = (f"document-manager{random.randint(3, 19)}",)
roles_response = client.post(
f"/v1/roles",
Expand All @@ -164,8 +175,6 @@ def test_create_role_as_user(client):
)
assert 200 == roles_response.status_code, response.json

print(json.dumps(response.json))


def test_read_permitted_resources_as_user(client):
"""
Expand Down
2 changes: 2 additions & 0 deletions nesis/frontend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ RUN mkdir -p /app/dist/client \
RUN find /app/dist/client -name node_modules -o -name src -exec rm -rf {} \; || true

FROM node:20
ARG NESIS_VERSION
ARG PROFILE
ENV PUBLIC_URL ${PUBLIC_URL}
ENV APP_HOME=/app/nesis/client
ENV PROFILE ${PROFILE}
ENV NESIS_VERSION=$NESIS_VERSION
ENV UNAME=nesis

# Create app directory
Expand Down
4 changes: 3 additions & 1 deletion nesis/rag/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
FROM python:3.11-buster as build
ARG ENABLE_LOCAL_EMBEDDINGS
COPY nesis/rag/requirements.txt /app/nesis/rag/requirements.txt
COPY nesis/rag/requirements-huggingface.txt /app/nesis/rag/requirements-huggingface.txt

Expand All @@ -8,6 +7,8 @@ RUN apt-get update \
&& /app/.venv/bin/pip install -r /app/nesis/rag/requirements.txt -r /app/nesis/rag/requirements-huggingface.txt --default-timeout=1200



ARG NESIS_VERSION
FROM python:3.11.6-slim-bookworm
RUN apt-get update \
&& apt-get clean \
Expand All @@ -25,6 +26,7 @@ ARG PORT="8080"
EXPOSE ${PORT}

ENV PYTHONPATH="${PYTHONPATH}:/app/nesis"
ENV NESIS_VERSION=$NESIS_VERSION
USER nesis
CMD python nesis/rag/core/main.py

Expand Down
3 changes: 2 additions & 1 deletion nesis/rag/requirements-huggingface.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# Required for local embeddings model
# Use pytorch@cpu
torch @ https://download.pytorch.org/whl/cpu/torch-2.2.2%2Bcpu-cp311-cp311-linux_x86_64.whl
llama-index-embeddings-huggingface==0.1.3
9 changes: 4 additions & 5 deletions package.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
while read -r v; do
docker build -t ametnes/nesis:"$v"-rag . -f nesis/rag/Dockerfile
docker build -t ametnes/nesis:"$v"-api . -f nesis/api/Dockerfile
docker build --build-arg PUBLIC_URL=/ --build-arg PROFILE=PROD -t ametnes/nesis:"$v"-frontend . -f nesis/frontend/Dockerfile
done <version.txt
version=$1
docker build --build-arg NESIS_VERSION="$version" -t ametnes/nesis:"$version"-rag . -f nesis/rag/Dockerfile
docker build --build-arg NESIS_VERSION="$version" -t ametnes/nesis:"$version"-api . -f nesis/api/Dockerfile
docker build --build-arg NESIS_VERSION="$version" --build-arg PUBLIC_URL=/ --build-arg PROFILE=PROD -t ametnes/nesis:"$version"-frontend . -f nesis/frontend/Dockerfile
1 change: 0 additions & 1 deletion version.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
latest
0.0.2