-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add predefined service template for FastAPI * Add README * Add to supported services
- Loading branch information
1 parent
f769f51
commit 730c530
Showing
8 changed files
with
118 additions
and
20 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
9 changes: 9 additions & 0 deletions
9
predefined-services/backend/fastapi/backend-fastapi/Dockerfile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
15
predefined-services/backend/fastapi/backend-fastapi/app/main.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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} |
3 changes: 3 additions & 0 deletions
3
predefined-services/backend/fastapi/backend-fastapi/requirements.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |