osmith has uploaded this change for review. ( 
https://gerrit.osmocom.org/c/osmo-ci/+/29598 )


Change subject: obs: prepare for multiple dockerfiles
......................................................................

obs: prepare for multiple dockerfiles

Rename Dockerfile to build_srcpkg.Dockerfile and adjust related code to
allow using a different Dockerfile for building the binary packages in a
future patch.

Related: OS#2385
Change-Id: I8ef7944a4a81acd6c915998f37139eebad2b2d3e
---
R scripts/obs/data/build_srcpkg.Dockerfile
M scripts/obs/lib/config.py
M scripts/obs/lib/docker.py
3 files changed, 27 insertions(+), 7 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/osmo-ci refs/changes/98/29598/1

diff --git a/scripts/obs/data/Dockerfile 
b/scripts/obs/data/build_srcpkg.Dockerfile
similarity index 100%
rename from scripts/obs/data/Dockerfile
rename to scripts/obs/data/build_srcpkg.Dockerfile
diff --git a/scripts/obs/lib/config.py b/scripts/obs/lib/config.py
index 79a7849..52b84fb 100644
--- a/scripts/obs/lib/config.py
+++ b/scripts/obs/lib/config.py
@@ -111,4 +111,4 @@
         "open5gs": "^v[0-9]*\\.[0-9]*\\.[0-9]*$",
 }

-docker_image_name = "debian-bullseye-osmocom-obs"
+docker_distro_default = "debian:11"
diff --git a/scripts/obs/lib/docker.py b/scripts/obs/lib/docker.py
index 629f239..0a1f748 100644
--- a/scripts/obs/lib/docker.py
+++ b/scripts/obs/lib/docker.py
@@ -8,11 +8,20 @@
 import lib.config


-def build_image():
-    print(f"docker: building image {lib.config.docker_image_name}")
+def get_image_name(distro, image_type):
+    ret = f"{distro}-osmocom-obs-{image_type}"
+    ret = ret.replace(":","-").replace("_","-")
+    return ret
+
+
+def build_image(distro, image_type):
+    image_name = get_image_name(distro, image_type),
+    print(f"docker: building image {image_name}")
     lib.run_cmd(["docker", "build",
+                 "--build-arg", f"DISTRO={distro}",
                  "--build-arg", f"UID={os.getuid()}",
-                 "-t", lib.config.docker_image_name,
+                 "-t", get_image_name(distro, image_type),
+                 "-f", f"{lib.config.path_top}/data/{image_type}.Dockerfile",
                  f"{lib.config.path_top}/data"])


@@ -28,7 +37,14 @@
     exit(1)


-def run_in_docker_and_exit(script_path, add_oscrc=False):
+def run_in_docker_and_exit(script_path, add_oscrc=False,
+                           image_type="build_srcpkg", distro=None):
+    """
+    :param script_path: what to run inside docker
+    :param add_oscrc: put user's oscrc in docker (contains obs credentials!)
+    :param image_type: which Dockerfile to use (data/{image_type}.Dockerfile)
+    :param distro: which Linux distribution to use, e.g. "debian:11"
+    """
     if "INSIDE_DOCKER" in os.environ:
         return

@@ -36,6 +52,10 @@
         print("ERROR: docker is not installed")
         exit(1)

+    if not distro:
+        distro = lib.config.docker_distro_default
+    image_name = get_image_name(distro, image_type)
+
     oscrc = None
     if add_oscrc:
         oscrc = get_oscrc()
@@ -44,7 +64,7 @@
     # minutes or so, therefore print the output. No need to restore
     # set_cmds_verbose, as we use subprocess.run() below and exit afterwards.
     lib.set_cmds_verbose(True)
-    build_image()
+    build_image(distro, image_type)

     cmd = ["docker", "run",
            "--rm",
@@ -56,7 +76,7 @@
         cmd += ["-v", f"{oscrc}:/home/user/.oscrc"]

     script_path = f"/obs/{os.path.basename(script_path)}"
-    cmd += [lib.config.docker_image_name, script_path] + sys.argv[1:]
+    cmd += [image_name, script_path] + sys.argv[1:]

     print(f"docker: running: {os.path.basename(script_path)} inside docker")
     ret = subprocess.run(cmd)

--
To view, visit https://gerrit.osmocom.org/c/osmo-ci/+/29598
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-ci
Gerrit-Branch: master
Gerrit-Change-Id: I8ef7944a4a81acd6c915998f37139eebad2b2d3e
Gerrit-Change-Number: 29598
Gerrit-PatchSet: 1
Gerrit-Owner: osmith <[email protected]>
Gerrit-MessageType: newchange

Reply via email to