From 54c8508d45b63a89d5d6dc12b4c76d91e33c0921 Mon Sep 17 00:00:00 2001 From: Tim Serong Date: Fri, 11 Oct 2013 23:39:16 +1100 Subject: [PATCH] Add support for building openSUSE images This is currently experimental/incomplete. See elements/opensuse/README.md for details. Change-Id: Ie5bcab15c9703cf15ceb642fb986a8afc34f96fb Co-Authored-By: Ralf Haferkamp --- elements/opensuse/README.md | 26 +++++++++ elements/opensuse/bin/install-packages | 47 +++++++++++++++ elements/opensuse/bin/map-packages | 55 ++++++++++++++++++ elements/opensuse/element-deps | 2 + .../opensuse/extra-data.d/01-inject-defaults | 12 ++++ elements/opensuse/post-install.d/10-mkinitrd | 20 +++++++ .../opensuse/pre-install.d/01-install-bin | 3 + .../opensuse/root.d/10-opensuse-cloud-image | 58 +++++++++++++++++++ elements/vm/finalise.d/51-bootloader | 5 +- 9 files changed, 227 insertions(+), 1 deletion(-) create mode 100644 elements/opensuse/README.md create mode 100644 elements/opensuse/bin/install-packages create mode 100755 elements/opensuse/bin/map-packages create mode 100644 elements/opensuse/element-deps create mode 100755 elements/opensuse/extra-data.d/01-inject-defaults create mode 100755 elements/opensuse/post-install.d/10-mkinitrd create mode 100755 elements/opensuse/pre-install.d/01-install-bin create mode 100755 elements/opensuse/root.d/10-opensuse-cloud-image diff --git a/elements/opensuse/README.md b/elements/opensuse/README.md new file mode 100644 index 000000000..49e031b7d --- /dev/null +++ b/elements/opensuse/README.md @@ -0,0 +1,26 @@ +Use an openSUSE cloud image as the baseline for built disk images. The base +image is located here: + + http://download.opensuse.org/repositories/Cloud:/Images/images/ + +This image should currently be considered experimental. Right now, we've only +got a 64 bit image, and no 32 bit image. But it's a start. + +Notes: + +* The filename of the base image in the above repository is currently not + stable (e.g. it includes a build number and image version). A fix for that + will be rolled out to the repositories soon. A tempoary workaround to figure + out the correct filename has been added to root.d/10-opensuse-cloud-image. +* Building with DIB\_EXTLINUX=1 doesn't work. It fails with: + /tmp/in\_target.d/finalise.d/51-bootloader: line 14: 16286 Segmentation fault + extlinux --install /boot/syslinux + (https://bugzilla.novell.com/show_bug.cgi?id=852856) +* This element doesn't need half of the rpm-distro element's pre-install + hooks. The exceptions are 01-install-bin, which has been copied to + this element, and 01-override-zypp-arch (which is something that + could probably be jammed into the base image...). +* We might want to use the local-config element (after updating that element to + inject http\_proxy properly for openSUSE, of course). + (https://bugs.launchpad.net/diskimage-builder/+bug/1256982) + diff --git a/elements/opensuse/bin/install-packages b/elements/opensuse/bin/install-packages new file mode 100644 index 000000000..eac97b4e1 --- /dev/null +++ b/elements/opensuse/bin/install-packages @@ -0,0 +1,47 @@ +#!/bin/sh + +# Copyright 2013 SUSE Linux Products GmbH +# All Rights Reserved. +# +# 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. + +set -e + +function run_zypper() { + # TODO: Uncertain if this can ever block wanting input from user + zypper --non-interactive --gpg-auto-import-keys "$@" +} + +if [ "$1" = "-u" ] ; then + run_zypper dist-upgrade + exit 0 +elif [ "$1" = "-d" ] ; then + EXTRA_ARGS="--download-only" + shift +fi + +# Packages that aren't available in the distro but requested for installation +# can be ignored by adding them to the exclude list +BLACKLIST=(dkms) +WHITELIST=() +for i in "$@" +do + if [[ ! ${BLACKLIST[*]} =~ $i ]]; then + WHITELIST+="$i " + else + echo "The package $i is not available and will not be installed" + fi +done +if [ -n "$WHITELIST" ]; then + run_zypper install $EXTRA_ARGS $(map-packages $WHITELIST) +fi diff --git a/elements/opensuse/bin/map-packages b/elements/opensuse/bin/map-packages new file mode 100755 index 000000000..b55daf239 --- /dev/null +++ b/elements/opensuse/bin/map-packages @@ -0,0 +1,55 @@ +#!/usr/bin/env python + +# Copyright 2013 SUSE Linux Products GmbH +# All Rights Reserved. +# +# 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. + +import sys + +# Manually maintained for brevity; consider making this compiled from +# distromatch or other rich data sources. +# Debian name on the left, openSUSE on the right. +package_map = { + 'grub-pc': 'grub2', + 'linux-image-generic': 'kernel-default', + 'python-dev': 'python-devel', + 'libc6-dev': 'glibc-devel', + 'libxml2-dev': 'libxml2-devel', + 'libxslt-dev': 'libxslt-devel', + 'python-libvirt': 'libvirt-python', + 'libvirt-bin': 'libvirt', + 'python-memcache': 'python-python-memcached', + 'build-essential': 'make automake gcc gcc-c++ kernel-devel', + 'python-mysqldb': 'python-mysql', + 'openvswitch-common': 'openvswitch', + 'openvswitch-switch': 'openvswitch-switch', + 'libssl-dev': 'openssl-devel', + 'libz-dev': 'zlib-devel', + 'qemu-utils': 'qemu-tools', + 'python-pyopenssl': 'python-pyOpenSSL', + 'libmysqlclient-dev': 'libmysqlclient-devel', + 'arping': 'iputils', + 'augeas-tools': 'augeas', + 'openssh-client': 'openssh', + 'extlinux': 'syslinux', + 'mysql-client-5.5': 'mysql-community-server-client', + 'mysql-server-5.5': 'mysql-community-server', + 'libmysql-java': 'mysql-connector-java', + 'default-jre': 'java', # Will match 'java' as capability + 'atftpd': 'atftp', + } + +for arg in sys.argv[1:]: + print(package_map.get(arg, arg)) +sys.exit(0) diff --git a/elements/opensuse/element-deps b/elements/opensuse/element-deps new file mode 100644 index 000000000..5c6d5779f --- /dev/null +++ b/elements/opensuse/element-deps @@ -0,0 +1,2 @@ +cache-url +dib-run-parts diff --git a/elements/opensuse/extra-data.d/01-inject-defaults b/elements/opensuse/extra-data.d/01-inject-defaults new file mode 100755 index 000000000..d07abd061 --- /dev/null +++ b/elements/opensuse/extra-data.d/01-inject-defaults @@ -0,0 +1,12 @@ +#!/bin/bash + +set -e +set -x + +export OPENSUSE_EXTRAS_PATH="$TMP_MOUNT_PATH/tmp/opensuse-extras" +mkdir -p $OPENSUSE_EXTRAS_PATH + +for file in common-defaults img-defaults ; do + cp $_LIB/$file $OPENSUSE_EXTRAS_PATH +done + diff --git a/elements/opensuse/post-install.d/10-mkinitrd b/elements/opensuse/post-install.d/10-mkinitrd new file mode 100755 index 000000000..1c7b234dc --- /dev/null +++ b/elements/opensuse/post-install.d/10-mkinitrd @@ -0,0 +1,20 @@ +#!/bin/bash +# The base tbz-image created by kiwi does not contain an initrd so create one +# here. + +set -eu + +# To have access to FS_TYPE +_LIB="/tmp/opensuse-extras" +source $_LIB/img-defaults + +# This is to tell mkinitrd to include the right tools for the root filesystem +# that will actually be used for the final image. This is likely something +# different than what the chroot is currently on (which might currently be a +# tmpfs even). +echo "rootfstype=$FS_TYPE" > /etc/sysconfig/initrd + +mkinitrd -A + +# And cleanup again +rm /etc/sysconfig/initrd diff --git a/elements/opensuse/pre-install.d/01-install-bin b/elements/opensuse/pre-install.d/01-install-bin new file mode 100755 index 000000000..555bc782b --- /dev/null +++ b/elements/opensuse/pre-install.d/01-install-bin @@ -0,0 +1,3 @@ +#!/bin/sh + +install -m 0755 -o root -g root $(dirname $0)/../bin/* /usr/local/bin diff --git a/elements/opensuse/root.d/10-opensuse-cloud-image b/elements/opensuse/root.d/10-opensuse-cloud-image new file mode 100755 index 000000000..a57ac3b31 --- /dev/null +++ b/elements/opensuse/root.d/10-opensuse-cloud-image @@ -0,0 +1,58 @@ +#!/bin/bash + +set -eu + +[ -n "$ARCH" ] +[ -n "$TARGET_ROOT" ] + +if [ 'amd64' = "$ARCH" ] ; then + ARCH="x86_64" +fi + +if [ 'i386' = "$ARCH" ] ; then + ARCH="i586" +fi + +DIB_CLOUD_IMAGES=${DIB_CLOUD_IMAGES:-http://download.opensuse.org/repositories/Cloud:/Images/images/} +DIB_RELEASE=${DIB_RELEASE:-13.1} +# FIXME: Hard coded build numbers, versions, etc. +BASE_IMAGE_NAME=${BASE_IMAGE_NAME:-openSUSE-$DIB_RELEASE-OpenStack-Guest.$ARCH} + +if [ -z "$DIB_OFFLINE" ] ; then + # XXX: Try to extract the filename of the current built from the index + # page. As there is one built available in the repo at a given time, this + # should work. This is a tempoary workaround until the fix for + # https://bugzilla.novell.com/show_bug.cgi?id=853882 is deployed + echo "Looking up current built of Base Image ($BASE_IMAGE_NAME):" + BASE_IMAGE_FILE=${BASE_IMAGE_FILE:-$(curl $DIB_CLOUD_IMAGES | \ + sed -n "s/^.*\