From ba398d43092295dc35f4860f7279f6dd5aa6e781 Mon Sep 17 00:00:00 2001
From: Lars Bilke <lars.bilke@ufz.de>
Date: Fri, 9 Apr 2021 14:43:37 +0200
Subject: [PATCH] Added enroot support.

-E option for converting to enroot squashfs image
--enroot_file for specifying filename
---
 ogscm/app/builder.py | 16 +++++++++++++---
 ogscm/cli.py         | 13 +++++++++++++
 2 files changed, 26 insertions(+), 3 deletions(-)

diff --git a/ogscm/app/builder.py b/ogscm/app/builder.py
index 1a93e35..361bc75 100644
--- a/ogscm/app/builder.py
+++ b/ogscm/app/builder.py
@@ -51,14 +51,24 @@ class builder(object):
 
         if self.__args.upload:
             subprocess.run(f"docker push {self.__tag}", shell=True)
+        image_base_name = f"{self.__images_out_dir}/{self.__img_file}-{image_id_short}"
         if self.__args.sif_file:
             self.image_file = f"{self.__images_out_dir}/{self.__args.sif_file}"
         else:
-            self.image_file = (
-                f"{self.__images_out_dir}/{self.__img_file}-{image_id_short}.sif"
-            )
+            self.image_file = f"{image_base_name}.sif"
         if self.__args.convert and not os.path.exists(self.image_file):
             subprocess.run(
                 f"cd {self.__cwd} && singularity build --force {self.image_file} docker-daemon:{self.__tag}",
                 shell=True,
             )
+
+        if self.__args.enroot_file:
+            self.image_file = f"{self.__images_out_dir}/{self.__args.enroot_file}"
+        else:
+            self.image_file = f"{image_base_name}.sqsh"
+        if self.__args.convert_enroot and not os.path.exists(self.image_file):
+            subprocess.run(
+                f"cd {self.__cwd} && ENROOT_SQUASH_OPTIONS='-comp lz4 -noD' enroot import -o {self.image_file} dockerd://{self.__tag}",
+                shell=True,
+            )
+            print(f"Wrote image file {self.image_file}")
diff --git a/ogscm/cli.py b/ogscm/cli.py
index cb05e22..65fdbe5 100644
--- a/ogscm/cli.py
+++ b/ogscm/cli.py
@@ -44,6 +44,12 @@ def main():  # pragma: no cover
         default="",
         help="Overwrite output singularity image file name",
     )
+    parser.add_argument(
+        "--enroot_file",
+        type=str,
+        default="",
+        help="Overwrite output enroot image file name",
+    )
     parser.add_argument(
         "--print",
         "-P",
@@ -103,6 +109,13 @@ def main():  # pragma: no cover
         action="store_true",
         help="Convert Docker image to Singularity image",
     )
+    build_g.add_argument(
+        "--convert-enroot",
+        "-E",
+        dest="convert_enroot",
+        action="store_true",
+        help="Convert Docker image to enroot image",
+    )
     build_g.add_argument(
         "--runtime-only",
         "-R",
-- 
GitLab