WIP: Move CI scripts to their own folder

This commit is contained in:
Rohan Mitchell
2015-04-22 14:29:59 +10:00
parent 6c81109b17
commit 883a2e0a0e
6 changed files with 0 additions and 0 deletions

6
script/ci/includes.sh Normal file
View File

@@ -0,0 +1,6 @@
function exit_unless_master_merged {
if [[ `git branch -a --merged origin/$BUILDKITE_BRANCH` != *origin/master* ]]; then
echo "This branch does not have the current master merged. Please merge master and push again."
exit 1
fi
}

View File

@@ -0,0 +1,26 @@
#!/bin/bash
# Every time staging is deployed, we load a baseline data set before running the new code's
# migrations. This script loads the baseline data set, after first taking a backup of the
# current database.
set -e
cd /home/openfoodweb/apps/openfoodweb/current
echo "Stopping unicorn..."
service unicorn_openfoodweb stop
echo "Backing up current data..."
mkdir -p db/backup
pg_dump -h localhost -U openfoodweb openfoodweb_production |gzip > db/backup/staging-`date +%Y%m%d%H%M%S`.sql.gz
echo "Loading baseline data..."
dropdb -U openfoodweb -w openfoodweb_production
createdb -U openfoodweb -w openfoodweb_production
gunzip -c db/backup/staging-baseline.sql.gz |psql -h localhost -U openfoodweb openfoodweb_production
echo "Restarting unicorn..."
service unicorn_openfoodweb start
echo "Done!"

15
script/ci/push_to_production.sh Executable file
View File

@@ -0,0 +1,15 @@
#!/bin/bash
set -e
# Add production git remote if required
PROD_TEST=`git remote | grep -s 'production' || true`
if [[ "$PROD_TEST" != *production* ]]; then
git remote add production ubuntu@ofn-prod:apps/openfoodweb/current
fi
echo "--- Saving baseline data for staging"
ssh ofn-staging2 "/home/openfoodweb/apps/openfoodweb/current/script/save_staging_baseline.sh $BUILDKITE_COMMIT"
echo "--- Pushing to production"
[[ $(git push production $BUILDKITE_COMMIT:master --force 2>&1) =~ "Done" ]]

19
script/ci/push_to_staging.sh Executable file
View File

@@ -0,0 +1,19 @@
#!/bin/bash
set -e
source ./script/includes.sh
# Add staging git remote if required
ST2_TEST=`git remote | grep -s 'staging2' || true`
if [[ "$ST2_TEST" != *staging2* ]]; then
git remote add staging2 openfoodweb@ofn-staging2:apps/openfoodweb/current
fi
echo "--- Verifying branch is based on current master"
exit_unless_master_merged
echo "--- Loading baseline data"
ssh ofn-staging2 "/home/openfoodweb/apps/openfoodweb/current/script/load_staging_baseline.sh"
echo "--- Pushing to staging"
[[ $(git push staging2 $BUILDKITE_COMMIT:master --force 2>&1) =~ "Done" ]]

22
script/ci/run_tests.sh Executable file
View File

@@ -0,0 +1,22 @@
#!/bin/bash
set -e
echo "--- Loading environment"
source ./script/includes.sh
source /var/lib/jenkins/.rvm/environments/ruby-1.9.3-p392
if [ ! -f config/application.yml ]; then
ln -s application.yml.example config/application.yml
fi
echo "--- Verifying branch is based on current master"
exit_unless_master_merged
echo "--- Bundling"
bundle install
echo "--- Preparing test database"
bundle exec rake db:test:prepare
echo "--- Running tests"
bundle exec rspec spec --format progress

View File

@@ -0,0 +1,20 @@
#!/bin/bash
# Every time staging is deployed, we load a baseline data set before running the new code's
# migrations. This script saves a new baseline data set for that purpose.
# This script is called remotely on a push to production. We only want to save a new baseline
# if the code in staging is identical to that in production. To accomplish that, we take the
# production commit SHA as a parameter ($1) and only perform the save if the SHA matches the
# current code checked out.
set -e
cd /home/openfoodweb/apps/openfoodweb/current
if [[ `git rev-parse HEAD` == $1 ]]; then
mkdir -p db/backup
pg_dump -h localhost -U openfoodweb openfoodweb_production |gzip > db/backup/staging-baseline.sql.gz
echo "Staging baseline data saved."
else
echo "Staging SHA does not match production, we will not save staging baseline data."
fi