Skip to content
Closed
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
152 changes: 78 additions & 74 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
@@ -1,77 +1,81 @@
name: Build and Push Docker Image

on:
push:
branches:
- main
tags:
- 'v*'
pull_request:
branches:
- main
workflow_dispatch:

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
build-and-push:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- variant: standard
dockerfile: Dockerfile
image_suffix: ""
cache_scope: standard
- variant: headed
dockerfile: Dockerfile.headed
image_suffix: -headed
cache_scope: headed
permissions:
contents: read
packages: write

steps:
- name: Checkout repository
uses: actions/checkout@v4

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

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Log in to Container Registry
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels)
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}${{ matrix.image_suffix }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=raw,value=latest,enable={{is_default_branch}}

- name: Build and push Docker image (${{ matrix.variant }})
uses: docker/build-push-action@v5
with:
context: .
file: ${{ matrix.dockerfile }}
platforms: linux/amd64,linux/arm64
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha,scope=${{ matrix.cache_scope }}
cache-to: type=gha,mode=max,scope=${{ matrix.cache_scope }}
- "a-branch-that-will-never-exist-999"
#name: Build and Push Docker Image
#
#on:
# push:
# branches:
# - main
# tags:
# - "v*"
# pull_request:
# branches:
# - main
# workflow_dispatch:
#
#env:
# REGISTRY: ghcr.io
# IMAGE_NAME: ${{ github.repository }}
#
#jobs:
# build-and-push:
# runs-on: ubuntu-latest
# strategy:
# fail-fast: false
# matrix:
# include:
# - variant: standard
# dockerfile: Dockerfile
# image_suffix: ""
# cache_scope: standard
# - variant: headed
# dockerfile: Dockerfile.headed
# image_suffix: -headed
# cache_scope: headed
# permissions:
# contents: read
# packages: write
#
# steps:
# - name: Checkout repository
# uses: actions/checkout@v4
#
# - name: Set up QEMU
# uses: docker/setup-qemu-action@v3
#
# - name: Set up Docker Buildx
# uses: docker/setup-buildx-action@v3
#
# - name: Log in to Container Registry
# if: github.event_name != 'pull_request'
# uses: docker/login-action@v3
# with:
# registry: ${{ env.REGISTRY }}
# username: ${{ github.actor }}
# password: ${{ secrets.GITHUB_TOKEN }}
#
# - name: Extract metadata (tags, labels)
# id: meta
# uses: docker/metadata-action@v5
# with:
# images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}${{ matrix.image_suffix }}
# tags: |
# type=ref,event=branch
# type=ref,event=pr
# type=semver,pattern={{version}}
# type=semver,pattern={{major}}.{{minor}}
# type=raw,value=latest,enable={{is_default_branch}}
#
# - name: Build and push Docker image (${{ matrix.variant }})
# uses: docker/build-push-action@v5
# with:
# context: .
# file: ${{ matrix.dockerfile }}
# platforms: linux/amd64,linux/arm64
# push: ${{ github.event_name != 'pull_request' }}
# tags: ${{ steps.meta.outputs.tags }}
# labels: ${{ steps.meta.outputs.labels }}
# cache-from: type=gha,scope=${{ matrix.cache_scope }}
# cache-to: type=gha,mode=max,scope=${{ matrix.cache_scope }}
146 changes: 146 additions & 0 deletions .github/workflows/production-docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
name: Build & Push
on:
push:
branches:
- main

env:
REGISTRY: ghcr.io
USER_NAME: btcfoxman
IMAGE_NAME: flow2api

jobs:
build-and-push:
runs-on: ubuntu-latest
environment: SSH-JP
env:
ALI_ENABLE: ${{ vars.ALI_ENABLE != '' && vars.ALI_ENABLE || 'true' }}
permissions:
contents: read
packages: write

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Print ALI_ENABLE context
run: |
echo "environment=SSH-JP"
echo "vars.ALI_ENABLE=${{ vars.ALI_ENABLE }}"
echo "env.ALI_ENABLE=${{ env.ALI_ENABLE }}"

- name: Log in to GHCR
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract version from src/main.py
id: version
run: |
python - <<'PY'
import os
import re
from pathlib import Path

data = Path('src/main.py').read_text(encoding='utf-8')
m = re.search(r'version\s*=\s*["\']([^"\']+)["\']', data)
if not m:
raise SystemExit('version not found in src/main.py')
version = m.group(1)
output = os.environ.get("GITHUB_OUTPUT")
if output:
with open(output, "a", encoding="utf-8") as fh:
fh.write(f"version={version}\n")
print(f"version={version}")
PY

- name: Build tag list
id: tags
run: |
GHCR_BASE="${{ env.REGISTRY }}/${{ env.USER_NAME }}/${{ env.IMAGE_NAME }}"
ALI_BASE="registry.cn-shenzhen.aliyuncs.com/epur/${{ env.IMAGE_NAME }}"
VERSION="v${{ steps.version.outputs.version }}"

{
echo "value<<EOF"
echo "${GHCR_BASE}:${VERSION}"
echo "${GHCR_BASE}:latest"
if [ "${{ env.ALI_ENABLE }}" = "true" ]; then
echo "${ALI_BASE}:${VERSION}"
echo "${ALI_BASE}:latest"
fi
echo "EOF"
} >> "$GITHUB_OUTPUT"

- name: Login to Aliyun ACR
if: env.ALI_ENABLE == 'true'
uses: docker/login-action@v2
with:
registry: registry.cn-shenzhen.aliyuncs.com
username: ${{ secrets.ALI_USERNAME }}
password: ${{ secrets.ALI_PASSWORD }}

- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: .
file: ./Dockerfile
push: true
tags: ${{ steps.tags.outputs.value }}
platforms: linux/amd64,linux/arm64
cache-from: type=gha
cache-to: type=gha,mode=max

- name: Deploy via SSH
uses: appleboy/ssh-action@v1.0.3
env:
DEPLOY_PATH: ${{ secrets.DEPLOY_PATH }}
GHCR_TOKEN: ${{ secrets.GHCR_TOKEN }}
GHCR_USERNAME: ${{ secrets.GHCR_USERNAME }}
DEPLOY_SERVICE: ${{ secrets.DEPLOY_SERVICE }}
ALI_ENABLE: ${{ env.ALI_ENABLE }}
ALI_USERNAME: ${{ secrets.ALI_USERNAME }}
ALI_PASSWORD: ${{ secrets.ALI_PASSWORD }}
with:
host: ${{ secrets.DEPLOY_HOST }}
username: ${{ secrets.DEPLOY_USER }}
key: ${{ secrets.DEPLOY_SSH_KEY }}
port: ${{ secrets.DEPLOY_PORT }}
timeout: 60s
command_timeout: 20m
envs: DEPLOY_PATH,GHCR_TOKEN,GHCR_USERNAME,DEPLOY_SERVICE,ALI_ENABLE,ALI_USERNAME,ALI_PASSWORD
script: |
set -e
cd "$DEPLOY_PATH"

if [ "$ALI_ENABLE" = "true" ]; then
echo "$ALI_PASSWORD" | docker login registry.cn-shenzhen.aliyuncs.com -u "$ALI_USERNAME" --password-stdin
IMAGE_REGISTRY="registry.cn-shenzhen.aliyuncs.com"
IMAGE_NAMESPACE="epur"
else
echo "$GHCR_TOKEN" | docker login ghcr.io -u "$GHCR_USERNAME" --password-stdin
IMAGE_REGISTRY="ghcr.io"
IMAGE_NAMESPACE="btcfoxman"
fi

touch .env
if grep -q '^IMAGE_REGISTRY=' .env; then
sed -i "s|^IMAGE_REGISTRY=.*|IMAGE_REGISTRY=${IMAGE_REGISTRY}|" .env
else
echo "IMAGE_REGISTRY=${IMAGE_REGISTRY}" >> .env
fi

if grep -q '^IMAGE_NAMESPACE=' .env; then
sed -i "s|^IMAGE_NAMESPACE=.*|IMAGE_NAMESPACE=${IMAGE_NAMESPACE}|" .env
else
echo "IMAGE_NAMESPACE=${IMAGE_NAMESPACE}" >> .env
fi

docker network inspect my-shared-net >/dev/null 2>&1 || docker network create my-shared-net
docker compose pull "$DEPLOY_SERVICE"
docker compose up -d "$DEPLOY_SERVICE"
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,4 @@ tmp/
config/setting.toml
config/setting_warp.toml
config/setting_warp_example.toml

2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ RUN pip install --no-cache-dir --root-user-action=ignore -r requirements.txt

COPY . .

EXPOSE 8000
EXPOSE 4020

CMD ["python", "main.py"]
2 changes: 1 addition & 1 deletion Dockerfile.headed
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ COPY . .
COPY docker/entrypoint.headed.sh /usr/local/bin/entrypoint.headed.sh
RUN chmod +x /usr/local/bin/entrypoint.headed.sh

EXPOSE 8000
EXPOSE 4020

CMD ["/usr/local/bin/entrypoint.headed.sh"]
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ python main.py

### 首次访问

服务启动后,访问管理后台: **http://localhost:8000**,首次登录后请立即修改密码!
服务启动后,访问管理后台: **http://localhost:4020**,首次登录后请立即修改密码!

- **用户名**: `admin`
- **密码**: `admin`
Expand Down Expand Up @@ -302,7 +302,7 @@ curl -X POST "http://localhost:8000/models/gemini-3.1-flash-image:generateConten
### 文生图

```bash
curl -X POST "http://localhost:8000/v1/chat/completions" \
curl -X POST "http://localhost:4020/v1/chat/completions" \
-H "Authorization: Bearer han1234" \
-H "Content-Type: application/json" \
-d '{
Expand All @@ -320,7 +320,7 @@ curl -X POST "http://localhost:8000/v1/chat/completions" \
### 图生图

```bash
curl -X POST "http://localhost:8000/v1/chat/completions" \
curl -X POST "http://localhost:4020/v1/chat/completions" \
-H "Authorization: Bearer han1234" \
-H "Content-Type: application/json" \
-d '{
Expand Down Expand Up @@ -349,7 +349,7 @@ curl -X POST "http://localhost:8000/v1/chat/completions" \
### 文生视频

```bash
curl -X POST "http://localhost:8000/v1/chat/completions" \
curl -X POST "http://localhost:4020/v1/chat/completions" \
-H "Authorization: Bearer han1234" \
-H "Content-Type: application/json" \
-d '{
Expand All @@ -367,7 +367,7 @@ curl -X POST "http://localhost:8000/v1/chat/completions" \
### 首尾帧生成视频

```bash
curl -X POST "http://localhost:8000/v1/chat/completions" \
curl -X POST "http://localhost:4020/v1/chat/completions" \
-H "Authorization: Bearer han1234" \
-H "Content-Type: application/json" \
-d '{
Expand Down
2 changes: 1 addition & 1 deletion config/setting.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ max_poll_attempts = 200

[server]
host = "0.0.0.0"
port = 8000
port = 4020

[debug]
enabled = false
Expand Down
2 changes: 1 addition & 1 deletion config/setting_example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ max_poll_attempts = 200

[server]
host = "0.0.0.0"
port = 8000
port = 4020

[debug]
enabled = false
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.headed.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ services:
image: flow2api:headed
container_name: flow2api-headed
ports:
- "8000:8000"
- "4020:4020"
volumes:
- ./data:/app/data
- ./tmp:/app/tmp
Expand Down
Loading