Skip to content

Commit

Permalink
Add fastapi, dockerfile & integrate into ci
Browse files Browse the repository at this point in the history
  • Loading branch information
tiadams committed Feb 15, 2024
1 parent b1f500a commit ef45f3b
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 1 deletion.
21 changes: 21 additions & 0 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,24 @@ jobs:
- name: Test with pytest
run: |
pytest
- name: Build Docker Image
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Get Version Tags
id: versions
run: |
echo "BACKEND_VERSION=$(echo "$(<index/api/routes.py)" | grep -oP "(?<=version=\")[^\"]+")" >> "$GITHUB_OUTPUT"
- name: Docker Login
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build & push backend
uses: docker/build-push-action@v2
with:
file: /Dockerfile
push: true
tags: ghcr.io/${{ github.repository }}/backend:latest, ghcr.io/${{ github.repository }}/backend:${{ steps.versions.outputs.BACKEND_VERSION }}
16 changes: 16 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Define the base image
FROM python:3.9

# Create a folder and copy the folder structure from local
RUN mkdir -p /index

COPY /index /index

# Install API requirements
COPY requirements.txt /tmp/
RUN pip install --requirement /tmp/requirements.txt

EXPOSE 80

# API entry point
CMD ["uvicorn", "index.api.routes:app", "--host", "0.0.0.0", "--port", "80"]
Empty file added index/api/__init__.py
Empty file.
43 changes: 43 additions & 0 deletions index/api/routes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import logging

from fastapi import FastAPI
from starlette.middleware.cors import CORSMiddleware
from starlette.responses import RedirectResponse

app = FastAPI(
title="INDEX",
description="Intelligent data steward toolbox using Large Language Model embeddings "
"for automated Data-Harmonization .",
version="0.0.1",
terms_of_service="https://www.scai.fraunhofer.de/",
contact={
"name": "Dr. Marc Jacobs",
"email": "[email protected]",
},
license_info={
"name": "Apache 2.0",
"url": "https://www.apache.org/licenses/LICENSE-2.0.html",
},
)

origins = ["*"]

app.add_middleware(
CORSMiddleware,
allow_origins=origins,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)

logger = logging.getLogger("uvicorn.info")


@app.get("/", include_in_schema=False)
def swagger_redirect():
return RedirectResponse(url='/docs')


@app.get("/version", tags=["info"])
def get_current_version():
return app.version
6 changes: 5 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,8 @@ scikit-learn==1.3.2
six==1.16.0
thefuzz~=0.20.0
tzdata==2023.3
wheel==0.37.1
wheel==0.37.1
aiofiles~=0.7.0
uvicorn>=0.15.0
python-multipart
fastapi~=0.87.0

0 comments on commit ef45f3b

Please sign in to comment.