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

Dockerfile fastapi gunicorn uvicorn #2

Merged
merged 8 commits into from
Nov 29, 2023
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
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.