Skip to content

Commit

Permalink
Predefined service: FastAPI (#314)
Browse files Browse the repository at this point in the history
* Add predefined service template for FastAPI

* Add README

* Add to supported services
  • Loading branch information
marcauberer committed Apr 25, 2022
1 parent f769f51 commit 730c530
Show file tree
Hide file tree
Showing 8 changed files with 118 additions and 20 deletions.
40 changes: 20 additions & 20 deletions docs/docs/supported-services.md

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions predefined-services/backend/fastapi/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
## FastAPI
FastAPI is a high-performance, easy to learn, fast to code and ready for production framework for building APIs. It is based on Python 3.6+ and can handle massive amounts of requests in parallel due to its asynchronous programming style.

### Setup
FastAPI is considered as backend service and can therefore be found in backends collection, when generating the compose configuration with Compose Generator.

### Usage
Compose Generator provides a basic Hello World API out of the box which can be found at the url root.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM python:${{FASTAPI_PYTHON_VERSION}}-alpine
WORKDIR /app

COPY ./requirements.txt ./requirements.txt
RUN pip install --no-cache-dir --upgrade -r ./requirements.txt

COPY ./app ./app

CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "80"]
Empty file.
15 changes: 15 additions & 0 deletions predefined-services/backend/fastapi/backend-fastapi/app/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from typing import Optional

from fastapi import FastAPI

app = FastAPI()


@app.get("/")
def read_root():
return {"Hello": "World"}


@app.get("/items/{item_id}")
def read_item(item_id: int, q: Optional[str] = None):
return {"item_id": item_id, "q": q}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fastapi==${{FASTAPI_VERSION}}
pydantic==1.9.0
uvicorn==0.17.6
51 changes: 51 additions & 0 deletions predefined-services/backend/fastapi/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"label": "FastAPI",
"preselected": "false",
"proxied": true,
"files": [
{
"path": "service.yml",
"type": "service"
},
{
"path": "README.md",
"type": "docs"
},
{
"path": "${{FASTAPI_SOURCE_DIRECTORY}}/Dockerfile",
"type": "config"
},
{
"path": "${{FASTAPI_SOURCE_DIRECTORY}}/requirements.txt",
"type": "config"
}
],
"questions": [
{
"text": "On which port you want to expose your FastAPI?",
"type": 2,
"defaultValue": "80",
"validator": "port",
"variable": "FASTAPI_PORT"
},
{
"text": "Which Python version do you want to use?",
"type": 2,
"defaultValue": "3.10",
"variable": "FASTAPI_PYTHON_VERSION"
},
{
"text": "Which FastAPI version do you want to use?",
"type": 2,
"defaultValue": "0.75.2",
"variable": "FASTAPI_VERSION"
}
],
"volumes": [
{
"text": "Custom path for backend source directory?",
"defaultValue": "./backend-fastapi",
"variable": "FASTAPI_SOURCE_DIRECTORY"
}
]
}
12 changes: 12 additions & 0 deletions predefined-services/backend/fastapi/service.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
build: ${{FASTAPI_SOURCE_DIRECTORY}}
container_name: ${{PROJECT_NAME_CONTAINER}}-backend-fastapi
restart: always
networks:
#? if has services.frontend {
# - frontend-backend
#? }
#? if has services.database {
# - backend-database
#? }
ports:
- ${{FASTAPI_PORT}}:80

0 comments on commit 730c530

Please sign in to comment.