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

Add fastapi, dockerfile & integrate into ci #2

Merged
merged 3 commits into from
Feb 16, 2024
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
27 changes: 24 additions & 3 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python

name: Python package

on:
Expand Down Expand Up @@ -38,3 +35,27 @@ jobs:
- name: Test with pytest
run: |
pytest

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/scai-bio/backend:latest
ghcr.io/scai-bio/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
Loading