From 689af841d64631d3dced80fa729f87d05dbe1124 Mon Sep 17 00:00:00 2001 From: Alexey Makhov Date: Tue, 17 Jun 2025 22:23:25 +0300 Subject: [PATCH] Sort keys in image index to keep the digest consistent (#149) The digest is calculated based on written json data, but JSONEncoder doesn't preserve order bby default, so the digest is not consistent. Signed-off-by: Alexey --- Sources/ContainerizationOCI/Content/ContentWriter.swift | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Sources/ContainerizationOCI/Content/ContentWriter.swift b/Sources/ContainerizationOCI/Content/ContentWriter.swift index 6f2828a4..ce59c531 100644 --- a/Sources/ContainerizationOCI/Content/ContentWriter.swift +++ b/Sources/ContainerizationOCI/Content/ContentWriter.swift @@ -29,6 +29,8 @@ public class ContentWriter { /// - base: The URL to write content to. If this is not a directory a /// ContainerizationError will be thrown with a code of .internalError. public init(for base: URL) throws { + self.encoder.outputFormatting = [JSONEncoder.OutputFormatting.sortedKeys] + self.base = base var isDirectory = ObjCBool(true) let exists = FileManager.default.fileExists(atPath: base.path, isDirectory: &isDirectory)