1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3
4# Deterministic layer json: https://github.com/docker/hub-feedback/issues/488
5
6import sys
7reload(sys)
8sys.setdefaultencoding('UTF8')
9import json
10
11# If any of the keys below are equal to a certain value
12# then we can delete it because it's the default value
13SAFEDELS = {
14 "Size": 0,
15 "config": {
16 "ExposedPorts": None,
17 "MacAddress": "",
18 "NetworkDisabled": False,
19 "PortSpecs": None,
20 "VolumeDriver": ""
21 }
22}
23SAFEDELS["container_config"] = SAFEDELS["config"]
24
25def makedet(j, safedels):
26 for k,v in safedels.items():
27 if k not in j:
28 continue
29 if type(v) == dict:
30 makedet(j[k], v)
31 elif j[k] == v:
32 del j[k]
33
34def main():
35 j = json.load(sys.stdin)
36 makedet(j, SAFEDELS)
37 json.dump(j, sys.stdout, sort_keys=True)
38
39if __name__ == '__main__':
40 main()