Skip to content

Commit 826305d

Browse files
committed
fix: web file and docker images
1 parent 33df7fb commit 826305d

File tree

9 files changed

+72
-18
lines changed

9 files changed

+72
-18
lines changed

Diff for: .github/workflows/docker-build.yml

+30-15
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,23 @@ on:
88
- main
99
- release-*
1010
tags:
11-
- 'v*.*.*' # 例如 v1.0.0, v2.1.3
12-
- 'v*.*.*-*' # 例如 v1.0.0-beta.1
11+
- 'v*.*.*'
12+
- 'v*.*.*-*'
1313
workflow_dispatch:
1414

1515
jobs:
1616
build-voiceflow:
1717
runs-on: ubuntu-latest
1818
steps:
19-
# 1. 检出代码
2019
- name: Checkout code
2120
uses: actions/checkout@v4
2221
with:
23-
fetch-depth: 0 # 确保获取所有标签
22+
fetch-depth: 0
2423

25-
# 2. 设置 Docker Buildx
2624
- name: Set up Docker Buildx
2725
uses: docker/[email protected]
2826

27+
# 改进的缓存配置
2928
- name: Cache Docker layers
3029
uses: actions/cache@v4
3130
with:
@@ -34,30 +33,35 @@ jobs:
3433
restore-keys: |
3534
${{ runner.os }}-buildx-
3635
37-
# 3. 登录 Docker Hub
36+
# 添加 Trivy 缓存
37+
- name: Cache Trivy vulnerability database
38+
uses: actions/cache@v4
39+
with:
40+
path: ~/.cache/trivy
41+
key: trivy-${{ github.sha }}
42+
restore-keys: |
43+
trivy-
44+
3845
- name: Log in to Docker Hub
3946
uses: docker/login-action@v3
4047
with:
4148
username: ${{ secrets.DOCKER_USERNAME }}
4249
password: ${{ secrets.DOCKER_PASSWORD }}
4350

44-
# 4. 登录阿里云容器注册表
4551
- name: Log in to AliYun Docker Hub
4652
uses: docker/login-action@v3
4753
with:
4854
registry: registry.cn-hangzhou.aliyuncs.com
4955
username: ${{ secrets.ALIREGISTRY_USERNAME }}
5056
password: ${{ secrets.ALIREGISTRY_TOKEN }}
5157

52-
# 5. 登录 GitHub Container Registry
5358
- name: Log in to GitHub Container Registry
5459
uses: docker/login-action@v3
5560
with:
5661
registry: ghcr.io
5762
username: ${{ github.repository_owner }}
5863
password: ${{ secrets.GITHUB_TOKEN }}
5964

60-
# 6. 获取 Docker Metadata
6165
- name: Get Docker metadata
6266
id: metadata
6367
uses: docker/[email protected]
@@ -77,7 +81,7 @@ jobs:
7781
type=semver,pattern={{major}}
7882
type=sha
7983
80-
# 7. 构建并推送 Docker 镜像
84+
# 改进的构建步骤
8185
- name: Build and push Docker image for voiceflow
8286
uses: docker/build-push-action@v5
8387
with:
@@ -88,19 +92,30 @@ jobs:
8892
tags: ${{ steps.metadata.outputs.tags }}
8993
labels: ${{ steps.metadata.outputs.labels }}
9094
cache-from: type=local,src=/tmp/.buildx-cache
91-
cache-to: type=local,dest=/tmp/.buildx-cache
95+
cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max
9296
build-args: |
9397
VERSION=${{ steps.metadata.outputs.version }}
9498
provenance: true
9599

96-
# 8. 可选:安全扫描(例如 Trivy)
100+
# 修改缓存路径
101+
- name: Move cache
102+
run: |
103+
rm -rf /tmp/.buildx-cache
104+
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
105+
106+
# 改进的 Trivy 扫描配置
97107
- name: Scan Docker image for vulnerabilities
98108
uses: aquasecurity/[email protected]
99109
with:
100-
image-ref: telepace/voiceflow:${{ steps.metadata.outputs.version }}
110+
image-ref: docker.io/telepace/voiceflow:${{ steps.metadata.outputs.version }}
101111
format: 'table'
102-
exit-code: '0'
112+
exit-code: '1'
113+
ignore-unfixed: true
114+
vuln-type: 'os,library'
115+
severity: 'CRITICAL,HIGH'
116+
timeout: '5m'
117+
cache-dir: ~/.cache/trivy
103118

104-
# 9. 清理未使用的 Docker 镜像
105119
- name: Clean up Docker
120+
if: always()
106121
run: docker system prune -f

Diff for: audio_files/.txt

Whitespace-only changes.

Diff for: audio_files/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# readme

Diff for: cmd/voiceflow/root.go

+41-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ package main
33

44
import (
55
"context"
6+
"embed"
67
"fmt"
78
"github.com/joho/godotenv"
89
"github.com/telepace/voiceflow/pkg/config"
10+
"io/fs"
911
"net/http"
1012
"os"
1113
"strings"
@@ -20,6 +22,41 @@ import (
2022

2123
var cfgFile string
2224

25+
//go:embed web/*
26+
var webFS embed.FS
27+
28+
// setupFileServers sets up the file servers for both embedded and local files
29+
func setupFileServers(mux *http.ServeMux) error {
30+
// Setup web content from embedded files
31+
webContent, err := fs.Sub(webFS, "web")
32+
if err != nil {
33+
return err
34+
}
35+
mux.Handle("/", http.FileServer(http.FS(webContent)))
36+
37+
// Setup audio files from local directory
38+
// This allows for dynamic audio file serving without embedding
39+
mux.Handle("/audio_files/", http.StripPrefix("/audio_files/",
40+
http.FileServer(http.Dir("audio_files"))))
41+
42+
return nil
43+
}
44+
45+
// ensureDirectories creates necessary directories if they don't exist
46+
func ensureDirectories() error {
47+
dirs := []string{
48+
"audio_files",
49+
}
50+
51+
for _, dir := range dirs {
52+
if err := os.MkdirAll(dir, 0755); err != nil {
53+
return fmt.Errorf("failed to create directory %s: %w", dir, err)
54+
}
55+
}
56+
57+
return nil
58+
}
59+
2360
var rootCmd = &cobra.Command{
2461
Use: "voiceflow",
2562
Short: "VoiceFlow is a voice processing server",
@@ -64,8 +101,9 @@ func run(cmd *cobra.Command, args []string) error {
64101

65102
// Set up HTTP server
66103
mux := http.NewServeMux()
67-
mux.Handle("/", http.FileServer(http.Dir("./web")))
68-
mux.Handle("/audio_files/", http.StripPrefix("/audio_files/", http.FileServer(http.Dir("./audio_files"))))
104+
if err := setupFileServers(mux); err != nil {
105+
return fmt.Errorf("failed to setup file servers: %w", err)
106+
}
69107

70108
// Initialize WebSocket server
71109
wsServer := serverpkg.NewServer()
@@ -147,7 +185,7 @@ func init() {
147185
func initConfig() {
148186
// 加载 .env 文件
149187
if err := godotenv.Load(); err != nil {
150-
logger.Fatal("No .env file found or failed to load, proceeding without it")
188+
logger.Warn("No .env file found or failed to load, proceeding without it")
151189
} else {
152190
logger.Info(".env file loaded")
153191
}

Diff for: web/OWNERS renamed to cmd/voiceflow/web/OWNERS

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)