Skip to content

Commit 6dc1a69

Browse files
author
Esteban D'Amico
committed
Add Langgraph Serverless Dokerized RAG using FastAPI
1 parent a94258d commit 6dc1a69

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+12530
-0
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
node_modules
2+
.git
3+
.github
4+
build
5+
.devcontainer
6+
.serverless
7+
.venv
8+
.vscode
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# For local development only
2+
# OpenAI API key
3+
OPENAI_API_KEY=
4+
PINECONE_API_KEY=
5+
PINECONE_INDEX_NAME=
6+
TAVILY_API_KEY=
7+
8+
# LangSmith tracing
9+
LANGCHAIN_API_KEY=
10+
LANGCHAIN_TRACING_V2=
11+
LANGCHAIN_CALLBACKS_BACKGROUND=
12+
13+
# AWS credentials
14+
AWS_ACCESS_KEY_ID=
15+
AWS_SECRET_ACCESS_KEY=
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[flake8]
2+
max-line-length = 100
3+
max-complexity = 18
4+
select =
5+
"B", # Bugbear
6+
"C", # Cyclomatic complexity
7+
"E", # PEP8 errors
8+
"F", # PyFlakes
9+
"W", # PEP8 warnings
10+
"T4", # Flake8 plugins that check typing
11+
"B9", # Bugbear
12+
#require-plugins =
13+
# "flake8-bugbear",
14+
# "flake8-black",
Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
##### IDE's #####
2+
# VisualStudioCode
3+
/.vscode/
4+
.vscode/*
5+
!.vscode/settings.json
6+
!.vscode/tasks.json
7+
!.vscode/launch.json
8+
!.vscode/extensions.json
9+
*.code-workspace
10+
.history
11+
12+
# IntelliJ IDEA
13+
.idea/*
14+
15+
##### Database #####
16+
*.accdb
17+
*.db
18+
*.dbf
19+
*.mdb
20+
*.pdb
21+
*.sqlite3
22+
23+
24+
##### Logs #####
25+
*.log
26+
*.log*
27+
28+
##### Python #####
29+
# Byte-compiled / optimized / DLL files
30+
__pycache__/
31+
*.py[cod]
32+
*$py.class
33+
34+
# Distribution / packaging
35+
.Python
36+
build/
37+
develop-eggs/
38+
dist/
39+
downloads/
40+
eggs/
41+
.eggs/
42+
lib/
43+
lib64
44+
lib64/
45+
parts/
46+
sdist/
47+
var/
48+
wheels/
49+
pip-wheel-metadata/
50+
share/python-wheels/
51+
*.egg-info/
52+
.installed.cfg
53+
*.egg
54+
MANIFEST
55+
bin/
56+
57+
# Environments
58+
Makefile
59+
.env
60+
.env.*
61+
.env.local
62+
!.env.example
63+
.venv
64+
env/
65+
venv/
66+
ENV/
67+
env.bak/
68+
venv.bak/
69+
.flaskenv
70+
pyvenv.cfg
71+
72+
# PyInstaller
73+
*.manifest
74+
*.spec
75+
76+
# Installer logs
77+
pip-log.txt
78+
pip-delete-this-directory.txt
79+
80+
# Unit test / coverage reports
81+
htmlcov/
82+
.tox/
83+
.nox/
84+
.coverage
85+
.coverage.*
86+
.cache
87+
nosetests.xml
88+
coverage.xml
89+
*.cover
90+
*.py,cover
91+
.hypothesis/
92+
.pytest_cache/
93+
94+
# Flask stuff:
95+
instance/
96+
.webassets-cache
97+
98+
# Translations
99+
*.mo
100+
*.pot
101+
102+
# Sphinx documentation
103+
docs/_build/
104+
105+
# PyBuilder
106+
target/
107+
108+
# IPython
109+
profile_default/
110+
ipython_config.py
111+
112+
# PEP 582
113+
__pypackages__/
114+
115+
# mkdocs documentation
116+
/site
117+
118+
# mypy
119+
.mypy_cache/
120+
.dmypy.json
121+
dmypy.json
122+
123+
124+
# ruff
125+
.ruff_cache/
126+
127+
# Pyre type checker
128+
.pyre/
129+
130+
# pytype static type analyzer
131+
.pytype/
132+
133+
# C extensions
134+
*.so
135+
136+
##### Heroku (old) #####
137+
Procfile
138+
139+
# Serverless
140+
node_modules/
141+
.serverless/
142+
143+
# wsgi
144+
wsgi_handler.py
145+
serverless_wsgi.py
146+
.serverless-wsgi
147+
148+
#OSx
149+
.DS_Store
150+
151+
run.Ps1
152+
153+
154+
# LangGraph
155+
.langgraph_api
156+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"MD041": false,
3+
"MD042": false,
4+
"MD004": false,
5+
"MD013": false,
6+
"MD033": false,
7+
"MD024": false
8+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
22.14.0
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
# See https://pre-commit.com for more information
3+
# See https://pre-commit.com/hooks.html for more hooks
4+
repos:
5+
- repo: https://github.com/pycqa/flake8
6+
rev: 6.0.0
7+
hooks:
8+
- id: flake8
9+
additional_dependencies: [flake8-black, flake8-bugbear]
10+
args: [--config, .flake8]
11+
- repo: https://github.com/astral-sh/ruff-pre-commit
12+
rev: v0.5.1
13+
hooks:
14+
- id: ruff
15+
args: [--fix]
16+
- repo: https://github.com/pycqa/isort
17+
rev: 5.12.0
18+
hooks:
19+
- id: isort
20+
args: [--profile, black]
21+
- repo: local
22+
hooks:
23+
- id: pytest
24+
name: pytest
25+
entry: pytest
26+
language: system
27+
pass_filenames: false
28+
always_run: true
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
disable=SC1090 # Non-constant source
2+
disable=SC1091 # Not specified as input
3+
disable=SC2034 # Unused variables (they are used but in other scripts)
4+
disable=SC2154 # Referenced, but not assigned
5+
disable=SC1071 # Unknown shell
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
extends: default
3+
4+
ignore: |
5+
**/pnpm-lock.yaml
6+
7+
rules:
8+
line-length:
9+
max: 100
10+
ignore: |
11+
**/workflows/lint.yml
12+
**/serverless.yml
13+
**/sls/envs/*.yml
14+
braces:
15+
max-spaces-inside: -1 # Disable spaces inside braces enforcement
16+
min-spaces-inside: -1 # Disable spaces inside braces enforcement
17+
truthy:
18+
ignore: |
19+
**/workflows/*.yml
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# Stage 1: Build development dependencies
2+
FROM python:3.12.0 AS builder-dev
3+
4+
WORKDIR /code
5+
6+
# Install system dependencies for psycopg2 and pipenv
7+
RUN apt-get update \
8+
&& apt-get install --no-install-recommends -y \
9+
libpq-dev \
10+
gcc=4:12.2.0-3 \
11+
&& pip install --no-cache-dir --upgrade pip==24.1.2 \
12+
&& pip install --no-cache-dir pipenv==2024.0.1
13+
14+
# Copy Pipfiles
15+
COPY Pipfile Pipfile.lock ./
16+
17+
# Install development dependencies
18+
RUN pipenv install --dev --system --deploy
19+
20+
21+
22+
# Stage 2: Build production dependencies
23+
FROM python:3.12.0-alpine AS builder-prod
24+
25+
WORKDIR /code
26+
27+
# Install system dependencies for psycopg2 and pipenv
28+
RUN apk update \
29+
&& apk add --no-cache \
30+
postgresql15-dev=15.7-r0 \
31+
gcc=12.2.1_git20220924-r10 \
32+
musl-dev=1.2.4-r2 \
33+
&& pip install --no-cache-dir --upgrade pip==24.1.4 \
34+
&& pip install --no-cache-dir pipenv==2024.0.1
35+
36+
# Copy Pipfiles
37+
COPY Pipfile Pipfile.lock ./
38+
39+
# Install production dependencies
40+
RUN PIPENV_VENV_IN_PROJECT=1 pipenv install --deploy --system
41+
42+
# Stage 3: Final image
43+
FROM python:3.12.0-alpine as production
44+
45+
WORKDIR /code
46+
47+
# Install runtime dependencies for psycopg2
48+
RUN apk update \
49+
&& apk add libpq=15.7-r0
50+
51+
# Copy production dependencies from builder-prod stage
52+
COPY --from=builder-prod /usr/local /usr/local
53+
54+
# Copy the application code
55+
COPY ./app ./app
56+
57+
# Create a non-root user to run the application
58+
RUN adduser -D -H nonroot
59+
60+
# Switch to the non-root user
61+
USER nonroot
62+
63+
# Command to run the application
64+
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "80"]
65+
66+
# Stage 4: Lambda function
67+
FROM public.ecr.aws/lambda/python:3.12 as lambda
68+
69+
WORKDIR ${LAMBDA_TASK_ROOT}
70+
71+
# Install system dependencies for psycopg2 and pipenv
72+
RUN dnf install -y \
73+
postgresql-devel \
74+
gcc-11.4.1-2.amzn2023.0.2.x86_64 \
75+
&& pip install --no-cache-dir --upgrade pip==24.1.2 \
76+
&& pip install --no-cache-dir pipenv==2024.0.1 \
77+
&& dnf clean all
78+
79+
# Copy Pipfiles
80+
COPY Pipfile Pipfile.lock ${LAMBDA_TASK_ROOT}/
81+
82+
# Install production dependencies
83+
RUN PIPENV_VENV_IN_PROJECT=1 pipenv install --system --deploy
84+
85+
# Copy the lambda handler code
86+
COPY . ${LAMBDA_TASK_ROOT}
87+
88+
CMD ["app/main.handler"]

0 commit comments

Comments
 (0)