From 6a2919c6ace64b98886335ea319f5172294c0739 Mon Sep 17 00:00:00 2001 From: hyusap Date: Tue, 5 Mar 2024 18:43:50 -0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=80=20feat:=20add=20support=20for=20ru?= =?UTF-8?q?nning=20API=20using=20docker-compose=20with=20configurable=20en?= =?UTF-8?q?vironment=20variables=20and=20update=20docker-compose.yml=20for?= =?UTF-8?q?=20API=20and=20database=20services.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 3 ++- README.md | 37 ++++++++++++++++---------------- api/docker-compose.yml.example | 39 ++++++++++++++++++++++++++++++++++ 3 files changed, 59 insertions(+), 20 deletions(-) create mode 100644 api/docker-compose.yml.example diff --git a/.gitignore b/.gitignore index 7ac7eb3..19997de 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ api/**/*.db - +api/data +api/docker-compose.yml # Byte-compiled / optimized / DLL files diff --git a/README.md b/README.md index 2e1669a..9105948 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ # Honcho + ![Static Badge](https://img.shields.io/badge/Version-0.0.4-blue) [![Discord](https://img.shields.io/discord/1016845111637839922?style=flat&logo=discord&logoColor=23ffffff&label=Plastic%20Labs&labelColor=235865F2)](https://discord.gg/plasticlabs) ![GitHub License](https://img.shields.io/github/license/plastic-labs/honcho) @@ -35,6 +36,19 @@ directories. ### API +#### Docker + +The API can be run using docker-compose. The `docker-compose.yml.example` file can be copied to `docker-compose.yml` and the environment variables can be set in the `.env` file. + +```bash +cd honcho/api +cp docker-compose.yml.example docker-compose.yml +[ update the file with openai key and other wanted environment variables ] +docker compose up -d +``` + +#### Manually + The API can be run either by installing the necessary dependencies and then specifying the appropriate environment variables. @@ -48,7 +62,7 @@ poetry install # install dependencies 2. Copy the `.env.template` file and specify the type of database and connection_uri. For testing sqlite is fine. The below example uses an - in-memory sqlite database. + in-memory sqlite database. > Honcho has been tested with Postgresql and PGVector @@ -72,26 +86,11 @@ poetry shell # Activate virtual environment if not already enabled python -m uvicorn src.main:app --reload ``` -#### Docker - -Alternatively there is also a `Dockerfile` included to run the API server from a -docker container. - -The `.env` file is not loaded into the docker container and should still be -configured from outside. - -```bash -cd honcho/api -docker build -t honcho-api . -docker run --env-file .env -p 8000:8000 honcho-api:latest -``` - #### Deploy on Fly The API can also be deployed on fly.io. Follow the [Fly.io Docs](https://fly.io/docs/getting-started/) to setup your environment and the -`flyctl`. - +`flyctl`. Once `flyctl` is set up use the following commands to launch the application: @@ -134,12 +133,12 @@ See more information [here](https://python-poetry.org/docs/cli/#add) This project is completely open source and welcomes any and all open source contributions. The workflow for contributing is to make a fork of the repository. You can claim an issue in the issues tab or start a new thread to -indicate a feature or bug fix you are working on. +indicate a feature or bug fix you are working on. Once you have finished your contribution make a PR pointed at the `staging` branch, and it will be reviewed by a project manager. Feel free to join us in our [discord](http://discord.gg/plasticlabs) to discuss your changes or get -help. +help. Once your changes are accepted and merged into staging they will undergo a period of live testing before entering the upstream into `main` diff --git a/api/docker-compose.yml.example b/api/docker-compose.yml.example new file mode 100644 index 0000000..60fc24d --- /dev/null +++ b/api/docker-compose.yml.example @@ -0,0 +1,39 @@ +version: "3.8" +services: + api: + build: + context: . + dockerfile: Dockerfile + ports: + - 8000:8000 + volumes: + - .:/app + environment: + - DATABASE_TYPE=postgres + - CONNECTION_URI=postgresql://testuser:testpwd@database:5432/honcho + - OPENAI_API_KEY=[YOUR_OPENAI_API_KEY] + - OPENTELEMETRY_ENABLED=false + - SENTRY_ENABLED=false + - SENTRY_DSN= + - OTEL_SERVICE_NAME=honcho + - OTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLED=true + - OTEL_PYTHON_LOG_CORRELATION=true + - OTEL_PYTHON_LOG_LEVEL= + - OTEL_EXPORTER_OTLP_PROTOCOL= + - OTEL_EXPORTER_OTLP_ENDPOINT= + - OTEL_EXPORTER_OTLP_HEADERS= + - OTEL_RESOURCE_ATTRIBUTES= + - DEBUG_LOG_OTEL_TO_PROVIDER=false + - DEBUG_LOG_OTEL_TO_CONSOLE=true + database: + image: ankane/pgvector + restart: always + environment: + - POSTGRES_DB=honcho + - POSTGRES_USER=testuser + - POSTGRES_PASSWORD=testpwd + - POSTGRES_HOST_AUTH_METHOD=trust + - PGDATA=/var/lib/postgresql/data/pgdata + volumes: + - ./local/init.sql:/docker-entrypoint-initdb.d/init.sql + - ./data:/var/lib/postgresql/data/