This also changes the structure of the object store, though the basic idea is the same. The object store contains a directory of objects, which are content addressable filesystem trees. Currently we only ever use their content-hash internally, but the idea for this is basically Lars Karlitski and Kay Sievers' `treesum()`. We may exopse this in the future. Moreover, it contains a directory of refs, which are symlinks named by the stage id they correspond to (as before), pointing to an object generated from that stage-id. The ObjectStore exposes three method: `has_tree()`: This checks if the content store contains the given tree. If so, we can rely on the tree remaining there. `get_tree()`: This is meant to be used with a `with` block and yields the path to a read-only instance of the tree with the given id. If the tree_id is passed in as None, an empty directory is given instead. `new_tree()`: This is meant to be used with a `with` block and yields the path to a directory in which the tree by the given id should be created. If a base_id is passed in, the tree is initialized with the tree with the given id. Only when the block is exited successfully is the tree written to the content store, referenced by the id in question. Use this in Pipeline.run() to avoid regenerating trees unneccessarily. In order to trigger a regeneration, the content store must currently be manually flushed. Update the travis test to run the noop pipeline twice, verifying that the stage is only run the first time. Signed-off-by: Tom Gundersen <teg@jklm.no>
43 lines
1.6 KiB
Python
Executable file
43 lines
1.6 KiB
Python
Executable file
import argparse
|
|
import json
|
|
import os
|
|
import sys
|
|
import osbuild
|
|
|
|
|
|
RESET = "\033[0m"
|
|
BOLD = "\033[1m"
|
|
RED = "\033[31m"
|
|
|
|
|
|
def main():
|
|
parser = argparse.ArgumentParser(description="Build operating system images")
|
|
parser.add_argument("pipeline_path", metavar="PIPELINE",
|
|
help="json file containing the pipeline that should be built")
|
|
parser.add_argument("--store", metavar="DIRECTORY", type=os.path.abspath,
|
|
default=".osbuild/store",
|
|
help="the directory where intermediary os trees are stored")
|
|
parser.add_argument("-l", "--libdir", metavar="DIRECTORY", type=os.path.abspath,
|
|
help="the directory containing stages, assemblers, and the osbuild library")
|
|
requiredNamed = parser.add_argument_group('required named arguments')
|
|
requiredNamed.add_argument("-o", "--output", dest="output_dir", metavar="DIRECTORY", type=os.path.abspath,
|
|
help="provide the empty DIRECTORY as output argument to the last stage", required=True)
|
|
args = parser.parse_args()
|
|
|
|
with open(args.pipeline_path) as f:
|
|
pipeline = osbuild.load(json.load(f))
|
|
|
|
try:
|
|
pipeline.run(args.output_dir, args.store, interactive=True, libdir=args.libdir)
|
|
except KeyboardInterrupt:
|
|
print()
|
|
print(f"{RESET}{BOLD}{RED}Aborted{RESET}")
|
|
sys.exit(130)
|
|
except (osbuild.StageFailed, osbuild.AssemblerFailed) as error:
|
|
print()
|
|
print(f"{RESET}{BOLD}{RED}{error.name} failed with code {error.returncode}{RESET}")
|
|
sys.exit(1)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|