Skip to content

Commit

Permalink
Add elastic service and code of llm-pdf app
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanRublev committed Jun 22, 2024
0 parents commit d656e8c
Show file tree
Hide file tree
Showing 18 changed files with 915 additions and 0 deletions.
37 changes: 37 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Ignore Python cache files
**/__pycache__

# Ignore pytest cache files
.pytest_cache/

# Ignore ruff files
.ruff_cache/

# Ignore git files
.gitignore
.github/

# Ignore Dockerfile and .dockerignore
Dockerfile
.dockerignore

# Ignore other unnecessary files
*.pyc
*.pyo
*.pyd
*~

# Ignore makefile
Makefile

# Environment variables
.envrc

# Fly.io
fly.toml

# Elastic container config
elastic/

# temporary data
tmp/
4 changes: 4 additions & 0 deletions .envrc-example
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export STREAMLIT_SERVER_PORT=8000
export ELASTIC_URL='http://elacticserver:9200'
export OPENAI_API_KEY='<<apikey here>>'
export STREAMLIT_SERVER_COOKIE_SECRET='<<uuid here>>'
43 changes: 43 additions & 0 deletions .github/workflows/fly.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Fly Deploy
on:
push:
branches:
- 'master'
env:
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}
jobs:
test:
name: Run tests
runs-on: ubuntu-latest
env:
STREAMLIT_SERVER_PORT: 8080
STREAMLIT_SERVER_COOKIE_SECRET: 00000000-0000-0000-0000-000000000000
OPENAI_API_KEY: nnn
steps:
- uses: actions/checkout@v4
- name: Restore asdf cache
id: asdf-cache
uses: actions/cache@v4
with:
path: ~/.asdf
key: ${{ runner.os }}-asdf-${{ hashFiles('.tool-versions') }}
- name: Install asdf
uses: asdf-vm/actions/install@v3
- name: Restore poetry cache
id: poetry-cache
uses: actions/cache@v4
with:
path: ~/.cache/pypoetry
key: ${{ runner.os }}-poetry-${{ hashFiles('pyproject.toml') }}
- name: Install Dependencies
run: make deps
- name: Run Linter
run: make lint
deploy:
name: Deploy to fly.io
runs-on: ubuntu-latest
needs: test
steps:
- uses: actions/checkout@v4
- uses: superfly/flyctl-actions/setup-flyctl@master
- run: flyctl deploy --remote-only
49 changes: 49 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# .gitignore
__pycache__/
.pytest_cache/
.ruff_cache/
*.pyc
*.pyo
*.pyd
*.pyc
*.pyo
*.pyd
*.egg-info/
dist/
build/
*.egg
*.log
*.sql
*.sqlite

# Environments
.env
.venv
env/
venv/
ENV/

# IDEs
.idea/
*.swp
*.swo
*.swn
*.pyc
*.pyo
*.pyd
*.egg-info/
dist/
build/
*.egg
*.log
*.sql
*.sqlite

# Poetry
/poetry.lock

# Environment variables
.envrc

# temporary data
tmp/
2 changes: 2 additions & 0 deletions .streamlit/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[server]
maxUploadSize = 3
3 changes: 3 additions & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
python 3.11.2
poetry 1.8.2
direnv 2.32.1
16 changes: 16 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Use an official Python runtime as a parent image
FROM python:3.11-slim-buster

# Set the working directory in the container to /app
WORKDIR /app

# Add the current directory contents into the container at /app
ADD . /app

# Install any needed packages specified in pyproject.toml
RUN pip install poetry
RUN poetry config virtualenvs.create false
RUN poetry install --no-dev

# Run app.py when the container launches
CMD poetry run streamlit run app.py
22 changes: 22 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
.PHONY: deps lint shell server server_headless test

deps:
poetry install

lint:
poetry run ruff check .

shell:
poetry run python

server:
poetry run streamlit run app.py

server_headless:
poetry run streamlit run app.py --browser.serverAddress 0.0.0.0 --server.headless true

test:
poetry run -- ptw -- -s -vv $(args)

test_once:
poetry run pytest -s
5 changes: 5 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from src.llm_pdf import llm_pdf_app


if __name__ == "__main__":
llm_pdf_app()
10 changes: 10 additions & 0 deletions elastic/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Use the official Elasticsearch image
FROM docker.elastic.co/elasticsearch/elasticsearch:8.4.3

# Set environment variables
ENV discovery.type=single-node
ENV xpack.security.enabled=false

# Expose ports
EXPOSE 9200
EXPOSE 9300
25 changes: 25 additions & 0 deletions elastic/fly.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# fly.toml app configuration file generated for llm-pdf-elastic on 2024-06-20T15:19:26+02:00
#
# See https://fly.io/docs/reference/configuration/ for information about how to use this file.
#

app = 'llm-pdf-elastic'
primary_region = 'ams'

[build]

[http_service]
internal_port = 9200
auto_stop_machines = true
auto_start_machines = true
min_machines_running = 1
processes = ['app']

[http_service.concurrency]
type = 'requests'
soft_limit = 250

[[vm]]
memory = '1gb'
cpu_kind = 'shared'
cpus = 1
2 changes: 2 additions & 0 deletions elastic/proxy_port.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
fly proxy 19200:9200 -a llm-pdf-elastic
48 changes: 48 additions & 0 deletions fly.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# fly.toml app configuration file generated for llm-pdf on 2024-06-21T08:48:12+02:00
#
# See https://fly.io/docs/reference/configuration/ for information about how to use this file.
#

app = 'llm-pdf'
primary_region = 'ams'
kill_signal = 'SIGTERM'
kill_timeout = '5s'

[experimental]
auto_rollback = true

[build]

[deploy]
strategy = 'rolling'
wait_timeout = '10m0s'

[env]
ELASTIC_URL = 'http://llm-pdf-elastic.internal:9200'
HOST = 'llm-pdf.fly.dev'
STREAMLIT_SERVER_PORT = '8080'

[http_service]
internal_port = 8080
force_https = true
auto_stop_machines = true
auto_start_machines = true
min_machines_running = 1
processes = ['app']

[http_service.concurrency]
type = 'connections'
hard_limit = 1000
soft_limit = 1000

[[http_service.checks]]
interval = '30s'
timeout = '5s'
grace_period = '10s'
method = 'GET'
path = '/'

[[vm]]
memory = '1024mb'
cpu_kind = 'shared'
cpus = 1
21 changes: 21 additions & 0 deletions logging.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[loggers]
keys=root

[handlers]
keys=consoleHandler

[formatters]
keys=normalFormatter

[logger_root]
level=INFO
handlers=consoleHandler

[handler_consoleHandler]
class=StreamHandler
level=DEBUG
formatter=normalFormatter
args=(sys.stdout,)

[formatter_normalFormatter]
format=%(asctime)s loglevel=%(levelname)-6s logger=%(name)s %(message)s
Loading

0 comments on commit d656e8c

Please sign in to comment.