-
Notifications
You must be signed in to change notification settings - Fork 228
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #340 from LlmKira/github-bot
Pydantic 2.0 / Fix Bug
- Loading branch information
Showing
56 changed files
with
748 additions
and
651 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 |
---|---|---|
@@ -1,25 +1,37 @@ | ||
FROM python:3.10-slim AS builder | ||
# 第一个阶段 | ||
FROM python:3.11-buster as builder | ||
|
||
RUN apt update && \ | ||
apt install build-essential -y | ||
RUN apt update && apt install -y build-essential \ | ||
&& pip install poetry==1.6.1 | ||
|
||
ENV POETRY_NO_INTERACTION=1 \ | ||
POETRY_VIRTUALENVS_IN_PROJECT=1 \ | ||
POETRY_VIRTUALENVS_CREATE=1 \ | ||
POETRY_CACHE_DIR=/tmp/poetry_cache | ||
|
||
COPY ./requirements.txt . | ||
COPY pm2.json . | ||
COPY start.sh . | ||
# 将 config_dir 的设置文件映射到宿主机 | ||
COPY ./config_dir /config_dir | ||
WORKDIR /app | ||
|
||
COPY poetry.lock pyproject.toml ./ | ||
VOLUME ["/redis", "/rabbitmq", "/mongodb", "run.log", "/config_dir"] | ||
|
||
RUN pip install --upgrade --no-cache-dir pip && pip install --no-cache-dir -r requirements.txt | ||
RUN poetry config virtualenvs.in-project true && \ | ||
poetry install --without dev --no-root && rm -rf $POETRY_CACHE_DIR | ||
|
||
FROM python:3.10-slim | ||
RUN apt-get update && \ | ||
# 第二个阶段 | ||
FROM python:3.11-slim-buster as runtime | ||
|
||
RUN apt update && \ | ||
apt install -y npm && \ | ||
npm install pm2 -g | ||
|
||
ENV WORKDIR /app | ||
WORKDIR $WORKDIR | ||
ADD . $WORKDIR | ||
COPY --from=builder /usr/local/lib/python3.10/site-packages /usr/local/lib/python3.10/site-packages | ||
ENV VIRTUAL_ENV=/app/.venv \ | ||
PATH="/app/.venv/bin:$PATH" | ||
|
||
WORKDIR /app | ||
|
||
COPY --from=builder /app/.venv /app/.venv | ||
|
||
COPY pm2.json ./ | ||
COPY config_dir ./config_dir | ||
|
||
CMD [ "pm2-runtime", "pm2.json" ] |
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
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
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
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
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
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,23 @@ | ||
# -*- coding: utf-8 -*- | ||
# @Time : 2023/11/12 下午9:12 | ||
# @Author : sudoskys | ||
# @File : pydantic_feat.py | ||
# @Software: PyCharm | ||
from pydantic import field_validator, BaseModel, ValidationError | ||
|
||
|
||
class UserModel(BaseModel): | ||
id: int | ||
name: str | ||
|
||
@field_validator('name') | ||
def name_must_contain_space(cls, v: str) -> str: | ||
if ' ' not in v: | ||
raise ValueError('must contain a space') | ||
return v.title() | ||
|
||
|
||
try: | ||
UserModel(id=0, name='JohnDoe') | ||
except ValidationError as e: | ||
print(e) |
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
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
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
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
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
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
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
Oops, something went wrong.