Skip to content

Commit

Permalink
Merge pull request #1 from teddy-ambona/feat/add-chatbot
Browse files Browse the repository at this point in the history
Added chatbot
  • Loading branch information
teddy-ambona authored May 3, 2024
2 parents d1dcbbe + e8c232c commit 411a4ee
Show file tree
Hide file tree
Showing 23 changed files with 4,635 additions and 1 deletion.
93 changes: 93 additions & 0 deletions .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
---
name: Application code CICD Pipeline
on: [push]

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Check for code styling, static code issues
run: |
pip install pre-commit
pre-commit install
pre-commit run --all-files -v
image-misconfiguration:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Run Trivy misconfiguration scanner
uses: aquasecurity/trivy-action@master
with:
scan-type: config

# File to scan
scan-ref: Dockerfile
format: table
exit-code: 1
vuln-type: security-check
severity: CRITICAL,HIGH

build:
# Build Docker image and upload it to the pipeline artifacts.
# The image will be re-used in the downstream jobs
needs: [lint, image-misconfiguration]
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Build image tag
id: build_image_tag
run: |
echo "::set-output name=IMAGE_TAG::$(make app-get-version)"
echo "::set-output name=ACT::${ACT}"
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- name: Build and push
uses: docker/build-push-action@v2
with:
context: .
file: ./Dockerfile
tags: ${{ steps.build_image_tag.outputs.IMAGE_TAG }}
outputs: type=docker,dest=/tmp/openai-rag-chatbot-app.tar

- name: Upload artifact
uses: actions/upload-artifact@v2
with:
name: openai-rag-chatbot-app
path: /tmp/openai-rag-chatbot-app.tar
outputs:
SUFFIX: ${{ steps.build_image_tag.outputs.SUFFIX }}
IMAGE_TAG: ${{ steps.build_image_tag.outputs.IMAGE_TAG }}
ACT: ${{ steps.build_image_tag.outputs.ACT }}

image-vulnerabilities:
needs: [build]
runs-on: ubuntu-latest
steps:
- name: Download artifact
uses: actions/download-artifact@v2
with:
name: openai-rag-chatbot-app
path: /tmp

- name: Load Docker image
run: |
docker load --input /tmp/openai-rag-chatbot-app.tar
docker image ls -a
- name: Run Trivy vulnerability scanner
uses: aquasecurity/trivy-action@master
with:
image-ref: ${{ needs.build.outputs.IMAGE_TAG }}
format: table
exit-code: 1
ignore-unfixed: true
vuln-type: library
severity: CRITICAL,HIGH
95 changes: 95 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]

# C extensions
*.so

# Distribution / packaging
.Python
env/
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
*.egg-info/
.installed.cfg
*.egg

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover

# Translations
*.mo
*.pot

# Django stuff:
*.log

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# DotEnv configuration
.env

# Database
*.db
*.rdb

# Pycharm
.idea

# VS Code
.vscode/

# Spyder
.spyproject/

# Jupyter NB Checkpoints
.ipynb_checkpoints/

# Mac OS-specific storage files
.DS_Store

# vim
*.swp
*.swo

# Mypy cache
.mypy_cache/

# Secrets variables
/secrets/

# Python virtual environment
/venv/

# milvus volumes
/volumes/
10 changes: 10 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.1.14
hooks:
# Run the linter.
- id: ruff
args: [ --fix ]
# Run the formatter.
- id: ruff-format
41 changes: 41 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
FROM python:3.11

# Create app user
RUN groupadd -r user && useradd -r -g user --create-home app
RUN chown -R app /home/app
RUN mkdir -v /app && chown -R app /app

WORKDIR /app

RUN apt-get -y update && \
apt-get install -y --no-install-recommends \
make \
curl \
jq && \
apt-get clean

# Create virtual environment and activate it
ENV VIRTUAL_ENV=/opt/venv
RUN python -m venv $VIRTUAL_ENV
ENV PATH="$VIRTUAL_ENV/bin:$PATH"

