Skip to content

Commit

Permalink
Merge pull request #2 from AaltoRSE/dockerfile_fastapi_gunicorn_uvicorn
Browse files Browse the repository at this point in the history
  • Loading branch information
ruokolt authored Nov 29, 2023
2 parents af988b3 + b2a16de commit 8409f7c
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 7 deletions.
34 changes: 28 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,30 @@
# https://github.com/tiangolo/uvicorn-gunicorn-fastapi-docker
# https://github.com/tiangolo/uvicorn-gunicorn-fastapi-docker/blob/master/docker-images/python3.11.dockerfile
FROM tiangolo/uvicorn-gunicorn:python3.11
# Dockerfile
FROM mambaorg/micromamba:latest

COPY requirements.txt /tmp/requirements.txt
RUN pip install --no-cache-dir -r /tmp/requirements.txt
USER root

COPY ./app /app
# Run apt install
RUN apt-get update -y && apt-get upgrade -y

# Don't write .pyc files into image to reduce image size
ENV PYTHONDONTWRITEBYTECODE=1 PYTHONUNBUFFERED=1

# Install conda environment to /opt/env/ and prepend to PATH
COPY environment.yml /opt/
RUN micromamba create -f /opt/environment.yml -p /opt/env/
ENV PATH="/opt/env/bin:$PATH"

# Change work directory
WORKDIR /

# Copy application contents
COPY ./app .
COPY ./entrypoint.sh .

# run the container as a non-root user
ENV USER=aaltorse
RUN groupadd -r $USER && useradd -r -g $USER $USER
USER $USER

# Entrypoint
ENTRYPOINT ["/entrypoint.sh"]
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,18 @@
# LLMGateway

An API gateway for Aalto LLM deployment.

Implemented as a FastAPI app, served using gunicorn + uvicorn, and containerized using Docker.

## Run container locally

Build image and run container
```
docker build -t llmgateway .
docker run -p 8000:8000 llmgateway
```

Test the connection
```
curl 0.0.0.0:8000
```
4 changes: 4 additions & 0 deletions app/main.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
"""
A placeholder hello world app.
"""

from typing import Union

from fastapi import FastAPI
Expand Down
2 changes: 2 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/usr/bin/env bash
gunicorn app.main:app --bind 0.0.0.0:8000 -k uvicorn.workers.UvicornWorker --workers 1
2 changes: 2 additions & 0 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ channels:
- conda-forge
dependencies:
- fastapi
- gunicorn
- uvicorn
- redis-py
- pymongo
- schedule
1 change: 0 additions & 1 deletion requirements.txt

This file was deleted.

0 comments on commit 8409f7c

Please sign in to comment.