容器 env 里的 MINIO_ENDPOINT 往往是服务名(langfuse-minio:9000),封存跑在宿主机上 解析不到,真实封存报 read library resource 并整体失败。 新增 -source-s3-endpoint:只换访问入口,桶与对象键不变;缺 scheme 直接拒绝; status 会打印实际使用的 endpoint。 试过:make verify 15 项全绿;新增覆盖用例(生效 + 拒绝无 scheme)。
This commit is contained in:
+32
-19
@@ -40,22 +40,25 @@ import (
|
||||
)
|
||||
|
||||
type options struct {
|
||||
sourceApp string
|
||||
sourcePG string
|
||||
sourceES string
|
||||
governancePG string
|
||||
project string
|
||||
writers string
|
||||
nonWriters string
|
||||
archiveRoot string
|
||||
journalRoot string
|
||||
dockerSocket string
|
||||
maxDocuments int
|
||||
maxObjectBytes int64
|
||||
scope string
|
||||
job string
|
||||
dryRun bool
|
||||
snapshot string
|
||||
sourceApp string
|
||||
sourcePG string
|
||||
sourceES string
|
||||
governancePG string
|
||||
project string
|
||||
writers string
|
||||
nonWriters string
|
||||
archiveRoot string
|
||||
journalRoot string
|
||||
dockerSocket string
|
||||
// sourceS3Endpoint:容器里写的对象存储端点往往只在容器网络里能解析
|
||||
// (例如 minio 服务名),而封存跑在宿主机上。这里允许用宿主机可达地址覆盖。
|
||||
sourceS3Endpoint string
|
||||
maxDocuments int
|
||||
maxObjectBytes int64
|
||||
scope string
|
||||
job string
|
||||
dryRun bool
|
||||
snapshot string
|
||||
}
|
||||
|
||||
func main() {
|
||||
@@ -156,6 +159,7 @@ func parseFlags(command string, args []string) (options, []string, error) {
|
||||
set.StringVar(&opts.archiveRoot, "archive", opts.archiveRoot, "sealed artifact root")
|
||||
set.StringVar(&opts.journalRoot, "journal", opts.journalRoot, "freeze journal root")
|
||||
set.StringVar(&opts.dockerSocket, "docker-socket", opts.dockerSocket, "Docker engine socket")
|
||||
set.StringVar(&opts.sourceS3Endpoint, "source-s3-endpoint", "", "host-reachable source object-store endpoint (overrides the container-internal one)")
|
||||
set.IntVar(&opts.maxDocuments, "max-documents", opts.maxDocuments, "maximum indexed documents per scope")
|
||||
set.Int64Var(&opts.maxObjectBytes, "max-object-bytes", opts.maxObjectBytes, "maximum bytes per stored object")
|
||||
set.StringVar(&opts.scope, "scope", "", "internal|external")
|
||||
@@ -265,7 +269,7 @@ func discoverSource(ctx context.Context, opts options, binding map[string]string
|
||||
config.SearchIndex = app["ELASTICSEARCH_INDEX"]
|
||||
config.Search = v071.SearchExporterConfig{BaseURL: "http://" + esAddress + ":9200", Index: app["ELASTICSEARCH_INDEX"],
|
||||
AuthorizationToken: app["ELASTICSEARCH_PASSWORD"], PageSize: 500}
|
||||
config.Object, config.ObjectDetail, err = objectStoreFromSourceEnv(app, opts.maxObjectBytes)
|
||||
config.Object, config.ObjectDetail, err = objectStoreFromSourceEnv(app, opts.sourceS3Endpoint, opts.maxObjectBytes)
|
||||
if err != nil {
|
||||
return config, err
|
||||
}
|
||||
@@ -277,7 +281,7 @@ func discoverSource(ctx context.Context, opts options, binding map[string]string
|
||||
// 只认 OSS 时,S3 兼容的 MinIO 目标(本机专用验收实例)会在发现阶段就被拒,
|
||||
// 验收链只能跑在生产存储上——这不是安全性,而是能力缺口。两种都要能读,
|
||||
// 读不出端点/桶就明确报错,不退回任何默认值。
|
||||
func objectStoreFromSourceEnv(app map[string]string, maxObjectBytes int64) (v071.S3ObjectStoreConfig, string, error) {
|
||||
func objectStoreFromSourceEnv(app map[string]string, endpointOverride string, maxObjectBytes int64) (v071.S3ObjectStoreConfig, string, error) {
|
||||
storage := strings.ToLower(strings.TrimSpace(app["STORAGE_TYPE"]))
|
||||
var config v071.S3ObjectStoreConfig
|
||||
var endpoint, bucket string
|
||||
@@ -313,13 +317,22 @@ func objectStoreFromSourceEnv(app map[string]string, maxObjectBytes int64) (v071
|
||||
if strings.TrimSpace(endpoint) == "" {
|
||||
return v071.S3ObjectStoreConfig{}, "", errors.New("source object endpoint is not configured")
|
||||
}
|
||||
// 宿主机可达地址优先:容器里的 minio 服务名在宿主机上根本解析不到,
|
||||
// 真跑时资源导出会直接失败(read library resource)。覆盖仍是"同一个桶",
|
||||
// 只换访问入口,不换来源。
|
||||
if override := strings.TrimSpace(endpointOverride); override != "" {
|
||||
if !strings.Contains(override, "://") {
|
||||
return v071.S3ObjectStoreConfig{}, "", errors.New("source object endpoint override needs a scheme")
|
||||
}
|
||||
endpoint = override
|
||||
}
|
||||
config.Endpoint = endpoint
|
||||
config.Secure = strings.HasPrefix(endpoint, "https://")
|
||||
config.ForcePathStyle = storage == "minio"
|
||||
if config.Bucket == "" {
|
||||
return v071.S3ObjectStoreConfig{}, "", errors.New("source object bucket is not configured")
|
||||
}
|
||||
return config, "provider=" + config.Provider + " bucket=" + bucket, nil
|
||||
return config, "provider=" + config.Provider + " bucket=" + bucket + " endpoint=" + config.Endpoint, nil
|
||||
}
|
||||
|
||||
func firstNonEmpty(values ...string) string {
|
||||
|
||||
Reference in New Issue
Block a user