From f9fc68024c7b40bdc53f64dcdef929671153432e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Meny?= Date: Wed, 26 Jan 2022 15:38:17 +0000 Subject: [PATCH] Ensures DB migration only happens on first instance --- lib/tasks/cf.rake | 12 ++++++++++++ manifest.yml | 4 ++-- 2 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 lib/tasks/cf.rake diff --git a/lib/tasks/cf.rake b/lib/tasks/cf.rake new file mode 100644 index 000000000..ad7dc0c6d --- /dev/null +++ b/lib/tasks/cf.rake @@ -0,0 +1,12 @@ +namespace :cf do + desc "Only run on the first application instance" + task on_first_instance: :environment do + instance_index = -1 + begin + instance_index = JSON.parse(ENV["VCAP_APPLICATION"])["instance_index"] + rescue StandardError + nil + end + exit(0) unless instance_index.zero? + end +end diff --git a/manifest.yml b/manifest.yml index 154e816ef..5935f2495 100644 --- a/manifest.yml +++ b/manifest.yml @@ -1,10 +1,10 @@ --- defaults: &defaults buildpacks: - - https://github.com/cloudfoundry/ruby-buildpack.git + - ruby_buildpack processes: - type: web - command: rake db:migrate && bin/rails server + command: bundle exec rake cf:on_first_instance db:migrate && bin/rails server instances: 2 memory: 512M