"""Construct our own manifest definition. Usually you may want to utilize some library layer instead, some standard program to bundle the layers with your build definition, platform, license, author etc. Here we demonstrate how to do this by hand instead. The process is simple. The build tool will pass a file into which it dumps the hash-based object-identity of all layers that will be part of the bundled image. In turn, the runner constructs an OCI compatible manifest description for (part of) these layers. Referencing layers that were not in the file provided will generally fail. More precisely, only layers mentioned to the task's timeline as `export-layer` can be utilized. """ import json import hashlib import sys with open('layers.json', 'r') as layers: layers = json.load(layers) layers = [r['layer'] for r in layers['exports']] print(layers, file=sys.stderr) with open('oci-config.json', 'wb') as config: config_data = json.dumps({ "architecture":"amd64", "os":"linux", "rootfs": { "type":"layers", "diff_ids":[l['digest'] for l in layers], } }).encode() configsize = len(config_data) config.write(config_data) m = hashlib.sha256() m.update(config_data) configdigest = m.hexdigest() with open('manifest.json', 'w') as manifest: json.dump({ "schemaVersion": 2, "mediaType": "application/vnd.oci.image.manifest.v1+json", "config": { "mediaType": "application/vnd.oci.image.config.v1+json", "digest": f"sha256:{configdigest}", "size": configsize, }, "layers": layers, }, manifest, indent=1)