diff --git a/Dockerfile b/Dockerfile index b3ea63c..51c503c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 \ No newline at end of file +# 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"] \ No newline at end of file diff --git a/README.md b/README.md index 47d1826..edae62a 100644 --- a/README.md +++ b/README.md @@ -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 +``` diff --git a/app/main.py b/app/main.py index 45a7db3..12fc463 100644 --- a/app/main.py +++ b/app/main.py @@ -1,3 +1,7 @@ +""" +A placeholder hello world app. +""" + from typing import Union from fastapi import FastAPI diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100755 index 0000000..2194769 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,2 @@ +#!/usr/bin/env bash +gunicorn app.main:app --bind 0.0.0.0:8000 -k uvicorn.workers.UvicornWorker --workers 1 \ No newline at end of file diff --git a/environment.yml b/environment.yml index ec932b8..ce22399 100644 --- a/environment.yml +++ b/environment.yml @@ -3,6 +3,8 @@ channels: - conda-forge dependencies: - fastapi + - gunicorn + - uvicorn - redis-py - pymongo - schedule diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index 6b0b939..0000000 --- a/requirements.txt +++ /dev/null @@ -1 +0,0 @@ -fastapi