Skip to content

Commit

Permalink
ci: 构建
Browse files Browse the repository at this point in the history
  • Loading branch information
RockChinQ committed Apr 28, 2024
1 parent dccdb15 commit 7d09afa
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 2 deletions.
55 changes: 55 additions & 0 deletions .github/workflows/build-latest-image.yaml
Original file line number Diff line number Diff line change
@@ -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 构建完成。"
}'
9 changes: 9 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
8 changes: 8 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
@@ -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)
2 changes: 1 addition & 1 deletion src/api.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import fastapi, os
from render import Text2ImgRender, ScreenshotOptions
from .render import Text2ImgRender, ScreenshotOptions
from dataclasses import dataclass

app = fastapi.FastAPI()
Expand Down
2 changes: 1 addition & 1 deletion src/render.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 7d09afa

Please sign in to comment.