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

Feature/devfile updates nov #77

Open
wants to merge 31 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
2940c63
Update host and port to be explicit
Nov 21, 2023
8d9847c
Update dependency management
Nov 21, 2023
4b8f17b
Update run command to use poetry
Nov 21, 2023
795d7b0
Add guidance for API endpoint usage in Dev Spaces
Nov 21, 2023
b8ce5db
Add note on how to add configmap to dev spaces
Nov 21, 2023
e7656f2
Add footnotes for how to properly deploy to dev spaces
Nov 21, 2023
883130b
Add annotations and labels to configmap and secrets
Nov 22, 2023
456fe20
Update pip and poetry
Nov 22, 2023
c582950
WIP openshift deployment action
Nov 22, 2023
4aa460f
Add health endpoint for healthchecks
HunterGerlach Nov 22, 2023
40d8709
Containerize deployment
HunterGerlach Nov 22, 2023
83f6f6a
Adjust container file path
HunterGerlach Nov 22, 2023
4f488c4
Add scripts for faster dev deployments
Nov 27, 2023
6aadd79
Add flags to make install cmd
HunterGerlach Nov 28, 2023
f1759e6
Merge remote-tracking branch 'refs/remotes/origin/feature/devfile-upd…
HunterGerlach Nov 28, 2023
1087aa1
Update deployment workflow for testing
HunterGerlach Nov 28, 2023
68df1a1
Add Kustomize files for dev spaces deploy, config
HunterGerlach Nov 29, 2023
ecb874a
Update kustomize path
Nov 29, 2023
f2822fb
Removed unnecessary annotations/labels
Nov 29, 2023
930cbc1
Attempt to update packages completely
HunterGerlach Nov 29, 2023
5a4d9ed
Add config line to Makefile
HunterGerlach Nov 29, 2023
960bf84
Update installation methods
HunterGerlach Nov 30, 2023
c1809c5
Temporarily remove torch
HunterGerlach Nov 30, 2023
11d0a72
Add placeholder .env files
Nov 30, 2023
614c724
Ensure secret/config updates are not tracked
Nov 30, 2023
8bd9a6e
Removed sentence-transformers
Nov 30, 2023
aeb8c6d
WIP build script and deploy template
Dec 8, 2023
437755b
Move env file ref location to root
Dec 8, 2023
364caf5
WIP Re-order dirs / cleanup
Dec 8, 2023
65ac038
WIP deployment
Dec 9, 2023
a65d817
Fix path reference for some docs
HunterGerlach Jan 12, 2024
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
5 changes: 5 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.venv
.pytest_cache
.coverage
__pycache__
.hypothesis
78 changes: 78 additions & 0 deletions .github/workflows/deploy-openshift.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
name: Deploy to OpenShift

on:
pull_request:
paths:
- "src/**"
- ".github/workflows/**"
- "Makefile"
- "pyproject.toml"
- "poetry.lock"
push:
branches:
- main

jobs:
build-and-deploy:
runs-on: ubuntu-latest
environment: test-non-prod
env:
IMAGE_NAME: deep-thought
REGISTRY_URI: quay.io
OPENSHIFT_PROJECT_NAME: deep-thought-github

steps:
# - name: Checkout repository
# uses: actions/checkout@v2

# - name: Login to OpenShift
# uses: redhat-actions/oc-login@v1
# with:
# openshift_server_url: ${{ secrets.OPENSHIFT_SERVER_URL }}
# openshift_token: ${{ secrets.OPENSHIFT_API_TOKEN }}
# insecure_skip_tls_verify: true
# namespace: ${{ secrets.OPENSHIFT_PROJECT_NAME }}

# - name: Build container image
# uses: redhat-actions/buildah-build@v2
# with:
# image: ${{ env.IMAGE_NAME }}
# tags: latest ${{ github.sha }}
# dockerfiles: |
# ./Dockerfile

# - name: Push To Quay Registry
# uses: redhat-actions/push-to-registry@v2
# with:
# image: ${{ env.IMAGE_NAME }}
# tags: latest
# registry: quay.io/${{ secrets.QUAY_REPOSITORY }}
# username: ${{ secrets.QUAY_USERNAME }}
# password: ${{ secrets.QUAY_PASSWORD }}

