puppet-openstack-integration/generate_puppetfile.sh
Emilien Macchi d4666d130a Implement a script to generate Puppetfile
* Implement generate_puppetfile.sh
This script will read from openstack_modules.txt and
external_modules.txt that contain the list of Puppet modules we rely to
run our CI. It will build a Puppetfile by using master for Puppet
OpenStack modules and the latest tag for external modules.

* Remove Puppetfile, that is not useful anymore since it's generated.

* Run the script everytime our CI needs to install modules.
Which means our CI will always test the latests versions of our external
modules.

* Allow to pin modules.
Example:
puppetlabs/puppetlabs-apache,1.8.1

Change-Id: I2d529cc16b335d112f996c9f1f0266f440eab065
2016-04-07 10:06:03 -04:00

58 lines
1.6 KiB
Bash
Executable File

#!/bin/bash
#
# Build a Puppetfile with latest dependencies
#
# cleanup
rm -rf modules Puppetfile
mkdir modules
# header
echo -e "# Auto-generated Puppetfile for Puppet OpenStack project\n" > Puppetfile
# OpenStack Modules
echo "## OpenStack modules" >> Puppetfile
for p in $(cat openstack_modules.txt); do
# hack for puppet-openstack-integration
# where namespace is openstack_integration
title=$(echo $p | sed 's/-/_/g')
# TODO(emilien) we need to add support for stable branches
cat >> Puppetfile <<EOF
mod '$title',
:git => 'https://git.openstack.org/openstack/puppet-$p',
:ref => 'master'
EOF
done
# External Modules
echo -e "## External modules" >> Puppetfile
for e in $(cat external_modules.txt); do
namespace=$(echo $e | awk -F'/' '{print $1}' | cut -d "," -f 1)
module=$(echo $e | awk -F'/' '{print $2}' | cut -d "," -f 1)
title=$(echo $module | awk -F'/' '{print $1}' | cut -d "-" -f 2)
pin=$(echo $e | grep "," | cut -d "," -f 2)
if [ ! -z "$pin" ]; then
git ls-remote --exit-code https://github.com/$namespace/$module $pin
if (($? == 2)); then
echo "Wrong pin: $pin does not exist in $module module."
exit 1
else
tag=$pin
fi
else
git clone https://github.com/$namespace/$module modules/$module
tag=$(cd modules/$module; git describe --tags $(git rev-list --tags --max-count=1))
rm -rf modules/$module
fi
cat >> Puppetfile <<EOF
mod '$title',
:git => 'https://github.com/$namespace/$module',
:ref => '$tag'
EOF
done
# for debug
cat Puppetfile