Skip to content

Commit

Permalink
feat(#63): add k8s deployment of ai app
Browse files Browse the repository at this point in the history
  • Loading branch information
billmetangmo committed Dec 12, 2023
1 parent 1daf3dd commit 9e67da2
Show file tree
Hide file tree
Showing 7 changed files with 176 additions and 7 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -186,4 +186,8 @@ etl/experiments/.chainlit/**
etl/.chainlit/**
etl/embeddings/**

format.*
format.*

# Ignore DevSpace/chainlit cache and log folder
.devspace/
.chainlit/
21 changes: 21 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Use an official Python runtime as a parent image
FROM python:3.11.7-bullseye

# Set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1

# Set the working directory in the container
WORKDIR /app

# Install any needed packages specified in requirements.txt
COPY etl/requirements.txt /app/
RUN pip install --no-cache-dir -r requirements.txt

# Copy the current directory contents into the container at /app
COPY . /app/

# Make port 8000 available to the world outside this container
EXPOSE 8000

CMD cd etl && chainlit run experiments/ui.py
114 changes: 114 additions & 0 deletions devspace.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
version: v2beta1
name: tchoung-tegit

# This is a list of `pipelines` that DevSpace can execute (you can define your own)
pipelines:
# This is the pipeline for the main command: `devspace dev` (or `devspace run-pipeline dev`)
dev:
run: |-
run_dependencies --all # 1. Deploy any projects this project needs (see "dependencies")
ensure_pull_secrets --all # 2. Ensure pull secrets
create_deployments --all # 3. Deploy Helm charts and manifests specfied as "deployments"
start_dev app # 4. Start dev mode "app" (see "dev" section)
# You can run this pipeline via `devspace deploy` (or `devspace run-pipeline deploy`)
deploy:
run: |-
run_dependencies --all # 1. Deploy any projects this project needs (see "dependencies")
ensure_pull_secrets --all # 2. Ensure pull secrets
build_images --all -t $(git describe --always) # 3. Build, tag (git commit hash) and push all images (see "images")
create_deployments --all # 4. Deploy Helm charts and manifests specfied as "deployments"
# This is a list of `images` that DevSpace can build for this project
# We recommend to skip image building during development (devspace dev) as much as possible
images:
app:
image: mongulu/tchoung-te
dockerfile: ./Dockerfile

# This is a list of `deployments` that DevSpace can create for this project
deployments:
app:
# This deployment uses `helm` but you can also define `kubectl` deployments or kustomizations
helm:
# We are deploying this project with the Helm chart you provided
chart:
name: component-chart
repo: https://charts.devspace.sh
# Under `values` we can define the values for this Helm chart used during `helm install/upgrade`
# You may also use `valuesFiles` to load values from files, e.g. valuesFiles: ["values.yaml"]
values:
containers:
- image: mongulu/tchoung-te
env:
- name: OPENAI_API_KEY
valueFrom:
secretKeyRef:
key: root
name: openai-credentials
- name: LANGCHAIN_TRACING_V2
value: "true"
- name: LANGCHAIN_ENDPOINT
value: https://api.smith.langchain.com
- name: LANGCHAIN_PROJECT
value: tchoung-te
- name: LANGCHAIN_API_KEY
valueFrom:
secretKeyRef:
key: root
name: langchain-credentials
service:
ports:
- port: 8000
type: LoadBalancer
ingress:
tls: true
tlsClusterIssuer: letsencrypt-prod
ingressClass: traefik
rules:
- host: ai.mongulu.cm

# This is a list of `dev` containers that are based on the containers created by your deployments
dev:
app:
# Search for the container that runs this image
imageSelector: mongulu/tchoung-te
# Replace the container image with this dev-optimized image (allows to skip image building during development)
devImage: python:3.11.7-bullseye
# Sync files between the local filesystem and the development container
sync:
- path: ./:/app
# Open a terminal and use the following command to start it
terminal:
command: ./app/devspace_start.sh
# Inject a lightweight SSH server into the container (so your IDE can connect to the remote dev env)
ssh:
enabled: true
# Make the following commands from my local machine available inside the dev container
proxyCommands:
- command: devspace
- command: kubectl
- command: helm
- gitCredentials: true
# Forward the following ports to be able access your application via localhost
ports:
- port: "8000"
# Open the following URLs once they return an HTTP status code other than 502 or 503
open:
- url: http://localhost:8000

# Use the `commands` section to define repeatable dev workflows for this project
commands:
migrate-db:
command: |-
echo 'This is a cross-platform, shared command that can be used to codify any kind of dev task.'
echo 'Anyone using this project can invoke it via "devspace run migrate-db"'
# Define dependencies to other projects with a devspace.yaml
# dependencies:
# api:
# git: https://... # Git-based dependencies
# tag: v1.0.0
# ui:
# path: ./ui # Path-based dependencies (for monorepos)

# To fill , use https://www.devspace.sh/component-chart/docs/configuration
36 changes: 36 additions & 0 deletions devspace_start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/bash
set +e # Continue on errors

COLOR_BLUE="\033[0;94m"
COLOR_GREEN="\033[0;92m"
COLOR_RESET="\033[0m"

# Print useful output for user
echo -e "${COLOR_BLUE}
%########%
%###########% ____ _____
%#########% | _ \ ___ __ __ / ___/ ____ ____ ____ ___
%#########% | | | | / _ \\\\\ \ / / \___ \ | _ \ / _ | / __// _ \\
%#############% | |_| |( __/ \ V / ____) )| |_) )( (_| |( (__( __/
%#############% |____/ \___| \_/ \____/ | __/ \__,_| \___\\\\\___|
%###############% |_|
%###########%${COLOR_RESET}
Welcome to your development container!
This is how you can work with it:
- Files will be synchronized between your local machine and this container
- Some ports will be forwarded, so you can access this container via localhost
- Run \`${COLOR_GREEN}python main.py${COLOR_RESET}\` to start the application
"

# Set terminal prompt
export PS1="\[${COLOR_BLUE}\]devspace\[${COLOR_RESET}\] ./\W \[${COLOR_BLUE}\]\\$\[${COLOR_RESET}\] "
if [ -z "$BASH" ]; then export PS1="$ "; fi

# Include project's bin/ folder in PATH
export PATH="./bin:$PATH"

# Open shell
bash --norc
Binary file removed etl/experiments/ai_robot.jpeg
Binary file not shown.
5 changes: 0 additions & 5 deletions etl/experiments/chainlit.md

This file was deleted.

1 change: 0 additions & 1 deletion etl/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
colorama==0.4.4
findspark==2.0.1
geocoder==1.38.1
geopandas==0.10.2
geopy==2.2.0
jupyter==1.0.0
jupyter-utils==1.2.6
Expand Down

0 comments on commit 9e67da2

Please sign in to comment.