Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🚀 feat: add support for running API using docker-compose with configurable environment variables and update docker-compose.yml for API and database services. #34

Merged
merged 2 commits into from
Mar 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
api/**/*.db

api/data
api/docker-compose.yml


# Byte-compiled / optimized / DLL files
Expand Down
36 changes: 17 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,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.

Expand All @@ -48,7 +61,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

Expand All @@ -72,26 +85,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:

Expand Down Expand Up @@ -134,12 +132,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`
Expand Down
39 changes: 39 additions & 0 deletions api/docker-compose.yml.example
Original file line number Diff line number Diff line change
@@ -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/
Loading