diff --git a/.github/workflows/build-dev-image.yaml b/.github/workflows/build-dev-image.yaml new file mode 100644 index 0000000..bbf97eb --- /dev/null +++ b/.github/workflows/build-dev-image.yaml @@ -0,0 +1,23 @@ +name: Build Dev Image + +on: + push: + workflow_dispatch: + +jobs: + build-dev-image: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Generate Tag + run: | + # 获取分支名称,把/替换为- + echo ${{ github.ref }} | sed 's/\//-/g' + echo ::set-output name=tag::$(echo ${{ github.ref }} | sed 's/\//-/g') + - name: Login to Registry + run: docker login --username=${{ secrets.DOCKER_USERNAME }} --password ${{ secrets.DOCKER_PASSWORD }} + - name: Build Docker Image + run: | + docker buildx create --name mybuilder --use + docker build -t rockchin/langbot:${{ steps.generate-tag.outputs.tag }} . --push diff --git a/.github/workflows/build-docker-image.yml b/.github/workflows/build-docker-image.yml index c877667..96841c4 100644 --- a/.github/workflows/build-docker-image.yml +++ b/.github/workflows/build-docker-image.yml @@ -19,12 +19,6 @@ jobs: export GITHUB_REF=${{ github.ref }} echo $GITHUB_REF fi - # - name: Check GITHUB_REF env - # run: echo $GITHUB_REF - # - name: Get version # 在 GitHub Actions 运行环境 - # id: get_version - # if: (startsWith(env.GITHUB_REF, 'refs/tags/')||startsWith(github.ref, 'refs/tags/')) && startsWith(github.repository, 'RockChinQ/QChatGPT') - # run: export GITHUB_REF=${GITHUB_REF/refs\/tags\//} - name: Check version id: check_version run: | diff --git a/Dockerfile b/Dockerfile index 89f0950..428ad14 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,8 +1,19 @@ +FROM node:22-alpine AS node + +WORKDIR /app + +COPY web ./web + +RUN cd web && npm install && npm run build + FROM python:3.10.13-slim + WORKDIR /app COPY . . +COPY --from=node /app/web/dist ./web/dist + RUN apt update \ && apt install gcc -y \ && python -m pip install -r requirements.txt \ diff --git a/pkg/api/http/controller/main.py b/pkg/api/http/controller/main.py index 35ac761..d91f9af 100644 --- a/pkg/api/http/controller/main.py +++ b/pkg/api/http/controller/main.py @@ -1,6 +1,7 @@ from __future__ import annotations import asyncio +import os import quart import quart_cors @@ -49,3 +50,13 @@ class HTTPController: for g in group.preregistered_groups: ginst = g(self.ap, self.quart_app) await ginst.initialize() + + frontend_path = "web/dist" + + @self.quart_app.route("/") + async def index(): + return await quart.send_from_directory(frontend_path, "index.html") + + @self.quart_app.route("/") + async def static_file(path: str): + return await quart.send_from_directory(frontend_path, path)