[jenkins-ci POC 2/2] guests: Add Dockerfile generator

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is basically the exact same algorithm used by the
Ansible playbooks to process package mappings, implemented
as a standalone script.

There's little to none error handling, and some information
is hardcoded instead of being configurable at runtime; more
importantly, before it can be considered for merging it
needs to be integrated into lcitool, which in turn requires
lcitool to be significantly reworked.

Signed-off-by: Andrea Bolognani <abologna@xxxxxxxxxx>
---
 guests/dockerfile-generator                   | 72 +++++++++++++++++++
 guests/host_vars/libvirt-centos-7/docker.yml  |  2 +
 guests/host_vars/libvirt-debian-8/docker.yml  |  2 +
 guests/host_vars/libvirt-debian-9/docker.yml  |  2 +
 .../host_vars/libvirt-debian-sid/docker.yml   |  2 +
 guests/host_vars/libvirt-fedora-27/docker.yml |  2 +
 guests/host_vars/libvirt-fedora-28/docker.yml |  2 +
 .../libvirt-fedora-rawhide/docker.yml         |  2 +
 guests/host_vars/libvirt-ubuntu-16/docker.yml |  2 +
 guests/host_vars/libvirt-ubuntu-18/docker.yml |  2 +
 10 files changed, 90 insertions(+)
 create mode 100755 guests/dockerfile-generator
 create mode 100644 guests/host_vars/libvirt-centos-7/docker.yml
 create mode 100644 guests/host_vars/libvirt-debian-8/docker.yml
 create mode 100644 guests/host_vars/libvirt-debian-9/docker.yml
 create mode 100644 guests/host_vars/libvirt-debian-sid/docker.yml
 create mode 100644 guests/host_vars/libvirt-fedora-27/docker.yml
 create mode 100644 guests/host_vars/libvirt-fedora-28/docker.yml
 create mode 100644 guests/host_vars/libvirt-fedora-rawhide/docker.yml
 create mode 100644 guests/host_vars/libvirt-ubuntu-16/docker.yml
 create mode 100644 guests/host_vars/libvirt-ubuntu-18/docker.yml

