Browse code

New features in mkimage-yum.sh script

Added -g and -p options for the contrib/mkimage-yum.sh script to allow generating images with the dependencies you want. I use this because I generate images where I only need "glibc" with its dependencies or "java-1.8.0-openjdk-headless" and so on. This makes sure that I don't get a lot of bogus packages from the Core group.

Possible usages now include sudo ./mkimage-yum.sh -y yum.conf -g '' -p java-1.8.0-openjdk-headless.

Also changed the "test" at the end to add --rm parameter to docker run so it doesn't leave a junk container and use bash to echo "success" in case you don't get coreutils in your dependencies tree.

Signed-off-by: Florin Asavoaie <florin.asavoaie@gmail.com>

Florin Asavoaie authored on 2015/12/20 21:20:30
Showing 1 changed files
... ...
@@ -10,8 +10,12 @@ usage() {
10 10
     cat <<EOOPTS
11 11
 $(basename $0) [OPTIONS] <name>
12 12
 OPTIONS:
13
-  -y <yumconf>  The path to the yum config to install packages from. The
14
-                default is /etc/yum.conf for Centos/RHEL and /etc/dnf/dnf.conf for Fedora
13
+  -p "<packages>"  The list of packages to install in the container.
14
+                   The default is blank.
15
+  -g "<groups>"    The groups of packages to install in the container.
16
+                   The default is "Core".
17
+  -y <yumconf>     The path to the yum config to install packages from. The
18
+                   default is /etc/yum.conf for Centos/RHEL and /etc/dnf/dnf.conf for Fedora
15 19
 EOOPTS
16 20
     exit 1
17 21
 }
... ...
@@ -21,8 +25,9 @@ yum_config=/etc/yum.conf
21 21
 if [ -f /etc/dnf/dnf.conf ] && command -v dnf &> /dev/null; then
22 22
 	yum_config=/etc/dnf/dnf.conf
23 23
 	alias yum=dnf
24
-fi 
25
-while getopts ":y:h" opt; do
24
+fi
25
+install_groups="Core"
26
+while getopts ":y:p:g:h" opt; do
26 27
     case $opt in
27 28
         y)
28 29
             yum_config=$OPTARG
... ...
@@ -30,6 +35,12 @@ while getopts ":y:h" opt; do
30 30
         h)
31 31
             usage
32 32
             ;;
33
+        p)
34
+            install_packages="$OPTARG"
35
+            ;;
36
+        g)
37
+            install_groups="$OPTARG"
38
+            ;;
33 39
         \?)
34 40
             echo "Invalid option: -$OPTARG"
35 41
             usage
... ...
@@ -65,8 +76,18 @@ if [ -d /etc/yum/vars ]; then
65 65
 	cp -a /etc/yum/vars "$target"/etc/yum/
66 66
 fi
67 67
 
68
-yum -c "$yum_config" --installroot="$target" --releasever=/ --setopt=tsflags=nodocs \
69
-    --setopt=group_package_types=mandatory -y groupinstall Core
68
+if [[ -n "$install_groups" ]];
69
+then
70
+    yum -c "$yum_config" --installroot="$target" --releasever=/ --setopt=tsflags=nodocs \
71
+        --setopt=group_package_types=mandatory -y groupinstall $install_groups
72
+fi
73
+
74
+if [[ -n "$install_packages" ]];
75
+then
76
+    yum -c "$yum_config" --installroot="$target" --releasever=/ --setopt=tsflags=nodocs \
77
+        --setopt=group_package_types=mandatory -y install $install_packages
78
+fi
79
+
70 80
 yum -c "$yum_config" --installroot="$target" -y clean all
71 81
 
72 82
 cat > "$target"/etc/sysconfig/network <<EOF
... ...
@@ -108,6 +129,6 @@ fi
108 108
 
109 109
 tar --numeric-owner -c -C "$target" . | docker import - $name:$version
110 110
 
111
-docker run -i -t $name:$version echo success
111
+docker run -i -t --rm $name:$version /bin/bash -c 'echo success'
112 112
 
113 113
 rm -rf "$target"