Skip to content
Snippets Groups Projects
Commit 07638b2d authored by Cody Cutrer's avatar Cody Cutrer
Browse files

allow choosing rails 5.1 via consul

also add a hook so plugins can preset $canvas_cluster

Change-Id: I508ffc6e5c73e87f9f086dd9a3877833286bb83b
Reviewed-on: https://gerrit.instructure.com/129327


Tested-by: Jenkins
Reviewed-by: default avatarJames Williams <jamesw@instructure.com>
Product-Review: Cody Cutrer <cody@instructure.com>
QA-Review: Cody Cutrer <cody@instructure.com>
parent 7e9acf09
Branches
Tags release/2018-07-14.04
No related merge requests found
......@@ -12,8 +12,13 @@
# these gems to prevent regression, and the indentation serves to alert us to the relationship between the gem and canvas-lms
source 'https://rubygems.org/'
Dir[File.join(File.dirname(__FILE__), 'gems/plugins/*/Gemfile.d/_before.rb')].each do |file|
eval(File.read(file), nil, file)
end
require File.expand_path("../config/canvas_rails5", __FILE__)
Dir.glob(File.join(File.dirname(__FILE__), 'Gemfile.d', '*.rb')).sort.each do |file|
eval(File.read(file), nil, file)
end
\ No newline at end of file
end
......@@ -18,5 +18,6 @@
# Non-standard Canvas extension to Bundler behavior -- load the Gemfiles from
# plugins.
Dir[File.join(File.dirname(__FILE__), '../gems/plugins/*/Gemfile.d/*')].each do |g|
next if g.end_with?('/_before.rb')
eval(File.read(g), nil, g)
end
......@@ -16,11 +16,39 @@
# with this program. If not, see <http://www.gnu.org/licenses/>.
# You can enable the Rails 5.1 support by either defining a
# CANVAS_RAILS5_1=1 env var, or create an empty RAILS5_1 file in the canvas config dir
# CANVAS_RAILS5_1=1 env var, creating an empty RAILS5_1 file in the canvas config dir,
# or setting `private/canvas/rails5.1` to `true` in a locally accessible consul
if !defined?(CANVAS_RAILS5_0)
if ENV['CANVAS_RAILS5_1']
CANVAS_RAILS5_0 = ENV['CANVAS_RAILS5_1'] != '1'
elsif File.exist?(File.expand_path("../RAILS5_1", __FILE__))
CANVAS_RAILS5_0 = false
else
CANVAS_RAILS5_0 = !File.exist?(File.expand_path("../RAILS5_1", __FILE__))
begin
# have to do the consul communication without any gems, because
# we're in the context of loading the gemfile
require 'base64'
require 'json'
require 'net/http'
require 'yaml'
environment = YAML.load(File.read(File.expand_path("../consul.yml", __FILE__))).dig(ENV['RAILS_ENV'] || 'development', 'environment')
keys = [
["private/canvas", environment, $canvas_cluster, "rails5.1"].compact.join("/"),
["private/canvas", environment, "rails5.1"].compact.join("/"),
["global/private/canvas", environment, "rails5.1"].compact.join("/")
].uniq
result = nil
keys.each do |key|
result = Net::HTTP.get_response(URI("http://localhost:8500/v1/kv/#{key}"))
result = nil unless result.is_a?(Net::HTTPSuccess)
break if result
end
CANVAS_RAILS5_0 = !(result && Base64.decode64(JSON.load(result.body).first['Value']) == 'true')
rescue
CANVAS_RAILS5_0 = true
end
end
end
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment