mirror of
https://git.fightbot.fun/hxuanyu/BingPaper.git
synced 2026-02-15 10:29:32 +08:00
新增 Docker Compose 支持,完善环境变量绑定逻辑,升级 Go 版本
This commit is contained in:
2
.github/workflows/release.yml
vendored
2
.github/workflows/release.yml
vendored
@@ -16,7 +16,7 @@ jobs:
|
|||||||
- name: Set up Go
|
- name: Set up Go
|
||||||
uses: actions/setup-go@v5
|
uses: actions/setup-go@v5
|
||||||
with:
|
with:
|
||||||
go-version: '1.23'
|
go-version: '1.25.5'
|
||||||
|
|
||||||
- name: Build and Package
|
- name: Build and Package
|
||||||
run: |
|
run: |
|
||||||
|
|||||||
2
.github/workflows/verify.yml
vendored
2
.github/workflows/verify.yml
vendored
@@ -15,7 +15,7 @@ jobs:
|
|||||||
- name: Set up Go
|
- name: Set up Go
|
||||||
uses: actions/setup-go@v5
|
uses: actions/setup-go@v5
|
||||||
with:
|
with:
|
||||||
go-version: '1.23'
|
go-version: '1.25.5'
|
||||||
|
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: go mod download
|
run: go mod download
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
FROM golang:1.23-alpine AS builder
|
FROM golang:1.25.5-alpine AS builder
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
COPY go.mod go.sum ./
|
COPY go.mod go.sum ./
|
||||||
|
|||||||
17
README.md
17
README.md
@@ -97,11 +97,26 @@ go run .
|
|||||||
2. 运行标签脚本:`./scripts/tag.sh v1.0.0` (替换为实际版本号)。
|
2. 运行标签脚本:`./scripts/tag.sh v1.0.0` (替换为实际版本号)。
|
||||||
3. 脚本会自动推送标签,触发 GitHub Actions 进行构建并发布 Release。
|
3. 脚本会自动推送标签,触发 GitHub Actions 进行构建并发布 Release。
|
||||||
|
|
||||||
### Docker 构建
|
### Docker 运行
|
||||||
```bash
|
```bash
|
||||||
docker build -t bing-paper .
|
docker build -t bing-paper .
|
||||||
|
docker run -d -p 8080:8080 -v $(pwd)/data:/app/data bing-paper
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Docker Compose (推荐)
|
||||||
|
使用项目根目录下的 `docker-compose.yml` 快速启动:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker-compose up -d
|
||||||
|
```
|
||||||
|
|
||||||
|
你可以通过修改 `docker-compose.yml` 中的 `environment` 部分来覆盖默认配置,例如:
|
||||||
|
- `BINGPAPER_SERVER_PORT`: 服务端口
|
||||||
|
- `BINGPAPER_API_MODE`: API 模式 (`local` 或 `redirect`)
|
||||||
|
- `BINGPAPER_DB_TYPE`: 数据库类型 (`sqlite`, `mysql`, `postgres`)
|
||||||
|
- `BINGPAPER_STORAGE_TYPE`: 存储类型 (`local`, `s3`, `webdav`)
|
||||||
|
- `BINGPAPER_ADMIN_PASSWORD_BCRYPT`: 管理员密码的 Bcrypt 哈希值
|
||||||
|
|
||||||
## 许可证
|
## 许可证
|
||||||
|
|
||||||
MIT
|
MIT
|
||||||
|
|||||||
31
docker-compose.yml
Normal file
31
docker-compose.yml
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
services:
|
||||||
|
bingpaper:
|
||||||
|
build: .
|
||||||
|
container_name: bingpaper
|
||||||
|
restart: always
|
||||||
|
ports:
|
||||||
|
- "8080:8080"
|
||||||
|
volumes:
|
||||||
|
- ./data:/app/data
|
||||||
|
environment:
|
||||||
|
- BINGPAPER_SERVER_PORT=8080
|
||||||
|
- BINGPAPER_LOG_LEVEL=info
|
||||||
|
- BINGPAPER_API_MODE=local
|
||||||
|
- BINGPAPER_CRON_ENABLED=true
|
||||||
|
- BINGPAPER_DB_TYPE=sqlite
|
||||||
|
- BINGPAPER_DB_DSN=data/bing_paper.db
|
||||||
|
- BINGPAPER_STORAGE_TYPE=local
|
||||||
|
- BINGPAPER_STORAGE_LOCAL_ROOT=data/picture
|
||||||
|
- BINGPAPER_RETENTION_DAYS=30
|
||||||
|
# S3 配置 (可选)
|
||||||
|
# - BINGPAPER_STORAGE_S3_ENDPOINT=
|
||||||
|
# - BINGPAPER_STORAGE_S3_REGION=
|
||||||
|
# - BINGPAPER_STORAGE_S3_BUCKET=
|
||||||
|
# - BINGPAPER_STORAGE_S3_ACCESS_KEY=
|
||||||
|
# - BINGPAPER_STORAGE_S3_SECRET_KEY=
|
||||||
|
# - BINGPAPER_STORAGE_S3_PUBLIC_URL_PREFIX=
|
||||||
|
# WebDAV 配置 (可选)
|
||||||
|
# - BINGPAPER_STORAGE_WEBDAV_URL=
|
||||||
|
# - BINGPAPER_STORAGE_WEBDAV_USERNAME=
|
||||||
|
# - BINGPAPER_STORAGE_WEBDAV_PASSWORD=
|
||||||
|
# - BINGPAPER_STORAGE_WEBDAV_PUBLIC_URL_PREFIX=
|
||||||
@@ -3,6 +3,7 @@ package config
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -134,6 +135,11 @@ func Init(configPath string) error {
|
|||||||
v.SetDefault("web.path", "web")
|
v.SetDefault("web.path", "web")
|
||||||
v.SetDefault("admin.password_bcrypt", "$2a$10$fYHPeWHmwObephJvtlyH1O8DIgaLk5TINbi9BOezo2M8cSjmJchka") // 默认密码: admin123
|
v.SetDefault("admin.password_bcrypt", "$2a$10$fYHPeWHmwObephJvtlyH1O8DIgaLk5TINbi9BOezo2M8cSjmJchka") // 默认密码: admin123
|
||||||
|
|
||||||
|
// 绑定环境变量
|
||||||
|
v.SetEnvPrefix("BINGPAPER")
|
||||||
|
v.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
|
||||||
|
v.AutomaticEnv()
|
||||||
|
|
||||||
if err := v.ReadInConfig(); err != nil {
|
if err := v.ReadInConfig(); err != nil {
|
||||||
// 如果指定了配置文件但读取失败(且不是找不到文件的错误),或者没指定但也没找到
|
// 如果指定了配置文件但读取失败(且不是找不到文件的错误),或者没指定但也没找到
|
||||||
_, isNotFound := err.(viper.ConfigFileNotFoundError)
|
_, isNotFound := err.(viper.ConfigFileNotFoundError)
|
||||||
|
|||||||
Reference in New Issue
Block a user