Skip to content

Commit

Permalink
Merge pull request #233 from pepkit/fix_232
Browse files Browse the repository at this point in the history
Address docker compose issues (#232)
  • Loading branch information
nleroy917 authored Nov 21, 2023
2 parents 2c8a73a + aa51c67 commit 60d5706
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 21 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,4 @@ postgres/
.idea
environment/local.env
qdrant_storage/
postgres-data/
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ COPY . /app

COPY --from=build /src/dist web/dist/
RUN python -m pip install --upgrade pip
RUN pip install -r requirements/requirements-all.txt --no-cache-dir
RUN pip install -r requirements/requirements-all-docker.txt --no-cache-dir
RUN pip install torch --index-url https://download.pytorch.org/whl/cpu

CMD ["uvicorn", "pephub.main:app", "--host", "0.0.0.0", "--port", "80"]
36 changes: 20 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,29 +142,18 @@ docker run -p 8000:8000 \

### Option 2. `docker compose`:

The server has been Dockerized and packaged with a [postgres](https://hub.docker.com/_/postgres) image to be run with [`docker compose`](https://docs.docker.com/compose/). This lets you run everything at once and develop without having to manage database instances. The `docker-compose.yaml` file is written such that it mounts the database storage info to a folder called `postgres/` at the root of the repository. This lets you load the database once and have it persist its state after restarting the container.
The server has been Dockerized and packaged with a [postgres](https://hub.docker.com/_/postgres) image to be run with [`docker compose`](https://docs.docker.com/compose/). This lets you run everything at once and develop without having to manage database instances.

You can start a development environment in three steps:
You can start a development environment in two steps:

**1. Obtain the latest database schema:**

```console
sh setup_db.sh
```

**2. Curate your environment:**
**1. Curate your environment:**
Since we are running in `docker`, we need to supply environment variables to the container. The `docker-compose.yaml` file is written such that you can supply a `.env` file at the root with your configurations. See the [example env file](environment/template.env) for reference. See [here](docs/server-settings.md) for a detailed explanation of all configurable server settings. For now, you can simply copy the `env` file:

```
cp environment/template.env .env
```

**3. Build and start the containers:**
If you are running on an Apple M1 chip, you will need to set the following env variable prior to running `docker compose`:

```console
export DOCKER_DEFAULT_PLATFORM=linux/amd64
```
**2. Build and start the containers:**

```console
docker compose up --build
Expand All @@ -173,7 +162,7 @@ docker compose up --build
`pephub` now runs/listens on http://localhost:8000
`postgres` now runs/listens on http://localhost:5432

**3. Utilize the [`load_db`](scripts/load_db.py) script to populate the database with `examples/`:**
**3. (_Optional_) Utilize the [`load_db`](scripts/load_db.py) script to populate the database with `examples/`:**

```console
cd scripts
Expand All @@ -184,4 +173,19 @@ python load_db.py \
../examples
```

**4. (_Optional_) GitHub Authentication Client Setup**

_pephub_ uses GitHub for namespacing and authentication. As such, a GitHub application capable of logging in users is required. We've [included instructions](https://github.com/pepkit/pephub/blob/master/docs/authentication.md#setting-up-github-oauth-for-your-own-server) for setting this up locally using your own GitHub account.

**5. (_Optional_) Vector Database Setup**

We've added [semantic-search](https://huggingface.co/course/chapter5/6?fw=tf#using-embeddings-for-semantic-search) capabilities to pephub. Optionally, you may host an instance of the [qdrant](https://qdrant.tech/) **vector database** to store embeddings computed using a sentence transformer that has mined and processed any relevant metadata from PEPs. If no qdrant connection settings are supplied, pephub will default to SQL search. Read more [here](docs/semantic-search.md). To run qdrant locally, simply run the following:

```
docker pull qdrant/qdrant
docker run -p 6333:6333 \
-v $(pwd)/qdrant_storage:/qdrant/storage \
qdrant/qdrant
```

_Note: If you wish to run the development environment with a pubic database, curate your `.env` file as such._
6 changes: 2 additions & 4 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ version: '3.8'

services:
db:
build:
context: ./postgres
dockerfile: Dockerfile
image: postgres:latest
ports:
- 5432:5432
networks:
Expand Down Expand Up @@ -34,4 +32,4 @@ volumes:

networks:
pephub:
driver: bridge
driver: bridge
1 change: 1 addition & 0 deletions pephub/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@

# mount ui
app.add_middleware(SPA)

# app.add_middleware(EnvironmentMiddleware)
try:
app.mount("/", StaticFiles(directory=SPA_PATH, html=True), name="spa")
Expand Down
19 changes: 19 additions & 0 deletions requirements/requirements-all-docker.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
fastapi>=0.72.0
aiofiles
eido
logmuse>=0.2.7
jinja2>=3.1.2
yacman>=0.8.4
python-multipart>=0.0.5
tqdm
uvicorn
python-dotenv
pepdbagent>=0.6.0
peppy<=0.40.0a4
qdrant-client
requests
aiofiles
pyjwt[crypto]
coloredlogs
-f https://download.pytorch.org/whl/torch_stable.html
sentence-transformers

0 comments on commit 60d5706

Please sign in to comment.