Merge "Add zypper-minimal element"

This commit is contained in:
Jenkins 2016-10-18 16:24:07 +00:00 committed by Gerrit Code Review
commit e0f7b6c6d6
5 changed files with 146 additions and 0 deletions

View File

@ -0,0 +1,19 @@
==============
zypper-minimal
==============
Base element for creating minimal SUSE-based images
This element is incomplete by itself so you probaby want to use it along
with the opensuse-minimal one. It requires 'zypper' to be installed on the
host.
Repositories
------------
This element expects the `ZYPPER_REPOS` variable to be exported by the
operating system element. This variable contains repository mappings in
the following format: `${repo_name}==>${repo_url}`. For example::
ZYPPER_REPOS="update=>http://download.opensuse.org/update/leap/42.1/oss/ "
ZYPPER_REPOS+="oss=>http://download.opensuse.org/distribution/leap/42.1/repo/oss/"
export ZYPPER_REPOS

View File

@ -0,0 +1,3 @@
dib-run-parts
package-installs
zypper

View File

@ -0,0 +1,27 @@
#!/bin/bash
#
# Copyright 2015 Hewlett-Packard Development Company, L.P.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
if [ "${DIB_DEBUG_TRACE:-0}" -gt 0 ]; then
set -x
fi
set -eu
set -o pipefail
cat << EOF > /etc/fstab
proc /proc proc nodev,noexec,nosuid 0 0
LABEL=${DIB_ROOT_LABEL} / ${FS_TYPE} errors=remount-ro 0 1
EOF

View File

@ -0,0 +1,10 @@
# kernel
linux-image-generic:
# And a few useful tools. Some are pulled
# as dependencies but that may change so lets
# be explicit.
bash:
lsb-release:
openssl:
sed:
sudo:

View File

@ -0,0 +1,87 @@
#!/bin/bash
#
# Copyright 2016 SUSE Linux Products Gmb
# Copyright 2015 Hewlett-Packard Development Company, L.P.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
# dib-lint: disable=safe_sudo
if [ "${DIB_DEBUG_TRACE:-0}" -gt 0 ]; then
set -x
fi
set -eu
set -o pipefail
[ -n "${ZYPPER_REPOS}" ]
function cleanup() {
sudo umount $TMP_MOUNT_PATH/var/cache/zypp
}
trap cleanup EXIT
ZYPPER_TARGET_OPTS="--non-interactive --gpg-auto-import-keys --root $TARGET_ROOT"
ZYPPER_INSTALL_OPTS="--no-confirm --no-recommends"
for repo in ${ZYPPER_REPOS}; do
reponame=repo-${repo%%=>*}
repouri=${repo##*=>}
sudo zypper ${ZYPPER_TARGET_OPTS} addrepo --name ${reponame} --keep-packages ${repouri} ${reponame}
done
# Refresh it
sudo zypper ${ZYPPER_TARGET_OPTS} refresh
# It appears that zypper will clean up the repo's cache when it (re-)adds the
# repo so we need to add the cache now, once the repos are added. This is
# similar to what the zypper/50-zypper-cache script does
ZYPPER_CACHE_DIR=$DIB_IMAGE_CACHE/zypper
mkdir -p $ZYPPER_CACHE_DIR
sudo mkdir -p $TMP_MOUNT_PATH/var/cache/zypp
sudo mount --bind $ZYPPER_CACHE_DIR $TMP_MOUNT_PATH/var/cache/zypp
# Install filesystem, base and useful tools
sudo zypper ${ZYPPER_TARGET_OPTS} install ${ZYPPER_INSTALL_OPTS} filesystem
# Install basic components in order
sudo zypper ${ZYPPER_TARGET_OPTS} install ${ZYPPER_INSTALL_OPTS} -t pattern base
# Install a few useful tools
sudo zypper ${ZYPPER_TARGET_OPTS} install ${ZYPPER_INSTALL_OPTS} python zypper
# Put in a dummy /etc/resolv.conf over the temporary one we used
# to bootstrap. systemd has a bug/feature [1] that it will assume
# you want systemd-networkd as the network manager and create a
# broken symlink to /run/... if the base image doesn't have one.
# This broken link confuses things like dhclient.
# [1] https://bugzilla.redhat.com/show_bug.cgi?id=1197204
echo -e "# This file intentionally left blank\n" | \
sudo tee $TARGET_ROOT/etc/resolv.conf
# set the most reliable UTF-8 locale
echo -e 'LANG="en_US.UTF-8"' | \
sudo tee $TARGET_ROOT/etc/locale.conf
# default to UTC
sudo -E chroot $TARGET_ROOT ln -sf /usr/share/zoneinfo/UTC \
/etc/localtime
# RPM doesn't know whether files have been changed since install
# At this point though, we know for certain that we have changed no
# config files, so anything marked .rpmnew is just a bug.
for newfile in $(sudo find $TARGET_ROOT -type f -name '*rpmnew') ; do
sudo mv $newfile $(echo $newfile | sed 's/.rpmnew$//')
done
# Unmounting of the /var/cache/zypp is handled by the cleanup EXIT
# handler so there is nothing else to do here