summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeonardo Sandoval <leonardo.sandoval@linaro.org>2020-09-02 18:17:43 -0500
committerZelalem Aweke <zelalem.aweke@arm.com>2020-10-01 16:05:53 +0000
commitbe9e39c47848d0fe2e62e3bb79ac4287c16603cb (patch)
tree3199ee0a914295e6438c4e3319c45de2937543a8
parent42d69353a8b5cca494c4de774500482430f24f76 (diff)
downloadtf-a-ci-scripts-be9e39c47848d0fe2e62e3bb79ac4287c16603cb.tar.gz
Introduce yaml-docker-config python script
Script that takes a FVP yaml file and produces the parameters for a docker-run command. Conceptually, this is similar to 'pgk-config' system application but this scripts applies to docker-run parameters. To exemplify its usage, let's assume we have the a FVP yaml file at ~/fvp.yaml then launch the container using the script to provide the correct model parameters $ docker run `./yaml-docker-config ~/fvp.yaml` If no errors, the (containerized) FVP model should be up and running. In case the docker image is not found, please create one following the instructions on the fvp/README.md file. Change-Id: I03aab0b882d4b0204df90b2b65cbdba637e19a51 Signed-off-by: Leonardo Sandoval <leonardo.sandoval@linaro.org>
-rwxr-xr-xscript/docker/yaml-docker-config.py59
1 files changed, 59 insertions, 0 deletions
diff --git a/script/docker/yaml-docker-config.py b/script/docker/yaml-docker-config.py
new file mode 100755
index 000000000..ac1a6e53f
--- /dev/null
+++ b/script/docker/yaml-docker-config.py
@@ -0,0 +1,59 @@
+#!/usr/bin/env python3
+#
+# Copyright (c) 2020, Arm Limited. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+
+# Script that takes a FVP yaml file and produces the parameters for a docker run
+# command. Conceptually, this is similar to 'pgk-config' system application but
+# this scripts applies to docker-run parameters.
+#
+# To exemplify its usage, let's assume we have the a FVP yaml file at ~/fvp.yaml
+# then launch the container using the script to provide the correct model parameters
+#
+# $ docker run `./yaml-docker-config ~/fvp.yaml`
+#
+# If no errors, the (containerized) FVP model should be up and running. In case the
+# docker image is not found, please create one following the instructions on the
+# fvp/README.md file.
+
+import yaml, sys, os.path, argparse
+
+class YamlDockerConfig:
+ def __init__(self, yaml_file):
+ with open(yaml_file) as f:
+ self.data = yaml.load(f, Loader=yaml.FullLoader)
+
+ self.docker_image = self. data['actions'][1]['boot']['docker']['name']
+ self.image = self. data['actions'][1]['boot']['image']
+ self.params = self.data['actions'][1]['boot']['arguments']
+
+ self._artefacts = self.data['actions'][0]['deploy']['images']
+ self.artefacts = [(self._artefacts[a]['url'], os.path.basename(self._artefacts[a]['url'])) for a in self._artefacts.keys()]
+
+ def docker_params(self):
+ docker_image, docker_ep = f"{self.docker_image}", f"{self.image}"
+ docker_bn_ep = os.path.dirname(docker_ep)
+ model_params = f"{' '.join(self.params)}"
+
+ # each artefact correspond to a --volume parameter
+ volumes = ''
+ for artefact in self.artefacts:
+ if artefact[0]:
+ a = artefact[0].strip('file:')
+ volumes += f"--volume {a}:{docker_bn_ep}/{artefact[1]} "
+
+ self._docker_params = volumes + " " + docker_image + " " + docker_ep + " " + model_params
+ return self._docker_params
+
+if __name__ == "__main__":
+
+ parser = argparse.ArgumentParser()
+ parser.add_argument("yaml", help="yaml filepath")
+ opts = parser.parse_args()
+
+ ydc = YamlDockerConfig(opts.yaml)
+ print(ydc.docker_params())
+
+ sys.exit(0)