diff --git a/.gitea/workflows/build_app.yaml b/.gitea/workflows/build_app.yaml index de673b5..4be868a 100644 --- a/.gitea/workflows/build_app.yaml +++ b/.gitea/workflows/build_app.yaml @@ -5,7 +5,7 @@ on: branches: [master] paths-ignore: - 'requirements.txt' - - 'RuntimeDockerfile' + - '*RuntimeDockerfile' - '.gitignore' - 'README.md' - '.gitea/workflows/**' diff --git a/.gitea/workflows/build_runtime.yaml b/.gitea/workflows/build_runtime.yaml index 2bd7bba..cd5da2f 100644 --- a/.gitea/workflows/build_runtime.yaml +++ b/.gitea/workflows/build_runtime.yaml @@ -6,7 +6,7 @@ on: paths: - 'requirements.txt' - 'poetry.lock' - - 'RuntimeDockerfile' + - '*RuntimeDockerfile' jobs: build-runtime: @@ -26,7 +26,7 @@ jobs: repo=${var##*/}"-runtime" version=$(grep -oP '(?<=version = ")(.*)(?=")' "pyproject.toml") new_version="v${version}" - docker build -t hub.airpig.cn/library/$repo:$new_version -f RuntimeDockerfile . + docker build -t hub.airpig.cn/library/$repo:$new_version -f AlpineRuntimeDockerfile . docker push hub.airpig.cn/library/$repo:$new_version docker rmi hub.airpig.cn/library/$repo:$new_version - run: echo "This job's status is ${{ job.status }}." \ No newline at end of file diff --git a/AlpineRuntimeDockerfile b/AlpineRuntimeDockerfile new file mode 100644 index 0000000..4eac719 --- /dev/null +++ b/AlpineRuntimeDockerfile @@ -0,0 +1,30 @@ +FROM python:3.11-alpine as builder + +RUN pip install poetry -i https://mirrors.aliyun.com/pypi/simple/ + +WORKDIR /venv + +COPY poetry.lock pyproject.toml /venv/ + +RUN poetry config virtualenvs.options.no-pip true \ + && poetry config virtualenvs.options.no-setuptools true \ + && poetry config virtualenvs.in-project true \ + && poetry install + + +FROM python:3.11-alpine as release + +COPY --from=builder /venv /venv + +ENV PATH="/venv/.venv/bin:${PATH}" + +RUN chmod a+x /venv/.venv/bin/activate \ + && activate + +WORKDIR /app + +COPY . /app + +ENV FAST_API_ENV=prod + +CMD ["/usr/local/bin/uvicorn", "main:fast_api_app", "--reload", "--host", "0.0.0.0", "--port", "80"] \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index 26300fe..d3fb992 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "fastapi-template" -version = "0.1.3" +version = "0.1.4" description = "" authors = ["chenwj113 "] license = "MIT"