Move install type enablement into base element
Move whether the package or source install type is enabled out of the source-repositories element and into the base element. source-repositories wasn't a great fit for this functionality to begin with. Specify the install type for an element via the DIB_INSTALLTYPE_<install_dir_prefix> environment variable. Additionally with this approach, any new install type can be added in an element, without having to update source-repositories or anything in dib. You could just write your install type implementation under nova-foo-install, then define DIB_INSTALLTYPE_nova=foo in your environment, and the scripts under nova-foo-install would get run during the image build. Source installs (any scripts under <install_dir_prefix>-source-install) is the default install type for all elements. Change-Id: I9414aca360c41e030e27d3d0c0a52d9d8e13d8b1
This commit is contained in:
parent
14140ae180
commit
b4dfa6cb90
36
README.md
36
README.md
@ -107,6 +107,42 @@ source-repositories
|
||||
Git repositories and tarballs obtained via the source-repositories element will
|
||||
be cached.
|
||||
|
||||
Install Types
|
||||
-------------
|
||||
|
||||
Install types permit elements to be installed from different sources, such as
|
||||
git repositories, distribution packages, or pip.
|
||||
|
||||
Many elements expose different install types. The different implementations
|
||||
live under <install-dir-prefix>-<install-type>-install directories under an
|
||||
element's install.d. The base element enables the chosen install type by
|
||||
symlinking the correct hook scripts under install.d directly.
|
||||
<install-dir-prefix> can be a string of alphanumeric and '-' characters, but
|
||||
typically corresponds to the element name.
|
||||
|
||||
For example, the nova element would provide:
|
||||
|
||||
nova/install.d/nova-package-install/74-nova
|
||||
nova/install.d/nova-source-install/74-nova
|
||||
|
||||
The following symlink would be created for the package install type:
|
||||
|
||||
install.d/74-nova -> nova-package-install/74-nova
|
||||
|
||||
Or, for the source install type:
|
||||
|
||||
install.d/74-nova -> nova-source-install/74-nova
|
||||
|
||||
All other scripts that exist under install.d for an element will be executed as
|
||||
normal. This allows common install code to live in a script outside of
|
||||
<install-dir-prefix>-package-install or <install-dir-prefix>-source-install.
|
||||
|
||||
To set the install type for an element define an environment variable
|
||||
DIB_INSTALLTYPE_<install_dir_prefx>. Note that if you used '-' characters in
|
||||
your install directory prefix, those need to be replaced with '_' in the
|
||||
environment variable.
|
||||
|
||||
|
||||
C and C++ compilation
|
||||
---------------------
|
||||
|
||||
|
71
elements/base/extra-data.d/99-enable-install-types
Executable file
71
elements/base/extra-data.d/99-enable-install-types
Executable file
@ -0,0 +1,71 @@
|
||||
#!/bin/bash
|
||||
# Copyright 2014 Red Hat, Inc.
|
||||
# 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 -eux
|
||||
|
||||
declare -a SPECIFIED_ELEMS
|
||||
|
||||
# Add a blank first element to the array, since we're running with -u, we don't
|
||||
# want an unbound variable error if no element install types were specified.
|
||||
SPECIFIED_ELEMS[0]=""
|
||||
|
||||
# List of all env vars to set install types
|
||||
PREFIX="DIB_INSTALLTYPE_"
|
||||
INSTALL_TYPE_VARS=$(env | grep ^$PREFIX | cut -d'=' -f1)
|
||||
|
||||
for _install_type_var in $INSTALL_TYPE_VARS; do
|
||||
|
||||
# Get the element name and its install type
|
||||
INSTALLDIRPREFIX=${_install_type_var:${#PREFIX}}
|
||||
INSTALLDIRPREFIX=${INSTALLDIRPREFIX//_/-}
|
||||
eval INSTALLTYPE=\$$_install_type_var
|
||||
|
||||
# Create symlink for correct install type
|
||||
pushd $TMP_HOOKS_PATH/install.d
|
||||
if [ -d $INSTALLDIRPREFIX-$INSTALLTYPE-install ]; then
|
||||
ln -sf $INSTALLDIRPREFIX-$INSTALLTYPE-install/* .
|
||||
fi
|
||||
popd
|
||||
|
||||
SPECIFIED_ELEMS+=($INSTALLDIRPREFIX)
|
||||
|
||||
done
|
||||
|
||||
# For any existing *-source-install directory under install.d, if an
|
||||
# environment variable setting a different install type was not seen, enable
|
||||
# the source install type.
|
||||
source_install_dirs=$(ls -d $TMP_HOOKS_PATH/install.d/*-source-install || true)
|
||||
for _source_install_dir in $source_install_dirs; do
|
||||
SUFFIX="-source-install"
|
||||
_source_install_dir=$(basename $_source_install_dir)
|
||||
INSTALLDIRPREFIX=${_source_install_dir%$SUFFIX}
|
||||
|
||||
found=0
|
||||
for specified in ${SPECIFIED_ELEMS[@]}; do
|
||||
if [ "$specified" = "$INSTALLDIRPREFIX" ]; then
|
||||
found=1
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
# install type not specified, assume source
|
||||
if [ "$found" = "0" ]; then
|
||||
pushd $TMP_HOOKS_PATH/install.d
|
||||
ln -sf $_source_install_dir/* .
|
||||
popd
|
||||
fi
|
||||
done
|
@ -65,6 +65,14 @@ function get_repos_for_element(){
|
||||
CACHE_PATH=${CACHE_BASE}/$CACHE_NAME
|
||||
make_new_cache $OLD_CACHE_PATH $CACHE_PATH
|
||||
|
||||
# Return if install type is not source
|
||||
local INSTALL_TYPE_VAR=DIB_INSTALLTYPE_${REPONAME//[^A-Za-z0-9]/_}
|
||||
local INSTALL_TYPE=${!INSTALL_TYPE_VAR:-source}
|
||||
if [ ! $INSTALL_TYPE = "source" ]; then
|
||||
echo "$REPONAME install type not set to source"
|
||||
continue
|
||||
fi
|
||||
|
||||
case $REPOTYPE in
|
||||
git)
|
||||
if [ -z "${!REPOLOCATION_OVERRIDE:-""}" -a -n "${DIB_GITREPOBASE:-""}" ] ; then
|
||||
@ -136,9 +144,6 @@ function get_repos_for_element(){
|
||||
sudo curl $REPOLOCATION -o $REPO_DEST
|
||||
fi
|
||||
;;
|
||||
package)
|
||||
echo "$REPONAME set to package source type"
|
||||
;;
|
||||
*)
|
||||
echo "Unsupported repository type: $REPOTYPE"
|
||||
return 1
|
||||
@ -149,20 +154,6 @@ function get_repos_for_element(){
|
||||
# elements (like a pypi dependency cache).
|
||||
echo "$REPOPATH" | sudo dd of=$TMP_MOUNT_PATH/etc/dib-source-repositories oflag=append conv=notrunc
|
||||
|
||||
# Save the $REPOTYPE used so that it can be used later by install.d
|
||||
if [ "$REPOTYPE" = "package" ]; then
|
||||
REPOINSTALLTYPE="package"
|
||||
else
|
||||
REPOINSTALLTYPE="source"
|
||||
fi
|
||||
|
||||
# Create symlink for correct install type
|
||||
pushd $TMP_HOOKS_PATH/install.d
|
||||
if [ -e $REPONAME-$REPOINSTALLTYPE-install ]; then
|
||||
ln -sf $REPONAME-$REPOINSTALLTYPE-install/* .
|
||||
fi
|
||||
popd
|
||||
|
||||
else
|
||||
echo "Couldn't parse '$line' as a source repository"
|
||||
return 1
|
||||
|
Loading…
Reference in New Issue
Block a user