diff --git a/guests/dockerfile-generator b/guests/dockerfile-generator
new file mode 100755
index 0000000..e1212da
--- /dev/null
+++ b/guests/dockerfile-generator
@@ -0,0 +1,72 @@
+#!/usr/bin/env python3
+
+import sys
+import yaml
+
+if len(sys.argv) < 2:
+    print("Usage: {} GUEST".format(sys.argv[0]))
+    sys.exit(1)
+
+guest = sys.argv[1]
+
+# Load data
+
+with open("vars/mappings.yml", "r") as f:
+    mappings = yaml.load(f)
+    mappings = mappings["mappings"]
+
+with open("host_vars/{}/main.yml".format(guest), "r") as f:
+    main = yaml.load(f)
+    package_format = main["package_format"]
+    os_name = main["os_name"]
+    os_version = main["os_version"]
+    os_full = "{}{}".format(os_name, os_version)
+
+with open("host_vars/{}/docker.yml".format(guest), "r") as f:
+    docker = yaml.load(f)
+    docker_base = docker["docker_base"]
+
+projects = ["base", "libvirt"]
+if os_name == "Fedora" and os_version == "Rawhide":
+    projects += ["libvirt+mingw"]
+
+# Process mappings
+
+temp = {}
+
+for project in projects:
+    with open("vars/projects/{}.yml".format(project), "r") as f:
+        packages = yaml.load(f)
+        packages = packages["packages"]
+    for package in packages:
+        if "default" in mappings[package]:
+            temp[package] = mappings[package]["default"]
+        if package_format in mappings[package]:
+            temp[package] = mappings[package][package_format]
+        if os_name in mappings[package]:
+            temp[package] = mappings[package][os_name]
+        if os_full in mappings[package]:
+            temp[package] = mappings[package][os_full]
+
+flattened = []
+
+for item in temp:
+    if temp[item] != None and temp[item] not in flattened:
+        flattened += [ temp[item] ]
+
+# Output Dockerfile
+
+print("FROM {}".format(docker_base))
+
+sys.stdout.write("ENV PACKAGES ")
+print(" \\\n             ".join(sorted(flattened)))
+
+if package_format == "deb":
+    print("RUN apt-get update && \\")
+    print("    apt-get install -y ${PACKAGES} && \\")
+    print("    apt-get autoremove -y && \\")
+    print("    apt-get autoclean -y")
+elif package_format == "rpm":
+    print("RUN yum install -y ${PACKAGES} && \\")
+    print("    yum autoremove -y && \\")
+    print("    yum clean all -y")
diff --git a/guests/host_vars/libvirt-centos-7/docker.yml b/guests/host_vars/libvirt-centos-7/docker.yml
new file mode 100644
index 0000000..59f7f12
--- /dev/null
+++ b/guests/host_vars/libvirt-centos-7/docker.yml
@@ -0,0 +1,2 @@
+---
+docker_base: centos:centos7
diff --git a/guests/host_vars/libvirt-debian-8/docker.yml b/guests/host_vars/libvirt-debian-8/docker.yml
new file mode 100644
index 0000000..235f0fd
--- /dev/null
+++ b/guests/host_vars/libvirt-debian-8/docker.yml
@@ -0,0 +1,2 @@
+---
+docker_base: debian:8
diff --git a/guests/host_vars/libvirt-debian-9/docker.yml b/guests/host_vars/libvirt-debian-9/docker.yml
new file mode 100644
index 0000000..0b4ccee
--- /dev/null
+++ b/guests/host_vars/libvirt-debian-9/docker.yml
@@ -0,0 +1,2 @@
+---
+docker_base: debian:9
diff --git a/guests/host_vars/libvirt-debian-sid/docker.yml b/guests/host_vars/libvirt-debian-sid/docker.yml
new file mode 100644
index 0000000..e20a37e
--- /dev/null
+++ b/guests/host_vars/libvirt-debian-sid/docker.yml
@@ -0,0 +1,2 @@
+---
+docker_base: debian:sid
diff --git a/guests/host_vars/libvirt-fedora-27/docker.yml b/guests/host_vars/libvirt-fedora-27/docker.yml
new file mode 100644
index 0000000..dcada18
--- /dev/null
+++ b/guests/host_vars/libvirt-fedora-27/docker.yml
@@ -0,0 +1,2 @@
+---
+docker_base: fedora:27
diff --git a/guests/host_vars/libvirt-fedora-28/docker.yml b/guests/host_vars/libvirt-fedora-28/docker.yml
new file mode 100644
index 0000000..a874018
--- /dev/null
+++ b/guests/host_vars/libvirt-fedora-28/docker.yml
@@ -0,0 +1,2 @@
+---
+docker_base: fedora:28
diff --git a/guests/host_vars/libvirt-fedora-rawhide/docker.yml b/guests/host_vars/libvirt-fedora-rawhide/docker.yml
new file mode 100644
index 0000000..39dda1c
--- /dev/null
+++ b/guests/host_vars/libvirt-fedora-rawhide/docker.yml
@@ -0,0 +1,2 @@
+---
+docker_base: fedora:rawhide
diff --git a/guests/host_vars/libvirt-ubuntu-16/docker.yml b/guests/host_vars/libvirt-ubuntu-16/docker.yml
new file mode 100644
index 0000000..2d4eb25
--- /dev/null
+++ b/guests/host_vars/libvirt-ubuntu-16/docker.yml
@@ -0,0 +1,2 @@
+---
+docker_base: ubuntu:16.04
diff --git a/guests/host_vars/libvirt-ubuntu-18/docker.yml b/guests/host_vars/libvirt-ubuntu-18/docker.yml
new file mode 100644
index 0000000..13d6cc1
--- /dev/null
+++ b/guests/host_vars/libvirt-ubuntu-18/docker.yml
@@ -0,0 +1,2 @@
+---
+docker_base: ubuntu:18.04
-- 
2.17.1

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux