blob: ac1a6e53fb985013b1b25adeaaa7af45b7d0f8a9 [file] [log] [blame]
Leonardo Sandovalbe9e39c2020-09-02 18:17:43 -05001#!/usr/bin/env python3
2#
3# Copyright (c) 2020, Arm Limited. All rights reserved.
4#
5# SPDX-License-Identifier: BSD-3-Clause
6#
7
8# Script that takes a FVP yaml file and produces the parameters for a docker run
9# command. Conceptually, this is similar to 'pgk-config' system application but
10# this scripts applies to docker-run parameters.
11#
12# To exemplify its usage, let's assume we have the a FVP yaml file at ~/fvp.yaml
13# then launch the container using the script to provide the correct model parameters
14#
15# $ docker run `./yaml-docker-config ~/fvp.yaml`
16#
17# If no errors, the (containerized) FVP model should be up and running. In case the
18# docker image is not found, please create one following the instructions on the
19# fvp/README.md file.
20
21import yaml, sys, os.path, argparse
22
23class YamlDockerConfig:
24 def __init__(self, yaml_file):
25 with open(yaml_file) as f:
26 self.data = yaml.load(f, Loader=yaml.FullLoader)
27
28 self.docker_image = self. data['actions'][1]['boot']['docker']['name']
29 self.image = self. data['actions'][1]['boot']['image']
30 self.params = self.data['actions'][1]['boot']['arguments']
31
32 self._artefacts = self.data['actions'][0]['deploy']['images']
33 self.artefacts = [(self._artefacts[a]['url'], os.path.basename(self._artefacts[a]['url'])) for a in self._artefacts.keys()]
34
35 def docker_params(self):
36 docker_image, docker_ep = f"{self.docker_image}", f"{self.image}"
37 docker_bn_ep = os.path.dirname(docker_ep)
38 model_params = f"{' '.join(self.params)}"
39
40 # each artefact correspond to a --volume parameter
41 volumes = ''
42 for artefact in self.artefacts:
43 if artefact[0]:
44 a = artefact[0].strip('file:')
45 volumes += f"--volume {a}:{docker_bn_ep}/{artefact[1]} "
46
47 self._docker_params = volumes + " " + docker_image + " " + docker_ep + " " + model_params
48 return self._docker_params
49
50if __name__ == "__main__":
51
52 parser = argparse.ArgumentParser()
53 parser.add_argument("yaml", help="yaml filepath")
54 opts = parser.parse_args()
55
56 ydc = YamlDockerConfig(opts.yaml)
57 print(ydc.docker_params())
58
59 sys.exit(0)