# - name: Deploy to OpenShift
# run: |
# oc new-app quay.io/${{ secrets.QUAY_REPOSITORY }}/${{ env.IMAGE_NAME }}:latest
# oc expose svc/${{ env.IMAGE_NAME }}
# oc rollout status deployment/${{ env.IMAGE_NAME }}

# - name: Verify Deployment
# run: |
# oc get pods -n ${{ secrets.OPENSHIFT_PROJECT_NAME }}
- name: Checkout repository
uses: actions/checkout@v2

- name: Login to OpenShift
uses: redhat-actions/oc-login@v1
with:
openshift_server_url: ${{ secrets.OPENSHIFT_SERVER_URL }}
openshift_token: ${{ secrets.OPENSHIFT_API_TOKEN }}
insecure_skip_tls_verify: true
namespace: ${{ secrets.OPENSHIFT_PROJECT_NAME }}

- name: Trigger OpenShift Build
run: oc start-build <build-config-name> --follow --wait

- name: Verify Deployment
run: |
oc get pods -n ${{ secrets.OPENSHIFT_PROJECT_NAME }}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ debug.log
spend.log
.env.config
.env.secrets
.env*
deepthought-dev.json
.venv*

# Byte-compiled / optimized / DLL files
__pycache__/
Expand Down
47 changes: 47 additions & 0 deletions Containerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
ARG POETRY_VERSION=1.7.1

FROM registry.access.redhat.com/ubi8/python-311:1-35 as base

ENV PYTHONFAULTHANDLER=1 \
PYTHONHASHSEED=random \
PYTHONUNBUFFERED=1

FROM base as builder

ARG POETRY_VERSION

USER root
WORKDIR /app

ENV YOUR_ENV=${YOUR_ENV} \
PIP_NO_CACHE_DIR=off \
PIP_DISABLE_PIP_VERSION_CHECK=on \
PIP_DEFAULT_TIMEOUT=100

RUN pip install --upgrade pip && \
pip install "poetry==$POETRY_VERSION"

COPY pyproject.toml poetry.lock /app/

RUN poetry config virtualenvs.create true && \
poetry config virtualenvs.path "/app/.venv" && \
poetry install --no-interaction --no-ansi --no-root --verbose

COPY . /app

USER 1001

FROM base as final

COPY --from=builder /app/.venv /app/.venv
COPY src ./src
COPY deployment/entrypoint.sh .

CMD ["./entrypoint.sh"]


# Local build command
# podman build -t deep-thought:latest -f Dockerfile .

# Local run command
# podman run -it --rm -p 8000:8000 deep-thought:latest
7 changes: 4 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
API_VERSIONS = v1 v2
SERVER_URL = http://127.0.0.1:8000
SERVER_URL = http://0.0.0.0:8000
SPEC_PATH = specs

.PHONY: test run test-api test-all $(API_VERSIONS)

run:
@echo "Current virtualenv: $(VIRTUAL_ENV)"
@uvicorn src.app:app --reload
@poetry run uvicorn src.app:app --reload --host 0.0.0.0 --port 8000

install:
poetry install
poetry config installer.max-workers 10 && \
poetry install --no-interaction --only main --no-root -vvv

upgrade-dependencies:
./src/scripts/upgrade-dependencies.sh
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ Deep Thought is a question-answering system that uses embeddings and a language

## API Details

Information about the API can be found in the [API documentation](API.md).
Information about the API can be found in the [API documentation](./docs/API.md).

## Deployment to OpenShift

Information for deploying Deep Thought to OpenShift can be found in the [deployment documentation](deployment/README.md).

## Contributing

