Skip to content

Commit

Permalink
♻️ 迁移到 uv 并重写 Dockerfile (#667)
Browse files Browse the repository at this point in the history
Co-authored-by: BalconyJH <[email protected]>
Co-authored-by: suyiiyii <[email protected]>
  • Loading branch information
3 people authored Jan 3, 2025
1 parent eb2eae6 commit f35c6c2
Show file tree
Hide file tree
Showing 25 changed files with 3,793 additions and 5,405 deletions.
8 changes: 3 additions & 5 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
"name": "Default Linux Universal",
"image": "mcr.microsoft.com/devcontainers/universal:2-linux",
"features": {
"ghcr.io/devcontainers-contrib/features/poetry:2": {}
"ghcr.io/va-h/devcontainers-features/uv:1": {}
},
"postCreateCommand": "poetry config virtualenvs.in-project true && poetry install -E all && poetry run pre-commit install && npm install -g pnpm && pnpm install",
"postCreateCommand": "uv venv && uv sync --all-groups --all-extras && uv run pre-commit install && npm install -g pnpm && pnpm install",
"customizations": {
"vscode": {
"settings": {
"python.analysis.diagnosticMode": "workspace",
"python.analysis.typeCheckingMode": "basic",
"ruff.organizeImports": false,
"[python]": {
"editor.defaultFormatter": "ms-python.black-formatter",
"editor.defaultFormatter": "charliermarsh.ruff",
"editor.codeActionsOnSave": {
"source.fixAll.ruff": true,
"source.organizeImports": true
Expand Down Expand Up @@ -44,8 +44,6 @@
"extensions": [
"ms-python.python",
"ms-python.vscode-pylance",
"ms-python.isort",
"ms-python.black-formatter",
"charliermarsh.ruff",
"EditorConfig.EditorConfig",
"esbenp.prettier-vscode",
Expand Down
17 changes: 11 additions & 6 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
*.ini
*.yaml
*.yml
*.md
*.json
*.toml
*.xml
tests
node_modules
admin-frontend
data*
htmlcov
docker
dist
docs
.*
venv
.venv
/admin-frontend/node_modules
/LICENSE
/.editorconfig
/.gitattributes
/.prettierignore
/.prettierrc
/.devcontainer/
/.github/

!pyproject.toml
# self install 时需要
!README.md
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/issue.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ body:
description: 请选择安装方式
options:
- 通过 nb-cli 安装
- 使用 poetry/pdm 等现代包管理器安装
- 使用 uv/poetry/pdm 等现代包管理器安装
- 通过 pip install 安装
- 克隆或下载项目直接使用

Expand Down
26 changes: 23 additions & 3 deletions .github/actions/setup-python/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ inputs:
description: Python version
required: false
default: "3.10"
install-deps:
description: Install dependencies
required: false
default: "false"
install-playwright:
description: Install Playwright
required: false
default: "false"

runs:
using: "composite"
Expand All @@ -14,7 +22,19 @@ runs:
uses: actions/setup-python@v5
with:
python-version: ${{ inputs.python-version }}
- name: Setup Poetry
uses: Gr1N/setup-poetry@v9

- name: Install the latest version of uv
uses: astral-sh/setup-uv@v4
with:
poetry-version: "1.7.1"
version: "latest"
enable-cache: true

- name: Install dependencies
if: ${{ inputs.install-deps == 'true' }}
run: uv sync --frozen
shell: bash

- name: Install Playwright
if: ${{ inputs.install-playwright == 'true' }}
run: uv run playwright install
shell: bash
42 changes: 14 additions & 28 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ on:
- nonebot_bison/**
- tests/**
- pyproject.toml
- poetry.lock
- uv.lock
- docker.env.prod
- .github/**
pull_request:
Expand All @@ -21,7 +21,7 @@ on:
- nonebot_bison/**
- tests/**
- pyproject.toml
- poetry.lock
- uv.lock
- docker.env.prod
- .github/**
types:
Expand Down Expand Up @@ -72,12 +72,11 @@ jobs:
uses: ./.github/actions/setup-python
with:
python-version: ${{ matrix.python-version }}

- name: Install prerequisites
run: poetry install
install-deps: "true"
install-playwright: "true"

- name: Run Pytest
run: poetry run pytest --cov-report xml --cov=./nonebot_bison -k 'not compare and not render' -n auto
run: uv run pytest --cov-report xml --cov=./nonebot_bison -k 'not compare and not render' -n auto

- name: Upload coverage report
uses: codecov/codecov-action@v5
Expand Down Expand Up @@ -106,12 +105,11 @@ jobs:
uses: ./.github/actions/setup-python
with:
python-version: ${{ matrix.python-version }}

- name: Install prerequisites
run: poetry install
install-deps: "true"
install-playwright: "true"

- name: Run Pytest
run: poetry run pytest --cov-report xml --cov=./nonebot_bison -k 'not compare' -n auto
run: uv run pytest --cov-report xml --cov=./nonebot_bison -k 'not compare' -n auto

- name: Upload coverage report
uses: codecov/codecov-action@v5
Expand All @@ -127,12 +125,6 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Download frontend files
uses: actions/download-artifact@v4
with:
name: frontend
path: ./nonebot_bison/admin_page/dist

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

Expand All @@ -144,7 +136,7 @@ jobs:
if: github.event_name == 'pull_request'
with:
context: .
file: ./docker/Dockerfile_with_frontend
file: ./docker/Dockerfile
push: false
load: true
tags: felinae98/nonebot-bison:dummy
Expand Down Expand Up @@ -174,26 +166,20 @@ jobs:
if: github.event_name != 'pull_request'
with:
context: .
file: ./docker/Dockerfile_with_frontend
file: ./docker/Dockerfile
push: true
tags: felinae98/nonebot-bison:${{ env.GIT_BRANCH_NAME }}
cache-from: type=gha
cache-to: type=gha,mode=max

docker-main-sentry:
name: Docker main sentry
docker-main-nobrowser:
name: Docker main without browser
runs-on: ubuntu-latest
needs: [build-frontend, test]
if: github.event_name != 'pull_request'
steps:
- uses: actions/checkout@v4

- name: Download frontend files
uses: actions/download-artifact@v4
with:
name: frontend
path: ./nonebot_bison/admin_page/dist

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

Expand All @@ -215,8 +201,8 @@ jobs:
uses: docker/build-push-action@v6
with:
context: .
file: ./docker/Dockerfile_with_frontend_sentry
file: ./docker/Dockerfile_without_browser
push: ${{ github.event_name != 'pull_request' }}
tags: felinae98/nonebot-bison:${{ env.GIT_BRANCH_NAME }}-sentry
tags: felinae98/nonebot-bison:${{ env.GIT_BRANCH_NAME }}-nobrowser
cache-from: type=gha
cache-to: type=gha,mode=max
40 changes: 5 additions & 35 deletions .github/workflows/manual-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,35 +9,12 @@ on:
type: string

jobs:
build-frontend:
name: Build Frontend
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Build Frontend
uses: ./.github/actions/build-frontend

- name: Upload dist
uses: actions/upload-artifact@v4
with:
name: frontend
path: ./admin-frontend/build/

docker-main:
name: Docker main
runs-on: ubuntu-latest
needs: [build-frontend]
steps:
- uses: actions/checkout@v4

- name: Download frontend files
uses: actions/download-artifact@v4
with:
name: frontend
path: ./src/plugins/nonebot_bison/admin_page/dist

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

Expand All @@ -54,25 +31,18 @@ jobs:
uses: docker/build-push-action@v6
with:
context: .
file: ./docker/Dockerfile_with_frontend
file: ./docker/Dockerfile
push: true
tags: felinae98/nonebot-bison:${{ inputs.dockerTag }}
cache-from: type=gha
cache-to: type=gha,mode=max

docker-main-sentry:
name: Docker main sentry
docker-main-nobrowser:
name: Docker main without browser
runs-on: ubuntu-latest
needs: [build-frontend]
steps:
- uses: actions/checkout@v4

- name: Download frontend files
uses: actions/download-artifact@v4
with:
name: frontend
path: ./src/plugins/nonebot_bison/admin_page/dist

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

Expand All @@ -89,7 +59,7 @@ jobs:
uses: docker/build-push-action@v6
with:
context: .
file: ./docker/Dockerfile_with_frontend_sentry
tags: felinae98/nonebot-bison:${{ inputs.dockerTag }}-sentry
file: ./docker/Dockerfile_without_browser
tags: felinae98/nonebot-bison:${{ inputs.dockerTag }}-nobrowser
cache-from: type=gha
cache-to: type=gha,mode=max
8 changes: 4 additions & 4 deletions .github/workflows/pyd1-compat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ on:
- nonebot_bison/**
- tests/**
- pyproject.toml
- poetry.lock
- uv.lock
- docker.env.prod
- .github/**
pull_request:
Expand All @@ -21,7 +21,7 @@ on:
- nonebot_bison/**
- tests/**
- pyproject.toml
- poetry.lock
- uv.lock
- docker.env.prod
- .github/**
types:
Expand Down Expand Up @@ -55,7 +55,7 @@ jobs:
python-version: ${{ matrix.python-version }}

- name: Install prerequisites
run: poetry add pydantic@^1.10 && poetry install
run: uv add pydantic==1.10 && uv sync --frozen && uv run playwright install

- name: Run Pytest
run: poetry run pytest -k 'not compare and not render' -n auto
run: uv run pytest -k 'not compare and not render' -n auto
4 changes: 2 additions & 2 deletions .github/workflows/release-trigger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: Setup Python environment
uses: ./.github/actions/setup-python

- run: echo "TAG_NAME=v$(poetry version -s)" >> $GITHUB_ENV
- run: echo "TAG_NAME=v$(uvx --from=toml-cli toml get --toml-path=pyproject.toml project.version)" >> $GITHUB_ENV

- name: Archive Changelog
uses: docker://ghcr.io/nonebot/auto-changelog:master
Expand All @@ -30,6 +30,6 @@ jobs:
git config user.name github-actions[bot]
git config user.email github-actions[bot]@users.noreply.github.com
git add .
git commit -m ":bookmark: Release $(poetry version -s)"
git commit -m ":bookmark: Release ${{ env.TAG_NAME }}"
git tag ${{ env.TAG_NAME }}
git push && git push --tags
17 changes: 5 additions & 12 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,24 +54,17 @@ jobs:

- name: Publish PyPI and Github
run: |
poetry publish --build -u ${{ secrets.PYPI_USERNAME }} -p ${{ secrets.PYPI_PASSWORD }} || echo "Already pushed to pypi"
uv publish --build -u ${{ secrets.PYPI_USERNAME }} -p ${{ secrets.PYPI_PASSWORD }} || echo "Already pushed to pypi"
gh release upload --clobber ${{ env.TAG_NAME }} dist/*
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

publish-docker:
runs-on: ubuntu-latest
needs: build-frontend

steps:
- uses: actions/checkout@v4

- name: Download frontend files
uses: actions/download-artifact@v4
with:
name: frontend
path: ./nonebot_bison/admin_page/dist

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

Expand All @@ -92,7 +85,7 @@ jobs:
uses: docker/build-push-action@v6
with:
context: .
file: ./docker/Dockerfile_with_frontend
file: ./docker/Dockerfile
push: true
tags: |
felinae98/nonebot-bison:latest
Expand All @@ -104,10 +97,10 @@ jobs:
uses: docker/build-push-action@v6
with:
context: .
file: ./docker/Dockerfile_with_frontend_sentry
file: ./docker/Dockerfile_without_browser
push: true
tags: |
felinae98/nonebot-bison:${{ env.TAG_NAME }}-sentry
felinae98/nonebot-bison:sentry
felinae98/nonebot-bison:${{ env.TAG_NAME }}-nobrowser
felinae98/nonebot-bison:nobrowser
cache-from: type=gha
cache-to: type=gha,mode=max
Loading

0 comments on commit f35c6c2

Please sign in to comment.