﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
36461	Sort keys in staticfiles.json to support reproducible builds	Matthew Stell		"I am attempting to implement a build process whereby all my docker builds are reproducible.
I am running the collectstatic management command (using the ManifestStaticFilesStorage backend) as the final step of the Dockerfile, however the ordering of the key-value pairs in the staticfiles.json are not consistent across builds.

I propose that the keys in the staticfiles.json ""paths"" section are sorted alphabetically to ensure that the staticfiles.json file generated for a given set of static files is always consistent.
I do not believe that this will introduce a breaking change.

I am happy to submit a PR to implement this if accepted.


Here is the relevant code block:
https://github.com/django/django/blob/1ba5fe19ca221663e6a1e9391dbe726bb2baaf8a/django/contrib/staticfiles/storage.py#L498

{{{
    def save_manifest(self):
        self.manifest_hash = self.file_hash(
            None, ContentFile(json.dumps(sorted(self.hashed_files.items())).encode())
        )
        payload = {
            ""paths"": self.hashed_files,
            ""version"": self.manifest_version,
            ""hash"": self.manifest_hash,
        }
        if self.manifest_storage.exists(self.manifest_name):
            self.manifest_storage.delete(self.manifest_name)
        contents = json.dumps(payload).encode()
        self.manifest_storage._save(self.manifest_name, ContentFile(contents))
}}}
"	Cleanup/optimization	closed	contrib.staticfiles	5.1	Normal	duplicate			Unreviewed	0	0	0	0	1	0
