fix: 运行时环境替换为alpine
Gitea Action for docker build / build-app (push) Successful in 1m23s Details
Gitea Action for docker build runtime / build-runtime (push) Successful in 4m18s Details

This commit is contained in:
chenwj113 2024-08-16 18:37:51 +08:00
parent 61f91fa932
commit 6d69a18b03
4 changed files with 34 additions and 4 deletions

View File

@ -5,7 +5,7 @@ on:
branches: [master]
paths-ignore:
- 'requirements.txt'
- 'RuntimeDockerfile'
- '*RuntimeDockerfile'
- '.gitignore'
- 'README.md'
- '.gitea/workflows/**'

View File

@ -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 }}."

30
AlpineRuntimeDockerfile Normal file
View File

@ -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"]

View File

@ -1,6 +1,6 @@
[tool.poetry]
name = "fastapi-template"
version = "0.1.3"
version = "0.1.4"
description = ""
authors = ["chenwj113 <chenwj113@gmail.com>"]
license = "MIT"