diff --git a/README.md b/README.md index 7bd7c550..c393c8c3 100644 --- a/README.md +++ b/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 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. + 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 +-package-install or -source-install. + +To set the install type for an element define an environment variable +DIB_INSTALLTYPE_. 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 --------------------- diff --git a/elements/base/extra-data.d/99-enable-install-types b/elements/base/extra-data.d/99-enable-install-types new file mode 100755 index 00000000..d1e097d9 --- /dev/null +++ b/elements/base/extra-data.d/99-enable-install-types @@ -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 diff --git a/elements/source-repositories/extra-data.d/98-source-repositories b/elements/source-repositories/extra-data.d/98-source-repositories index f9ef86ee..6f417fc7 100755 --- a/elements/source-repositories/extra-data.d/98-source-repositories +++ b/elements/source-repositories/extra-data.d/98-source-repositories @@ -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