#!/bin/bash -l

set -e

unset RUBYOPT
export BUNDLE_WITHOUT="test:development"

version_number=${GO_PIPELINE_COUNTER-0}
revision=`git rev-parse HEAD`
build_date=`date +'%Y-%m-%d %H:%M %z'`

cat > public/version <<EOT
{
  "version":"$version_number",
  "buildDate":"$build_date",
  "gitRevision":"$revision"
}
EOT

cp config/database{,-original}.yml
cp config/database{-ci,}.yml

echo "Cleaning temporary files"
echo "----"
rm -rf public/assets vendor/cache coverage log/* tmp/*

echo "Running Bundle package"
echo "----"
bundle package --all

echo "Precompiling assets"
echo "----"
RAILS_ENV=production RAILS_GROUPS=assets rake assets:precompile

echo "Creating RPM"
echo "----"
cd ..
/usr/local/rpm_builder/create-rails-rpm $artifact_name $artifact_name $version

#prune packaged gems
rm -rf vendor/cache

cp config/database{-original,}.yml
#!/bin/bash -l

set -e

unset RUBYOPT
export BUNDLE_WITHOUT="test:development"

version_number=${GO_PIPELINE_COUNTER-0}
revision=`git rev-parse HEAD`
build_date=`date +'%Y-%m-%d %H:%M %z'`

cat > public/version <<EOT
{
  "version":"$version_number",
  "buildDate":"$build_date",
  "gitRevision":"$revision"
}
EOT

cp config/database{-ci,}.yml

echo "Cleaning temporary files"
echo "----"
rm -rf public/assets vendor/cache coverage log/* tmp/*

echo "Running Bundle package"
echo "----"
bundle package --all

echo "Precompiling assets"
echo "----"
RAILS_ENV=production RAILS_GROUPS=assets rake assets:precompile

echo "Creating RPM"
echo "----"
cd ..
/usr/local/rpm_builder/create-rails-rpm $artifact_name $artifact_name $version

#prune packaged gems
rm -rf vendor/cache

--- 
+++ 
@@ -17,7 +17,6 @@
 }
 EOT
 
-cp config/database{,-original}.yml
 cp config/database{-ci,}.yml
 
 echo "Cleaning temporary files"
@@ -39,5 +38,3 @@
 
 #prune packaged gems
 rm -rf vendor/cache
-
-cp config/database{-original,}.yml
Build process restores original database.yml
