diff --git a/.github/workflows/build-latest-image.yaml b/.github/workflows/build-latest-image.yaml new file mode 100644 index 0000000..3938d12 --- /dev/null +++ b/.github/workflows/build-latest-image.yaml @@ -0,0 +1,55 @@ +name: Release Docker Image + +on: + push: + branches: + - main + paths: + - 'Dockerfile' + - 'docker-compose.yml' + - 'src/**' + - '.github/workflows/build-latest-image.yaml' + - 'main.py' + workflow_dispatch: + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Log in to the Container registry + uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + + - name: Build and push Docker image + uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4 + with: + context: . + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + + - name: Push Finish Notification + run: | + curl --location '${{ secrets.ONEBOT_V11_ENDPOINT }}/send_group_msg' \ + --header 'Content-Type: application/json' \ + --header 'Authorization: Bearer ${{ secrets.ONEBOT_V11_TOKEN }}' \ + --data '{ + "group_id": ${{ secrets.ONEBOT_V11_GROUP_ID }}, + "message": "CampuxUtility 构建完成。" + }' \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..5d3de8f --- /dev/null +++ b/Dockerfile @@ -0,0 +1,9 @@ +FROM python:3.10-slim + +WORKDIR /app + +COPY . . + +RUN pip install --no-cache-dir -r requirements.txt + +CMD ["python", "main.py"] \ No newline at end of file diff --git a/main.py b/main.py new file mode 100644 index 0000000..8ffc8fb --- /dev/null +++ b/main.py @@ -0,0 +1,8 @@ +import os + +if __name__ == "__main__": + import uvicorn + + port = os.getenv("PORT", 8999) + + uvicorn.run("src.api:app", host="0.0.0.0", port=port) diff --git a/src/api.py b/src/api.py index 217c0de..f3bc5a8 100644 --- a/src/api.py +++ b/src/api.py @@ -1,5 +1,5 @@ import fastapi, os -from render import Text2ImgRender, ScreenshotOptions +from .render import Text2ImgRender, ScreenshotOptions from dataclasses import dataclass app = fastapi.FastAPI() diff --git a/src/render.py b/src/render.py index 3dd3946..37a1ce8 100644 --- a/src/render.py +++ b/src/render.py @@ -1,6 +1,6 @@ import logging, os, time -from util import generate_data_path +from .util import generate_data_path from pathlib import Path from playwright.async_api import async_playwright from jinja2 import Template