aboutsummaryrefslogtreecommitdiff
path: root/infra/libkookie/nixpkgs/pkgs/build-support/docker/detjson.py
blob: fe82cbea11bbf6b723bbc5b4d056097dba5ed8fe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/env python
# -*- coding: utf-8 -*-

# Deterministic layer json: https://github.com/docker/hub-feedback/issues/488

import sys
reload(sys)
sys.setdefaultencoding('UTF8')
import json

# If any of the keys below are equal to a certain value
# then we can delete it because it's the default value
SAFEDELS = {
    "Size": 0,
    "config": {
        "ExposedPorts": None,
        "MacAddress": "",
        "NetworkDisabled": False,
        "PortSpecs": None,
        "VolumeDriver": ""
    }
}
SAFEDELS["container_config"] = SAFEDELS["config"]

def makedet(j, safedels):
    for k,v in safedels.items():
        if k not in j:
            continue
        if type(v) == dict:
            makedet(j[k], v)
        elif j[k] == v:
            del j[k]

def main():
    j = json.load(sys.stdin)
    makedet(j, SAFEDELS)
    json.dump(j, sys.stdout, sort_keys=True)

if __name__ == '__main__':
    main()