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>
This commit is contained in:
Florin Asavoaie 2015-12-20 14:20:30 +02:00
parent cc6f0df2e4
commit c8badcbd26
1 changed files with 28 additions and 7 deletions

View File

@ -10,8 +10,12 @@ usage() {
cat <<EOOPTS
$(basename $0) [OPTIONS] <name>
OPTIONS:
-y <yumconf> The path to the yum config to install packages from. The
default is /etc/yum.conf for Centos/RHEL and /etc/dnf/dnf.conf for Fedora
-p "<packages>" The list of packages to install in the container.
The default is blank.
-g "<groups>" The groups of packages to install in the container.
The default is "Core".
-y <yumconf> The path to the yum config to install packages from. The
default is /etc/yum.conf for Centos/RHEL and /etc/dnf/dnf.conf for Fedora
EOOPTS
exit 1
}
@ -21,8 +25,9 @@ yum_config=/etc/yum.conf
if [ -f /etc/dnf/dnf.conf ] && command -v dnf &> /dev/null; then
yum_config=/etc/dnf/dnf.conf
alias yum=dnf
fi
while getopts ":y:h" opt; do
fi
install_groups="Core"
while getopts ":y:p:g:h" opt; do
case $opt in
y)
yum_config=$OPTARG
@ -30,6 +35,12 @@ while getopts ":y:h" opt; do
h)
usage
;;
p)
install_packages="$OPTARG"
;;
g)
install_groups="$OPTARG"
;;
\?)
echo "Invalid option: -$OPTARG"
usage
@ -65,8 +76,18 @@ if [ -d /etc/yum/vars ]; then
cp -a /etc/yum/vars "$target"/etc/yum/
fi
yum -c "$yum_config" --installroot="$target" --releasever=/ --setopt=tsflags=nodocs \
--setopt=group_package_types=mandatory -y groupinstall Core
if [[ -n "$install_groups" ]];
then
yum -c "$yum_config" --installroot="$target" --releasever=/ --setopt=tsflags=nodocs \
--setopt=group_package_types=mandatory -y groupinstall $install_groups
fi
if [[ -n "$install_packages" ]];
then
yum -c "$yum_config" --installroot="$target" --releasever=/ --setopt=tsflags=nodocs \
--setopt=group_package_types=mandatory -y install $install_packages
fi
yum -c "$yum_config" --installroot="$target" -y clean all
cat > "$target"/etc/sysconfig/network <<EOF
@ -108,6 +129,6 @@ fi
tar --numeric-owner -c -C "$target" . | docker import - $name:$version
docker run -i -t $name:$version echo success
docker run -i -t --rm $name:$version /bin/bash -c 'echo success'
rm -rf "$target"