See [CONTRIBUTING.md](CONTRIBUTING.md).
See [CONTRIBUTING.md](./docs/CONTRIBUTING.md).
29 changes: 29 additions & 0 deletions deployment/base/configMap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
kind: ConfigMap
apiVersion: v1
metadata:
name: deep-thought-config
data:
PYTHONPATH: /
SPENDING_WARNING_PCT: '0.8'
OPENAI_MODEL_PRICE: '0.000003'
VERTEX_MODEL_VERSION: v1
GOOGLE_APPLICATION_CREDENTIALS: DEAFULT_PATH
MODEL_PROVIDER: AI_PROVIDER
EMBEDDING_MODEL_NAME: EMBEDDING_MODEL_NAME
LOG_LEVEL: DEBUG
COLLECTION_NAME: YOUR_COLLECTION_NAME
OPENAI_MODEL_NAME: OPENAI_MODEL_NAME
VERTEX_REGION: VERTEXT_REGION
VERTEX_ENDPOINT: VERTEX_ENDPOINT
DISABLE_SWAGGER: 'false'
SPEND_LOG_FILE: spend.log
TOKENIZERS_PARALLELISM: 'false'
APP_FILE: src/app.py
SPEND_LIMIT: '0.075'
CORS_ORIGINS: '*'
VERTEX_PROJECT_ID: VERTEX_PROJECT_ID
VERTEX_MODEL_NAME: VERTEX_MODEL_NAME
API_TITLE: API_TITLE_FOR_SWAGGER
API_VERSION: API_VERSION_FOR_SWAGGER
API_DESCRIPTION: API_DESCRIPTION_FOR_SWAGGER
SPEC_KEYS_TO_IGNORE: 'components,paths,info,'
11 changes: 11 additions & 0 deletions deployment/base/google-application-credentials.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
kind: Secret
apiVersion: v1
metadata:
name: google-application-credentials
data:
deepthought-dev.json: INSERT_JSON # insert deep thought json file. This current resides in /etc/innovation-office/deepthought/deepthought-local.json
type: Opaque

# oc apply -f google-application-credentials.yaml -n admin-devspaces
# oc label secret google-application-credentials controller.devfile.io/mount-to-devworkspace=true controller.devfile.io/watch-secret=true
# oc annotate secret google-application-credentials controller.devfile.io/mount-path="/etc/42"
6 changes: 6 additions & 0 deletions deployment/base/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- configMap.yaml
- secrets.yaml
- google-application-credentials.yaml
12 changes: 12 additions & 0 deletions deployment/base/secrets.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
kind: Secret
apiVersion: v1
metadata:
name: deep-thought-secrets
data:
CONNECTION_STRING: postgresql://... # insert connection string to postgresql vector db
OPENAI_API_KEY: sk-... # insert openai api key
type: Opaque

# oc apply -f secrets.yaml -n admin-devspaces
# oc label secret deep-thought-secrets controller.devfile.io/mount-to-devworkspace=true controller.devfile.io/watch-secret=true
# oc annotate secret deep-thought-secrets controller.devfile.io/mount-as=env
33 changes: 0 additions & 33 deletions deployment/configmap.yaml

This file was deleted.

10 changes: 10 additions & 0 deletions deployment/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/sh

set -e

VENV_PATH=$(find /app/.venv -name 'activate' | grep -m 1 'bin/activate')
source $VENV_PATH

export PYTHONPATH=$(pwd)

uvicorn src.app:app --host 0.0.0.0 --port 8000
8 changes: 0 additions & 8 deletions deployment/google-application-credentials.yaml

This file was deleted.

Empty file.
9 changes: 0 additions & 9 deletions deployment/secrets.yaml

This file was deleted.

9 changes: 9 additions & 0 deletions deployment_k8s/overlay/dev-spaces/configMap-patch.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: deep-thought-config
# annotations:
# controller.devfile.io/mount-as: env
# labels:
# controller.devfile.io/mount-to-devworkspace: 'true'
# controller.devfile.io/watch-configmap: 'true'
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
kind: Secret
apiVersion: v1
metadata:
name: google-application-credentials
# annotations:
# controller.devfile.io/mount-path: /etc/42
# controller.devfile.io/mount-as: file
# labels:
# controller.devfile.io/mount-to-devworkspace: 'true'
# controller.devfile.io/watch-secret: 'true'
File renamed without changes.
21 changes: 21 additions & 0 deletions deployment_old/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash

# Exit in case of error
set -e

APP_MODULE="src.app:app"

# Check if Poetry is installed
if ! command -v poetry &> /dev/null
then
echo "Poetry could not be found, please install it first"
exit 1
fi

# Install dependencies
echo "Installing dependencies..."
#poetry install

# Run application
echo "Starting Deep Thought..."
#uvicorn $APP_MODULE --host 0.0.0.0 --port 8000
File renamed without changes.
File renamed without changes.
Loading
Loading