From 389ac07bd7db1a41f01b31997dacd8ad7b26099e Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Wed, 17 Jun 2015 16:25:34 +1000 Subject: [PATCH 1/5] Store commit at start of build process and use it throughout --- script/ci/includes.sh | 15 +++++++++++++++ script/ci/merge_master_into_branch.sh | 3 +++ script/ci/push_to_production.sh | 4 ++-- script/ci/push_to_staging.sh | 2 +- script/ci/run_js_tests.sh | 1 + script/ci/run_tests.sh | 1 + 6 files changed, 23 insertions(+), 3 deletions(-) diff --git a/script/ci/includes.sh b/script/ci/includes.sh index d7619f7d23..5bfe5b836f 100644 --- a/script/ci/includes.sh +++ b/script/ci/includes.sh @@ -19,6 +19,21 @@ function succeed_if_master_merged { fi } +function set_ofn_commit { + echo "Setting commit to $1" + buildkite-agent meta-data set "openfoodnetwork:git:commit" $1 +} + +function get_ofn_commit { + echo `git rev-parse $BUILDKITE_BRANCH` +} + +function checkout_ofn_commit { + OFN_COMMIT=`buildkite-agent meta-data get "openfoodnetwork:git:commit"` + echo "Checking out stored commit $OFN_COMMIT" + git checkout -qf "$OFN_COMMIT" +} + function drop_and_recreate_database { # Adapted from: http://stackoverflow.com/questions/12924466/capistrano-with-postgresql-error-database-is-being-accessed-by-other-users psql -U openfoodweb postgres <&1) =~ "Done" ]] +[[ $(git push production `get_ofn_commit`:master --force 2>&1) =~ "Done" ]] diff --git a/script/ci/push_to_staging.sh b/script/ci/push_to_staging.sh index c634ca53a4..080228cae5 100755 --- a/script/ci/push_to_staging.sh +++ b/script/ci/push_to_staging.sh @@ -16,4 +16,4 @@ echo "--- Loading baseline data" 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" ]] +[[ $(git push staging2 `get_ofn_commit`:master --force 2>&1) =~ "Done" ]] diff --git a/script/ci/run_js_tests.sh b/script/ci/run_js_tests.sh index 91a4be09d9..c4a03403b9 100755 --- a/script/ci/run_js_tests.sh +++ b/script/ci/run_js_tests.sh @@ -5,6 +5,7 @@ set -e echo "--- Loading environment" source ./script/ci/includes.sh load_environment +checkout_ofn_commit echo "--- Verifying branch is based on current master" exit_unless_master_merged diff --git a/script/ci/run_tests.sh b/script/ci/run_tests.sh index 9f9cdfa30d..efae0805a6 100755 --- a/script/ci/run_tests.sh +++ b/script/ci/run_tests.sh @@ -5,6 +5,7 @@ set -e echo "--- Loading environment" source ./script/ci/includes.sh load_environment +checkout_ofn_commit echo "--- Verifying branch is based on current master" exit_unless_master_merged From 9f883db25b7001d6790255c2079acd6042b2e621 Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Thu, 18 Jun 2015 09:57:21 +1000 Subject: [PATCH 2/5] Really show deploy output in real time --- script/ci/push_to_production.sh | 4 +++- script/ci/push_to_staging.sh | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/script/ci/push_to_production.sh b/script/ci/push_to_production.sh index 4851218064..fe16a8df80 100755 --- a/script/ci/push_to_production.sh +++ b/script/ci/push_to_production.sh @@ -12,4 +12,6 @@ echo "--- Saving baseline data for staging" ssh ofn-staging2 "/home/openfoodweb/apps/openfoodweb/current/script/ci/save_staging_baseline.sh `get_ofn_commit`" echo "--- Pushing to production" -[[ $(git push production `get_ofn_commit`:master --force 2>&1) =~ "Done" ]] +exec 5>&1 +OUTPUT=$(git push production `get_ofn_commit`:master --force 2>&1 |tee /dev/fd/5) +[[ $OUTPUT =~ "Done" ]] diff --git a/script/ci/push_to_staging.sh b/script/ci/push_to_staging.sh index 080228cae5..8dd23d53cc 100755 --- a/script/ci/push_to_staging.sh +++ b/script/ci/push_to_staging.sh @@ -16,4 +16,6 @@ echo "--- Loading baseline data" ssh ofn-staging2 "/home/openfoodweb/apps/openfoodweb/current/script/ci/load_staging_baseline.sh" echo "--- Pushing to staging" -[[ $(git push staging2 `get_ofn_commit`:master --force 2>&1) =~ "Done" ]] +exec 5>&1 +OUTPUT=$(git push staging2 `get_ofn_commit`:master --force 2>&1 |tee /dev/fd/5) +[[ $OUTPUT =~ "Done" ]] From b5d841562da85e2fa2d624fc7c12e89e32f45e64 Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Thu, 18 Jun 2015 10:02:15 +1000 Subject: [PATCH 3/5] Getting OFN commit should retrieve from meta-data --- script/ci/includes.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/script/ci/includes.sh b/script/ci/includes.sh index 5bfe5b836f..497959d33b 100644 --- a/script/ci/includes.sh +++ b/script/ci/includes.sh @@ -25,7 +25,7 @@ function set_ofn_commit { } function get_ofn_commit { - echo `git rev-parse $BUILDKITE_BRANCH` + echo `buildkite-agent meta-data get "openfoodnetwork:git:commit"` } function checkout_ofn_commit { From 860183e675013737218a05a7c4799603925cf84f Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Thu, 18 Jun 2015 12:41:47 +1000 Subject: [PATCH 4/5] Do not double-display deployment output --- script/ci/push_to_production.sh | 2 +- script/ci/push_to_staging.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/script/ci/push_to_production.sh b/script/ci/push_to_production.sh index fe16a8df80..e924f1166e 100755 --- a/script/ci/push_to_production.sh +++ b/script/ci/push_to_production.sh @@ -1,6 +1,6 @@ #!/bin/bash -set -ex +set -e # Add production git remote if required PROD_TEST=`git remote | grep -s 'production' || true` diff --git a/script/ci/push_to_staging.sh b/script/ci/push_to_staging.sh index 8dd23d53cc..7ace392276 100755 --- a/script/ci/push_to_staging.sh +++ b/script/ci/push_to_staging.sh @@ -1,6 +1,6 @@ #!/bin/bash -set -ex +set -e source ./script/ci/includes.sh # Add staging git remote if required From ce0de6e1dce1a5edcac08c2a207cefb432bd04e6 Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Thu, 18 Jun 2015 14:25:48 +1000 Subject: [PATCH 5/5] Fix push to production - needs includes for get_ofn_commit --- script/ci/push_to_production.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/script/ci/push_to_production.sh b/script/ci/push_to_production.sh index e924f1166e..9294bcb492 100755 --- a/script/ci/push_to_production.sh +++ b/script/ci/push_to_production.sh @@ -1,6 +1,7 @@ #!/bin/bash set -e +source ./script/ci/includes.sh # Add production git remote if required PROD_TEST=`git remote | grep -s 'production' || true`