Skip to content

Formerly KrillinAI, VideoTranslation and Dubbing Tool for 120+ Languages. Open-source AI workspace for creators, powered by Codex. Video downloader, video translation, create videos, images, audios, and edits with Agents in one place. For your Social Media like YouTube, TikTok, Instagram, etc.

feat: support docker deployment

PairZhu8447a5168eca
diff --git a/Dockerfile b/Dockerfile
index 75bd1fae..db795b58 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,13 +1,39 @@
+FROM alpine:latest as builder
+
+# 安装基础工具并创建目录
+WORKDIR /build
+RUN apk add --no-cache wget unzip && \
+ mkdir -p bin
+
+# 下载并安装所有依赖
+RUN wget -O bin/ffmpeg.zip https://modelscope.cn/models/Maranello/KrillinAI_dependency_cn/resolve/master/ffmpeg-6.1-linux-64.zip && \
+ unzip bin/ffmpeg.zip -d bin && \
+ rm bin/ffmpeg.zip && \
+ chmod +x bin/ffmpeg && \
+ wget -O bin/ffprobe.zip https://modelscope.cn/models/Maranello/KrillinAI_dependency_cn/resolve/master/ffprobe-6.1-linux-64.zip && \
+ unzip bin/ffprobe.zip -d bin && \
+ rm bin/ffprobe.zip && \
+ chmod +x bin/ffprobe && \
+ wget -O bin/yt-dlp https://modelscope.cn/models/Maranello/KrillinAI_dependency_cn/resolve/master/yt-dlp_linux && \
+ chmod +x bin/yt-dlp
+
+# 最终镜像
FROM alpine:latest
-# 创建并切换工作目录
+# 设置工作目录并复制文件
WORKDIR /app
-
-# 复制二进制文件
+COPY --from=builder /build/bin /app/bin
COPY KrillinAI ./
-# 设置可执行权限
-RUN chmod +x ./KrillinAI
+# 创建必要目录并设置权限
+RUN mkdir -p /app/models && \
+ chmod +x ./KrillinAI
+
+# 声明卷
+VOLUME ["/app/bin", "/app/models"]
+
+# 设置环境变量
+ENV PATH="/app/bin:${PATH}"
# 设置入口点
ENTRYPOINT ["./KrillinAI"]
\ No newline at end of file
diff --git a/README.md b/README.md
index bb8cdd8b..7efeee95 100644
--- a/README.md
+++ b/README.md
@@ -67,15 +67,18 @@ https://github.com/user-attachments/assets/0b32fad3-c3ad-4b6a-abf0-0865f0dd2385
### To: macOS用户
本软件没有做签名,因此在macOS上运行时,在完成“基本步骤”中的文件配置后,还需要手动信任应用,方法如下:
-1. 在终端打开可执行文件(假设文件名是KrillinAI-v1.0.0-windows)所在目录
+1. 在终端打开可执行文件(假设文件名是KrillinAI_1.0.0_macOS_arm64)所在目录
2. 依次执行以下命令:
```
- sudo xattr -rd com.apple.quarantine ./KrillinAI-v1.0.0-windows
- sudo chmod +x ./KrillinAI-v1.0.0-windows
- ./KrillinAI-v1.0.0-windows
+ sudo xattr -rd com.apple.quarantine ./KrillinAI_1.0.0_macOS_arm64
+ sudo chmod +x ./KrillinAI_1.0.0_macOS_arm64
+ ./KrillinAI_1.0.0_macOS_arm64
```
即可启动服务
+### Docker部署
+本项目支持Docker部署,请参考[Docker部署说明](./docs/docker.md)
+
### Cookie配置说明
如果你遇到视频下载失败的情况
diff --git a/config/config.go b/config/config.go
index 7144d5fa..037b9d8b 100644
--- a/config/config.go
+++ b/config/config.go
@@ -4,6 +4,8 @@ import (
"errors"
"github.com/BurntSushi/toml"
"net/url"
+ "os"
+ "strconv"
)
type App struct {
@@ -60,24 +62,161 @@ type Config struct {
Aliyun Aliyun `toml:"aliyun"`
}
-var Conf Config
+var Conf = Config{
+ App: App{
+ SegmentDuration: 5,
+ TranslateParallelNum: 5,
+ TranscribeProvider: "openai",
+ LlmProvider: "openai",
+ },
+ Server: Server{
+ Host: "127.0.0.1",
+ Port: 8888,
+ },
+ LocalModel: LocalModel{
+ FasterWhisper: "medium",
+ },
+}
+
+// 从环境变量加载配置
+func loadFromEnv() {
+ // App 配置
+ if v := os.Getenv("KRILLIN_SEGMENT_DURATION"); v != "" {
+ if duration, err := strconv.Atoi(v); err == nil {
+ Conf.App.SegmentDuration = duration
+ }
+ }
+ if v := os.Getenv("KRILLIN_TRANSLATE_PARALLEL_NUM"); v != "" {
+ if num, err := strconv.Atoi(v); err == nil {
+ Conf.App.TranslateParallelNum = num
+ }
+ }
+ if v := os.Getenv("KRILLIN_PROXY"); v != "" {
+ Conf.App.Proxy = v
+ }
+ if v := os.Getenv("KRILLIN_TRANSCRIBE_PROVIDER"); v != "" {
+ Conf.App.TranscribeProvider = v
+ }
+ if v := os.Getenv("KRILLIN_LLM_PROVIDER"); v != "" {
+ Conf.App.LlmProvider = v
+ }
+
+ // Server 配置
+ if v := os.Getenv("KRILLIN_SERVER_HOST"); v != "" {
+ Conf.Server.Host = v
+ }
+ if v := os.Getenv("KRILLIN_SERVER_PORT"); v != "" {
+ if port, err := strconv.Atoi(v); err == nil {
+ Conf.Server.Port = port
+ }
+ }
+
+ // LocalModel 配置
+ if v := os.Getenv("KRILLIN_FASTER_WHISPER"); v != "" {
+ Conf.LocalModel.FasterWhisper = v
+ }
+
+ // OpenAI 配置
+ if v := os.Getenv("KRILLIN_OPENAI_BASE_URL"); v != "" {
+ Conf.Openai.BaseUrl = v
+ }
+ if v := os.Getenv("KRILLIN_OPENAI_MODEL"); v != "" {
+ Conf.Openai.Model = v
+ }
+ if v := os.Getenv("KRILLIN_OPENAI_API_KEY"); v != "" {
+ Conf.Openai.ApiKey = v
+ }
+
+ // Aliyun OSS 配置
+ if v := os.Getenv("KRILLIN_ALIYUN_OSS_ACCESS_KEY_ID"); v != "" {
+ Conf.Aliyun.Oss.AccessKeyId = v
+ }
+ if v := os.Getenv("KRILLIN_ALIYUN_OSS_ACCESS_KEY_SECRET"); v != "" {
+ Conf.Aliyun.Oss.AccessKeySecret = v
+ }
+ if v := os.Getenv("KRILLIN_ALIYUN_OSS_BUCKET"); v != "" {
+ Conf.Aliyun.Oss.Bucket = v
+ }
+
+ // Aliyun Speech 配置
+ if v := os.Getenv("KRILLIN_ALIYUN_SPEECH_ACCESS_KEY_ID"); v != "" {
+ Conf.Aliyun.Speech.AccessKeyId = v
+ }
+ if v := os.Getenv("KRILLIN_ALIYUN_SPEECH_ACCESS_KEY_SECRET"); v != "" {
+ Conf.Aliyun.Speech.AccessKeySecret = v
+ }
+ if v := os.Getenv("KRILLIN_ALIYUN_SPEECH_APP_KEY"); v != "" {
+ Conf.Aliyun.Speech.AppKey = v
+ }
+
+ // Aliyun Bailian 配置
+ if v := os.Getenv("KRILLIN_ALIYUN_BAILIAN_API_KEY"); v != "" {
+ Conf.Aliyun.Bailian.ApiKey = v
+ }
+}
+
+// 检查必要的配置是否完整
+func validateConfig() error {
+ // 检查转写服务提供商配置
+ switch Conf.App.TranscribeProvider {
+ case "openai":
+ if Conf.Openai.ApiKey == "" {
+ return errors.New("使用OpenAI转写服务需要配置 OpenAI API Key")
+ }
+ case "fasterwhisper":
+ if Conf.LocalModel.FasterWhisper != "tiny" && Conf.LocalModel.FasterWhisper != "medium" && Conf.LocalModel.FasterWhisper != "large-v2" {
+ return errors.New("检测到开启了fasterwhisper,但模型选型配置不正确,请检查配置")
+ }
+ case "aliyun":
+ if Conf.Aliyun.Speech.AccessKeyId == "" || Conf.Aliyun.Speech.AccessKeySecret == "" || Conf.Aliyun.Speech.AppKey == "" {
+ return errors.New("使用阿里云语音服务需要配置相关密钥")
+ }
+ default:
+ return errors.New("不支持的转写服务提供商")
+ }
+
+ // 检查LLM提供商配置
+ switch Conf.App.LlmProvider {
+ case "openai":
+ if Conf.Openai.ApiKey == "" {
+ return errors.New("使用OpenAI LLM服务需要配置 OpenAI API Key")
+ }
+ case "aliyun":
+ if Conf.Aliyun.Bailian.ApiKey == "" {
+ return errors.New("使用阿里云百炼服务需要配置 API Key")
+ }
+ default:
+ return errors.New("不支持的LLM提供商")
+ }
+
+ return nil
+}
func LoadConfig(filePath string) error {
var err error
- _, err = toml.DecodeFile(filePath, &Conf)
- if err != nil {
- return err
+
+ // 如果提供了配置文件路径,则尝试加载
+ if filePath != "" {
+ _, err = toml.DecodeFile(filePath, &Conf)
+ if err != nil {
+ return err
+ }
}
+
+ // 加载环境变量配置
+ loadFromEnv()
+
// 解析代理地址
Conf.App.ParsedProxy, err = url.Parse(Conf.App.Proxy)
if err != nil {
return err
}
+
+ // 如果使用fasterwhisper,强制设置并行数为1
if Conf.App.TranscribeProvider == "fasterwhisper" {
Conf.App.TranslateParallelNum = 1
- if Conf.LocalModel.FasterWhisper != "tiny" && Conf.LocalModel.FasterWhisper != "medium" && Conf.LocalModel.FasterWhisper != "large-v2" {
- return errors.New("检测到开启了fasterwhisper,但模型选型配置不正确,请检查配置")
- }
}
- return nil
+
+ // 验证配置
+ return validateConfig()
}
diff --git a/docs/README_en.md b/docs/README_en.md
index c5968977..4c5a5680 100644
--- a/docs/README_en.md
+++ b/docs/README_en.md
@@ -63,15 +63,18 @@ https://github.com/user-attachments/assets/0b32fad3-c3ad-4b6a-abf0-0865f0dd2385
### To: macOS Users
This software is not signed, so after completing the file configuration in the "Basic Steps," you will need to manually trust the application on macOS. Follow these steps:
-1. Open the terminal and navigate to the directory where the executable file (assuming the file name is `KrillinAI-v1.0.0-windows`) is located.
+1. Open the terminal and navigate to the directory where the executable file (assuming the file name is `KrillinAI_1.0.0_macOS_arm64`) is located.
2. Execute the following commands in sequence:
```
-sudo xattr -rd com.apple.quarantine ./KrillinAI-v1.0.0-windows
-sudo chmod +x ./KrillinAI-v1.0.0-windows
-./KrillinAI-v1.0.0-windows
+sudo xattr -rd com.apple.quarantine ./KrillinAI_1.0.0_macOS_arm64
+sudo chmod +x ./KrillinAI_1.0.0_macOS_arm64
+./KrillinAI_1.0.0_macOS_arm64
```
This will start the service.
+### Docker Deployment
+This project supports Docker deployment. Please refer to the [Docker Deployment Instructions](./docker.md).
+
### Cookie Configuration Instructions
If you encounter video download failures, please refer to the [Cookie Configuration Instructions](./get_cookies.md) to configure your cookie information.
diff --git a/docs/docker.md b/docs/docker.md
new file mode 100644
index 00000000..a70cb4bd
--- /dev/null
+++ b/docs/docker.md
@@ -0,0 +1,112 @@
+# Docker 部署指南
+
+## 方法1. 使用配置文件
+先准备好配置文件,假设服务器监听端口为8888
+
+### docker run启动
+```bash
+docker run -d \
+ -p 8888:8888 \
+ -v /path/to/config.toml:/app/config.toml \
+ ghcr.io/krillinai/krillin
+```
+
+### docker-compose启动
+```yaml
+version: '3'
+services:
+ krillin:
+ image: ghcr.io/krillinai/krillin
+ ports:
+ - "8888:8888"
+ volumes:
+ - /path/to/config.toml:/app/config.toml
+```
+
+## 方法2. 使用环境变量
+
+KrillinAI 支持通过环境变量来代替配置文件。所有环境变量都以 `KRILLIN_` 为前缀。
+
+### 应用配置
+- `KRILLIN_SEGMENT_DURATION`: 视频分段时长(整数,默认值: 5)
+- `KRILLIN_TRANSLATE_PARALLEL_NUM`: 翻译并行数(整数,默认值: 5,使用fasterwhisper时强制为1)
+- `KRILLIN_PROXY`: 代理服务器地址(可选,默认值: 空)
+- `KRILLIN_TRANSCRIBE_PROVIDER`: 转写服务提供商(默认值: openai,可选: openai/fasterwhisper/aliyun)
+- `KRILLIN_LLM_PROVIDER`: LLM 服务提供商(默认值: openai,可选: openai/aliyun)
+
+### 服务器配置
+- `KRILLIN_SERVER_HOST`: 服务器监听地址(默认值: 127.0.0.1)
+- `KRILLIN_SERVER_PORT`: 服务器监听端口(整数,默认值: 8888)
+
+### 本地模型配置
+- `KRILLIN_FASTER_WHISPER`: Faster Whisper 所使用的模型(当 transcribe_provider 为 fasterwhisper 时有效,默认值: medium,可选: tiny/medium/large-v2)
+
+### OpenAI 配置
+- `KRILLIN_OPENAI_BASE_URL`: OpenAI API 基础 URL(可选,默认值: 官方 API 地址)
+- `KRILLIN_OPENAI_MODEL`: OpenAI 模型名称(可选,默认值: gpt-4-mini)
+- `KRILLIN_OPENAI_API_KEY`: OpenAI API 密钥(当使用 OpenAI 服务时必填)
+
+### 阿里云配置
+
+#### OSS 配置(用于音色克隆功能)
+- `KRILLIN_ALIYUN_OSS_ACCESS_KEY_ID`: 阿里云 OSS AccessKey ID(使用音色克隆功能时必填)
+- `KRILLIN_ALIYUN_OSS_ACCESS_KEY_SECRET`: 阿里云 OSS AccessKey Secret(使用音色克隆功能时必填)
+- `KRILLIN_ALIYUN_OSS_BUCKET`: 阿里云 OSS Bucket 名称(使用音色克隆功能时必填)
+
+#### 语音服务配置(用于语音识别或配音功能)
+- `KRILLIN_ALIYUN_SPEECH_ACCESS_KEY_ID`: 阿里云语音服务 AccessKey ID(使用阿里云语音服务时必填)
+- `KRILLIN_ALIYUN_SPEECH_ACCESS_KEY_SECRET`: 阿里云语音服务 AccessKey Secret(使用阿里云语音服务时必填)
+- `KRILLIN_ALIYUN_SPEECH_APP_KEY`: 阿里云语音服务 AppKey(使用阿里云语音服务时必填)
+
+#### 百炼配置(用于 LLM)
+- `KRILLIN_ALIYUN_BAILIAN_API_KEY`: 阿里云百炼 API 密钥(当 llm_provider 为 aliyun 时必填)
+
+### docker run启动(最简配置示例)
+```bash
+docker run -d \
+ -p 8888:8888 \
+ -e KRILLIN_OPENAI_API_KEY=your-api-key \
+ ghcr.io/krillinai/krillin
+```
+
+### docker-compose启动(最简配置示例)
+```yaml
+version: '3'
+services:
+ krillin:
+ image: ghcr.io/krillinai/krillin
+ ports:
+ - "8888:8888"
+ environment:
+ - KRILLIN_OPENAI_API_KEY=your-api-key
+```
+
+## 持久化模型
+如果使用fasterwhisper模型, KrillinAI 会自动下载模型所需文件到`/app/models`目录和`/app/bin`目录。容器删除后,这些文件会丢失。如果需要持久化模型,可以将这两个目录映射到宿主机的目录。
+
+### docker run启动
+```bash
+docker run -d \
+ # ...其他参数
+ -v /path/to/models:/app/models \
+ -v /path/to/bin:/app/bin \
+ ghcr.io/krillinai/krillin
+```
+
+### docker-compose启动
+```yaml
+version: '3'
+services:
+ krillin:
+ image: ghcr.io/krillinai/krillin
+ # ...其他参数
+ volumes:
+ # ...其他映射
+ - /path/to/models:/app/models
+ - /path/to/bin:/app/bin
+```
+
+## 注意事项
+1. 环境变量的值会覆盖配置文件中的对应设置。即环境变量优先级高于配置文件。不推荐混合使用配置文件和环境变量。
+2. 配置文件和环境变量二选一即可,推荐使用环境变量方式。
+
diff --git a/main.go b/main.go
index 095d1d95..d0022c1e 100644
--- a/main.go
+++ b/main.go
@@ -8,6 +8,7 @@ import (
"krillin-ai/internal/deps"
"krillin-ai/internal/router"
"krillin-ai/log"
+ "os"
)
type App struct {
@@ -19,9 +20,18 @@ func main() {
log.InitLogger()
defer log.GetLogger().Sync() // 确保日志被正确写入
- err = config.LoadConfig("./config/config.toml")
+ configPath := "./config/config.toml"
+ if _, err := os.Stat(configPath); os.IsNotExist(err) {
+ // 配置文件不存在,仅使用环境变量
+ log.GetLogger().Info("配置文件不存在,将仅使用环境变量配置")
+ err = config.LoadConfig("")
+ } else {
+ // 配置文件存在,加载配置文件
+ err = config.LoadConfig(configPath)
+ }
+
if err != nil {
- log.GetLogger().Error("加载配置文件失败", zap.Error(err))
+ log.GetLogger().Error("加载配置失败", zap.Error(err))
return
}