Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

通过分阶段打包减少Docker Image的空间占用并处理statically的域名更改 #95

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ATRI/plugins/manage/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
_NONEBOT_STORE_URLS = [
"https://registry.nonebot.dev/plugins.json",
"https://jsd.imki.moe/gh/nonebot/registry@results/plugins.json",
"https://cdn.staticaly.com/gh/nonebot/registry@results/plugins.json",
"https://cdn.statically.io/gh/nonebot/registry@results/plugins.json",
"https://jsd.cdn.zzko.cn/gh/nonebot/registry@results/plugins.json",
"https://ghproxy.com/https://raw.githubusercontent.com/nonebot/registry/results/plugins.json",
]
Expand Down
46 changes: 28 additions & 18 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,23 +1,33 @@
FROM flyingjoe/uvicorn-gunicorn-fastapi:python3.9-slim

WORKDIR /app

ENV PATH="${PATH}:/root/.local/bin"

ADD . /app/

EXPOSE 20000

RUN sed -i "s@http://deb.debian.org@http://mirrors.aliyun.com@g" /etc/apt/sources.list && rm -Rf /var/lib/apt/lists/* && apt-get update

RUN apt install curl -y

RUN curl -sSL https://install.python-poetry.org | python3 -

RUN /usr/local/bin/python -m pip install --no-cache-dir --upgrade --quiet pip

FROM sunpeek/poetry:py3.10-slim as base
# python
ENV PYTHONUNBUFFERED=1 \
# prevents python creating .pyc files
PYTHONDONTWRITEBYTECODE=1 \
\
POETRY_VERSION=1.1.4 \
# make poetry install to this location
POETRY_HOME="/opt/poetry" \
POETRY_VIRTUALENVS_IN_PROJECT=true \
POETRY_NO_INTERACTION=1 \
\
# paths
# this is where our requirements + virtual environment will live
PYSETUP_PATH="/opt/pysetup" \
VENV_PATH="/opt/pysetup/.venv"

# prepend poetry and venv to path
ENV PATH="$POETRY_HOME/bin:$VENV_PATH/bin:$PATH"

FROM base as base-builder
WORKDIR $PYSETUP_PATH
ADD ./poetry.lock ./pyproject.toml ./
RUN poetry install

FROM base as pre-production
EXPOSE 20000
COPY --from=base-builder $VENV_PATH /app/.venv/
COPY . /app/
VOLUME /app/accounts /app/data
WORKDIR /app

CMD poetry run python3 main.py
14 changes: 9 additions & 5 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
version: "3"
services:
nonebot:
nonebot_atri:
build: .
container_name: nonebot # 容器名称
container_name: atri # 容器名称
ports:
- "20000:20000" # 映射端口到宿主机 宿主机端口:容器端口
- "20000:20000" # 映射端口到宿主机 宿主机端口:容器端口
network_mode: bridge
restart: unless-stopped
stdin_open: true # docker run -i
tty: true # docker run -t
dns:
- 223.5.5.5
- 119.29.29.29
volumes:
- ~/.ATRI/data:/app/data # 这几条为挂载ATRI的工作数据目录与配置文件
- ~/.ATRI/accounts:/app/accounts # 挂载格式为 宿主机路径:容器路径
- ~/.ATRI/config.yml:/app/config.yml # 默认的工作路径为 ~/.ATRI 注意该目录默认状态下是隐藏的
- ~/.ATRI/accounts:/app/accounts # 挂载格式为 宿主机路径:容器路径
Loading