Skip to content

Commit

Permalink
fix: Dockerfile
Browse files Browse the repository at this point in the history
Signed-off-by: samzong.lu <[email protected]>
  • Loading branch information
samzong committed May 17, 2024
1 parent a039152 commit 68a9d29
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
15 changes: 12 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
13 changes: 8 additions & 5 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import uvicorn
from fastapi import FastAPI
from fastapi.responses import RedirectResponse

from src.hello import hello

Expand All @@ -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",
Expand All @@ -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")
2 changes: 1 addition & 1 deletion src/hello.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@


def hello():
return "Hello World"
return {"message": "Hello World!"}

0 comments on commit 68a9d29

Please sign in to comment.