Allow modules to be installed from source

This patch adds logic that can be used to clone
modules from remote git repositories and set the
resulting local repos to a know revision.

This logic has been added to make it easier to
decouple modules that are currently included as
a part of config into their own repos. Allowing
source installation will allow for edits of these
modules to be consumed more easily (without requiring
an additional release to the forge).

Additionally, this patch removes the puppet forge
installation logic that was installing without deps.
If modules are needed without their dependencies, they
can be installed from source to limit the amounts of ways
that modules can be installed.

Change-Id: I6e25cd65569f82bd5b0ef7d00b32e93ecdda3d71
This commit is contained in:
Dan 2014-05-28 22:47:05 -04:00
parent 271bb5bf70
commit ba3eb9f791
1 changed files with 35 additions and 16 deletions

View File

@ -14,8 +14,9 @@ function remove_module {
# Array of modules to be installed key:value is module:version.
declare -A MODULES
# These modules will be installed without dependency resolution
declare -A NONDEP_MODULES
# Array of modues to be installed from source and without dependency resolution.
# key:value is source location, revision to checkout
declare -A SOURCE_MODULES
#NOTE: if we previously installed kickstandproject-ntp we nuke it here
# since puppetlabs-ntp and kickstandproject-ntp install to the same dir
@ -54,14 +55,14 @@ MODULES["puppetlabs-firewall"]="0.0.4"
MODULES["puppetlabs-puppetdb"]="3.0.1"
MODULES["stankevich-python"]="1.6.6"
NONDEP_MODULES["nibalizer-puppetboard"]="2.3.0"
SOURCE_MODULES["https://github.com/nibalizer/puppet-module-puppetboard"]="2.4.0"
MODULE_LIST=`puppet module list`
# Transition away from old things
if [ -d /etc/puppet/modules/vcsrepo/.git ]
then
rm -rf /etc/puppet/modules/vcsrepo
rm -rf /etc/puppet/modules/vcsrepo
fi
# Install all the modules
@ -80,18 +81,36 @@ done
MODULE_LIST=`puppet module list`
# Make a second pass, installing all modules without their dependencies
for MOD in ${!NONDEP_MODULES[*]} ; do
# If the module at the current version does not exist upgrade or install it.
if ! echo $MODULE_LIST | grep "$MOD ([^v]*v${NONDEP_MODULES[$MOD]}" >/dev/null 2>&1
then
# Attempt module upgrade. If that fails try installing the module.
if ! puppet module upgrade $MOD --ignore-dependencies --version \
${NONDEP_MODULES[$MOD]} >/dev/null 2>&1
then
# This will get run in cron, so silence non-error output
puppet module install $MOD --ignore-dependencies --version \
${NONDEP_MODULES[$MOD]} >/dev/null 2>&1
# Make a second pass, just installing modules from source
for MOD in ${!SOURCE_MODULES[*]} ; do
# get the name of the module directory
if [ `echo $MOD | awk -F. '{print $NF}'` = 'git' ]; then
echo "Remote repos of the form repo.git are not supported: ${MOD}"
exit 1
fi
MODULE_NAME=`echo $MOD | awk -F- '{print $NF}'`
# set up git base command to use the correct path
GIT_CMD_BASE="git --git-dir=${MODULE_PATH}/${MODULE_NAME}/.git --work-tree ${MODULE_PATH}/${MODULE_NAME}"
# treat any occurrence of the module as a match
if ! echo $MODULE_LIST | grep "${MODULE_NAME}" >/dev/null 2>&1; then
# clone modules that are not installed
git clone $MOD "${MODULE_PATH}/${MODULE_NAME}"
else
if [ ! -d ${MODULE_PATH}/${MODULE_NAME}/.git ]; then
echo "Found directory ${MODULE_PATH}/${MODULE_NAME} that is not a git repo, deleting it and reinstalling from source"
remove_module $MODULE_NAME
git clone $MOD "${MODULE_PATH}/${MODULE_NAME}"
elif [ `${GIT_CMD_BASE} remote show origin | grep 'Fetch URL' | awk -F'URL: ' '{print $2}'` != $MOD ]; then
echo "Found remote in ${MODULE_PATH}/${MODULE_NAME} that does not match desired remote ${MOD}, deleting dir and re-cloning"
remove_module $MODULE_NAME
git clone $MOD "${MODULE_PATH}/${MODULE_NAME}"
fi
fi
# make sure the correct revision is installed, I have to use rev-list b/c rev-parse does not work with tags
if [ `${GIT_CMD_BASE} rev-list HEAD --max-count 1` != `${GIT_CMD_BASE} rev-list ${SOURCE_MODULES[$MOD]} --max-count 1` ]; then
# fetch the latest refs from the repo
$GIT_CMD_BASE fetch
# checkout correct revision
$GIT_CMD_BASE checkout ${SOURCE_MODULES[$MOD]}
fi
done