RUN python -m pip install wheel poetry==1.8.2

COPY poetry.lock pyproject.toml ./

# Install required libraries in the virtual environment
RUN poetry install --no-root

# Python won’t try to write .pyc files on the import of source modules
ENV PYTHONDONTWRITEBYTECODE 1
# Ensure that the stdout and stderr streams are sent straight to terminal
ENV PYTHONUNBUFFERED 1

# Copy python files
COPY src ./src
COPY data ./data

# Using non-root user to reduce vulnerabilities
USER app

CMD ["python", "src/server.py"]
109 changes: 109 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
.PHONY: app-build app-run db-up db-down db-populate clean

PYTHON_VERSION = 3.11
DRUN = docker run --rm
DBASH = $(DRUN) -u root -v ${PWD}:/foo -w="/foo" python:$(PYTHON_VERSION) bash -c
IMAGE_NAME = openai-rag-chatbot-app
IMAGE_VERSION = 0.0.0

# ============================================================
# App commands
# ============================================================

## Buid Docker image of Langserve app
app-build:
docker build -t ${IMAGE_NAME}:${IMAGE_VERSION} .

## Run Docker image
app-run:
docker compose up app

## Return API version (useful for tagging Docker image in CI)
app-get-version:
@echo ${IMAGE_NAME}:${IMAGE_VERSION}

# ============================================================
# DB commands
# ============================================================

## Start DB
db-up:
docker-compose up -d milvus-standalone

## Stop DB
db-down:
docker compose down

## Populate DB with the LASIK eye surgery complications dataset
db-populate:
docker compose run db-populate

## Delete all compiled Python files and Milvus volumes
clean:
find . -type f -name "*.py[co]" -delete
find . -type f -name ".coverage" -delete
find . -type d -name "_pycache_" -delete
find . -type d -name "*.egg-info" -exec rm -r "{}" +
find . -type d -name ".pytest_cache" -exec rm -r "{}" +
rm -rf volumes

#################################################################################
# Self Documenting Commands #
#################################################################################

.DEFAULT_GOAL := help

# Inspired by <http://marmelab.com/blog/2016/02/29/auto-documented-makefile.html>
# sed script explained:
# /^##/:
# * save line in hold space
# * purge line
# * Loop:
# * append newline + line to hold space
# * go to next line
# * if line starts with doc comment, strip comment character off and loop
# * remove target prerequisites
# * append hold space (+ newline) to line
# * replace newline plus comments by ---
# * print line
# Separate expressions are necessary because labels cannot be delimited by
# semicolon; see <http://stackoverflow.com/a/11799865/1968>
.PHONY: help
help:
@echo "$$(tput bold)Available rules:$$(tput sgr0)"
@echo
@sed -n -e "/^## / { \
h; \
s/.*//; \
:doc" \
-e "H; \
n; \
s/^## //; \
t doc" \
-e "s/:.*//; \
G; \
s/\\n## /---/; \
s/\\n/ /g; \
p; \
}" ${MAKEFILE_LIST} \
| LC_ALL='C' sort --ignore-case \
| awk -F '---' \
-v ncol=$$(tput cols) \
-v indent=19 \
-v col_on="$$(tput setaf 6)" \
-v col_off="$$(tput sgr0)" \
'{ \
printf "%s%*s%s ", col_on, -indent, $$1, col_off; \
n = split($$2, words, " "); \
line_length = ncol - indent; \
for (i = 1; i <= n; i++) { \
line_length -= length(words[i]) + 1; \
if (line_length <= 0) { \
line_length = ncol - indent - length(words[i]) - 1; \
printf "\n%*s ", -indent, " "; \
} \
printf "%s ", words[i]; \
} \
printf "\n"; \
}' \
| more $(shell test $(shell uname) = Darwin && echo '--no-init --raw-control-chars')
Loading

0 comments on commit 411a4ee

Please sign in to comment.