-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: samzong.lu <[email protected]>
- Loading branch information
Showing
3 changed files
with
21 additions
and
9 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -4,11 +4,20 @@ LABEL maintainer="[email protected]" | |
|
||
WORKDIR /app | ||
|
||
COPY ./* $WORKDIR | ||
# 安装 Poetry | ||
RUN apt-get update && apt-get install -y curl && \ | ||
curl -sSL https://install.python-poetry.org | python3 - && \ | ||
apt-get remove -y curl && apt-get autoremove -y && \ | ||
ln -s $HOME/.local/bin/poetry /usr/local/bin/poetry | ||
|
||
RUN cd $WORKDIR | ||
# 复制项目文件 | ||
COPY . . | ||
|
||
# 安装项目依赖 | ||
RUN poetry install --no-dev | ||
|
||
# 暴露端口 | ||
EXPOSE 5000 | ||
|
||
CMD ["uvicorn", "main:app" ,"--host", "0.0.0.0", "--port", "5000"] | ||
# 启动项目 | ||
CMD ["poetry", "run", "uvicorn", "main:app" ,"--host", "0.0.0.0", "--port", "5000"] |
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 |
---|---|---|
|
@@ -11,6 +11,7 @@ | |
|
||
import uvicorn | ||
from fastapi import FastAPI | ||
from fastapi.responses import RedirectResponse | ||
|
||
from src.hello import hello | ||
|
||
|
@@ -21,11 +22,9 @@ | |
title="Template Project", | ||
description="A template project of FastAPI", | ||
version="1.0", | ||
terms_of_service="https://samzong.me", | ||
contact={ | ||
"name": "Samzong Lu", | ||
"url": "https://samzong.me", | ||
"email": "[email protected]" | ||
}, | ||
license_info={ | ||
"name": "Apache 2.0", | ||
|
@@ -35,9 +34,13 @@ | |
|
||
|
||
@app.get("/") | ||
async def index(): | ||
return hello() | ||
async def root(): | ||
return RedirectResponse(url="/docs") | ||
|
||
|
||
@app.get("/hello") | ||
async def get_hello(): | ||
return hello() | ||
|
||
if __name__ == '__main__': | ||
uvicorn.run(app, host="0.0.0.0", port=8000, log_level="info") | ||
uvicorn.run(app, host="0.0.0.0", port=5000, log_level="info") |
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 |
---|---|---|
|
@@ -11,4 +11,4 @@ | |
|
||
|
||
def hello(): | ||
return "Hello World" | ||
return {"message": "Hello World!"} |