`docker ps -q` 默认输出 12 位短 ID,与 declared 里的 64 位 ID 永不相等, 结果连已声明的写入者都被判成"未声明的并发写入者",封存永远开不了窗。 改用 --no-trunc 并按前缀双向匹配。
This commit is contained in:
+18
-2
@@ -816,12 +816,14 @@ func writerImageIDs(ctx context.Context, items []libraryfreeze.Service) ([]strin
|
||||
func checkNoUndeclaredWriter(ctx context.Context, images []string, declared map[string]bool,
|
||||
sourceProject string, source map[string]string) error {
|
||||
for _, image := range images {
|
||||
out, err := dockerOutput(ctx, "ps", "-q", "--filter", "ancestor="+image)
|
||||
// 必须 --no-trunc:`docker ps` 默认只给 12 位短 ID,和 declared 里的
|
||||
// 64 位容器 ID 永远不相等——那样连"已声明的写入者"都会被判成未声明。
|
||||
out, err := dockerOutput(ctx, "ps", "-aq", "--no-trunc", "--filter", "ancestor="+image)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, id := range strings.Fields(out) {
|
||||
if declared[id] {
|
||||
if declaredWriter(declared, id) {
|
||||
continue
|
||||
}
|
||||
project, err := dockerOutput(ctx, "inspect", "--format", `{{index .Config.Labels "com.docker.compose.project"}}`, id)
|
||||
@@ -840,6 +842,20 @@ func checkNoUndeclaredWriter(ctx context.Context, images []string, declared map[
|
||||
return nil
|
||||
}
|
||||
|
||||
// declaredWriter 同时接受完整 ID 与短 ID:证据里两种写法都出现过,
|
||||
// 只比一种会把同一容器判成两个身份。
|
||||
func declaredWriter(declared map[string]bool, id string) bool {
|
||||
if declared[id] {
|
||||
return true
|
||||
}
|
||||
for key := range declared {
|
||||
if strings.HasPrefix(key, id) || strings.HasPrefix(id, key) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// sourceTargetOf 只取"写到哪儿"的身份:同一个数据库或同一个队列才是真冲突。
|
||||
func sourceTargetOf(env map[string]string) map[string]string {
|
||||
return map[string]string{
|
||||
|
||||
Reference in New Issue
Block a user