From 22127b2d18ca2ae85107f778d59ad2c6a33995f8 Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Tue, 21 Apr 2015 15:10:05 +1000 Subject: [PATCH 01/12] Use progress formatter for less verbose CI output. I miss Fuubar formatter, though. --- script/run_tests.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/script/run_tests.sh b/script/run_tests.sh index 72d895c04e..461ca4ecd8 100755 --- a/script/run_tests.sh +++ b/script/run_tests.sh @@ -15,4 +15,4 @@ echo "--- Preparing test database" bundle exec rake db:test:prepare echo "--- Running tests" -bundle exec rspec spec -f d +bundle exec rspec spec --format progress From 9f93c9f2218ea9f4a66ca0d3b8e29190d81882c1 Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Tue, 21 Apr 2015 15:12:39 +1000 Subject: [PATCH 02/12] Swap Jenkins build badge out for Buildkite --- README.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.markdown b/README.markdown index 07f786a453..f43856daf6 100644 --- a/README.markdown +++ b/README.markdown @@ -1,4 +1,4 @@ -[![Build Status](http://ci.openfood.com.au:8080/buildStatus/icon?job=openfoodweb - tests)](http://ci.openfood.com.au:8080/job/openfoodweb%20-%20tests/) +[![Build status](https://badge.buildkite.com/e18473fffac95ed2735ca75700673bd301cac5cffc64de821a.svg?branch=master)](https://buildkite.com/open-food-foundation/open-food-network) [![Code Climate](https://codeclimate.com/github/openfoodfoundation/openfoodnetwork.png)](https://codeclimate.com/github/openfoodfoundation/openfoodnetwork) # Open Food Network From 35536a629ce2a6ee32fc74096c98af35f6c460d8 Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Wed, 22 Apr 2015 10:28:01 +1000 Subject: [PATCH 03/12] Set execute bit --- script/delayed_job.sh | 0 script/prepare_imported_db.rb | 0 script/save_staging_baseline.sh | 0 3 files changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 script/delayed_job.sh mode change 100644 => 100755 script/prepare_imported_db.rb mode change 100644 => 100755 script/save_staging_baseline.sh diff --git a/script/delayed_job.sh b/script/delayed_job.sh old mode 100644 new mode 100755 diff --git a/script/prepare_imported_db.rb b/script/prepare_imported_db.rb old mode 100644 new mode 100755 diff --git a/script/save_staging_baseline.sh b/script/save_staging_baseline.sh old mode 100644 new mode 100755 From 7d4a4f8f9d8885f87de4cbe8144b0bab0a4dc8fc Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Wed, 22 Apr 2015 12:37:06 +1000 Subject: [PATCH 04/12] Pushing to staging first loads staging baseline data --- script/load_staging_baseline.sh | 26 ++++++++++++++++++++++++++ script/push_to_staging.sh | 5 +++++ 2 files changed, 31 insertions(+) create mode 100644 script/load_staging_baseline.sh diff --git a/script/load_staging_baseline.sh b/script/load_staging_baseline.sh new file mode 100644 index 0000000000..0a59b66d3b --- /dev/null +++ b/script/load_staging_baseline.sh @@ -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!" diff --git a/script/push_to_staging.sh b/script/push_to_staging.sh index e3a16ebb3b..c2c176bb2a 100755 --- a/script/push_to_staging.sh +++ b/script/push_to_staging.sh @@ -2,9 +2,14 @@ set -e +# 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 "--- 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" ]] From d406f9ccdf599b630b547d4f6dba7ae4e3ffd6d3 Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Wed, 22 Apr 2015 13:14:51 +1000 Subject: [PATCH 05/12] Tests fail unless master has been merged into current branch --- script/includes.sh | 6 ++++++ script/run_tests.sh | 4 ++++ 2 files changed, 10 insertions(+) create mode 100644 script/includes.sh diff --git a/script/includes.sh b/script/includes.sh new file mode 100644 index 0000000000..1b0519f940 --- /dev/null +++ b/script/includes.sh @@ -0,0 +1,6 @@ +function exit_unless_master_merged { + if [[ `git branch -a --merged $BUILDKITE_BRANCH` != *origin/master* ]]; then + echo "This branch does not have the current master merged. Please merge master and push again." + exit 1 + fi +} diff --git a/script/run_tests.sh b/script/run_tests.sh index 461ca4ecd8..616d454e5d 100755 --- a/script/run_tests.sh +++ b/script/run_tests.sh @@ -3,11 +3,15 @@ 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 From 53c4c8b5b7f4b18ba3227b6330b08eea2b9cceaf Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Wed, 22 Apr 2015 13:16:39 +1000 Subject: [PATCH 06/12] Push to staging fails unless master has been merged into current branch --- script/push_to_staging.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/script/push_to_staging.sh b/script/push_to_staging.sh index c2c176bb2a..75bccd6e09 100755 --- a/script/push_to_staging.sh +++ b/script/push_to_staging.sh @@ -1,6 +1,7 @@ #!/bin/bash set -e +source ./script/includes.sh # Add staging git remote if required ST2_TEST=`git remote | grep -s 'staging2' || true` @@ -8,6 +9,9 @@ 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" From 1c9a95b3d6094e0dde6bfd5b49f6f51d2939b390 Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Wed, 22 Apr 2015 13:19:17 +1000 Subject: [PATCH 07/12] Set execute bit --- script/load_staging_baseline.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 script/load_staging_baseline.sh diff --git a/script/load_staging_baseline.sh b/script/load_staging_baseline.sh old mode 100644 new mode 100755 From 6c81109b17945167e171640e2daf88b99b0f0c50 Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Wed, 22 Apr 2015 14:17:07 +1000 Subject: [PATCH 08/12] Local branch isn't checked out, so we need to test remote branch --- script/includes.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/script/includes.sh b/script/includes.sh index 1b0519f940..06713fc773 100644 --- a/script/includes.sh +++ b/script/includes.sh @@ -1,5 +1,5 @@ function exit_unless_master_merged { - if [[ `git branch -a --merged $BUILDKITE_BRANCH` != *origin/master* ]]; then + 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 From 883a2e0a0e4fdda1909218aeb60d9cd6482ebe2c Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Wed, 22 Apr 2015 14:29:59 +1000 Subject: [PATCH 09/12] WIP: Move CI scripts to their own folder --- script/{ => ci}/includes.sh | 0 script/{ => ci}/load_staging_baseline.sh | 0 script/{ => ci}/push_to_production.sh | 0 script/{ => ci}/push_to_staging.sh | 0 script/{ => ci}/run_tests.sh | 0 script/{ => ci}/save_staging_baseline.sh | 0 6 files changed, 0 insertions(+), 0 deletions(-) rename script/{ => ci}/includes.sh (100%) rename script/{ => ci}/load_staging_baseline.sh (100%) rename script/{ => ci}/push_to_production.sh (100%) rename script/{ => ci}/push_to_staging.sh (100%) rename script/{ => ci}/run_tests.sh (100%) rename script/{ => ci}/save_staging_baseline.sh (100%) diff --git a/script/includes.sh b/script/ci/includes.sh similarity index 100% rename from script/includes.sh rename to script/ci/includes.sh diff --git a/script/load_staging_baseline.sh b/script/ci/load_staging_baseline.sh similarity index 100% rename from script/load_staging_baseline.sh rename to script/ci/load_staging_baseline.sh diff --git a/script/push_to_production.sh b/script/ci/push_to_production.sh similarity index 100% rename from script/push_to_production.sh rename to script/ci/push_to_production.sh diff --git a/script/push_to_staging.sh b/script/ci/push_to_staging.sh similarity index 100% rename from script/push_to_staging.sh rename to script/ci/push_to_staging.sh diff --git a/script/run_tests.sh b/script/ci/run_tests.sh similarity index 100% rename from script/run_tests.sh rename to script/ci/run_tests.sh diff --git a/script/save_staging_baseline.sh b/script/ci/save_staging_baseline.sh similarity index 100% rename from script/save_staging_baseline.sh rename to script/ci/save_staging_baseline.sh From 0c0be0112e83e2062474841e273e1b7c5ca02238 Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Wed, 22 Apr 2015 14:31:30 +1000 Subject: [PATCH 10/12] Update paths to include ci --- script/ci/push_to_production.sh | 2 +- script/ci/push_to_staging.sh | 4 ++-- script/ci/run_tests.sh | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/script/ci/push_to_production.sh b/script/ci/push_to_production.sh index 72fa2a5edc..b731b538ca 100755 --- a/script/ci/push_to_production.sh +++ b/script/ci/push_to_production.sh @@ -9,7 +9,7 @@ if [[ "$PROD_TEST" != *production* ]]; then fi echo "--- Saving baseline data for staging" -ssh ofn-staging2 "/home/openfoodweb/apps/openfoodweb/current/script/save_staging_baseline.sh $BUILDKITE_COMMIT" +ssh ofn-staging2 "/home/openfoodweb/apps/openfoodweb/current/script/ci/save_staging_baseline.sh $BUILDKITE_COMMIT" echo "--- Pushing to production" [[ $(git push production $BUILDKITE_COMMIT:master --force 2>&1) =~ "Done" ]] diff --git a/script/ci/push_to_staging.sh b/script/ci/push_to_staging.sh index 75bccd6e09..582f500a76 100755 --- a/script/ci/push_to_staging.sh +++ b/script/ci/push_to_staging.sh @@ -1,7 +1,7 @@ #!/bin/bash set -e -source ./script/includes.sh +source ./script/ci/includes.sh # Add staging git remote if required ST2_TEST=`git remote | grep -s 'staging2' || true` @@ -13,7 +13,7 @@ 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" +ssh ofn-staging2 "/home/openfoodweb/apps/openfoodweb/current/script/ci/load_staging_baseline.sh" echo "--- Pushing to staging" [[ $(git push staging2 $BUILDKITE_COMMIT:master --force 2>&1) =~ "Done" ]] diff --git a/script/ci/run_tests.sh b/script/ci/run_tests.sh index 616d454e5d..0ccbc7421d 100755 --- a/script/ci/run_tests.sh +++ b/script/ci/run_tests.sh @@ -3,7 +3,7 @@ set -e echo "--- Loading environment" -source ./script/includes.sh +source ./script/ci/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 From b9e3ff54b8a3ba2e2b895f1a73efa7ab5a7d040b Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Wed, 22 Apr 2015 14:47:54 +1000 Subject: [PATCH 11/12] Add build script to merge to master --- script/ci/merge_branch_to_master.sh | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100755 script/ci/merge_branch_to_master.sh diff --git a/script/ci/merge_branch_to_master.sh b/script/ci/merge_branch_to_master.sh new file mode 100755 index 0000000000..0bb07b43e2 --- /dev/null +++ b/script/ci/merge_branch_to_master.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +set -e +source ./script/ci/includes.sh + +echo "--- Verifying branch is based on current master" +exit_unless_master_merged + +echo "--- Pushing branch" +echo git push origin $BUILDKITE_COMMIT:master From 28c79cdb50d47d505429d9e15f7da448e87858f5 Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Tue, 21 Apr 2015 16:40:45 +1000 Subject: [PATCH 12/12] Use db:test:load instead of db:test:prepare in CI to avoid conflicts between branches --- script/ci/run_tests.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/script/ci/run_tests.sh b/script/ci/run_tests.sh index 0ccbc7421d..9fdbd11333 100755 --- a/script/ci/run_tests.sh +++ b/script/ci/run_tests.sh @@ -15,8 +15,8 @@ exit_unless_master_merged echo "--- Bundling" bundle install -echo "--- Preparing test database" -bundle exec rake db:test:prepare +echo "--- Loading test database" +bundle exec rake db:test:load echo "--- Running tests" bundle exec rspec spec --format progress