#36461: Sort keys in staticfiles.json to support reproducible builds
-------------------------------------+-------------------------------------
     Reporter:  matthews-noriker     |                     Type:
                                     |  Cleanup/optimization
       Status:  new                  |                Component:
                                     |  contrib.staticfiles
      Version:  5.1                  |                 Severity:  Normal
     Keywords:                       |             Triage Stage:
                                     |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  1                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
 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))
 }}}
-- 
Ticket URL: <https://code.djangoproject.com/ticket/36461>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/django-updates/0107019763bec640-d0265981-0154-4aae-aba0-765d176638c1-000000%40eu-central-1.amazonses.com.

Reply via email to