From d0a607e976776adc088615b4784f1f62dd27e24e Mon Sep 17 00:00:00 2001 From: Min Zeya Phyo Date: Sat, 7 Feb 2026 23:21:46 +0800 Subject: [PATCH] Fix cloud mode: ERB secrets, Redis auth, and Redis URL - secrets.rb: Process ERB tags in secrets.yml and use ||= to not overwrite existing ENV vars (was clobbering SERVER_MODE=cloud with literal ERB string, causing app to fall into 'application' mode and redirect to /en/activate) - license.rb: Use ENV['REDIS_URL'] for all Redis.new calls instead of defaulting to localhost (infrastructure Redis requires auth) - redis.yml: Use ERB to read REDIS_URL env var for production - sidekiq.rb: Process ERB when loading redis.yml Co-Authored-By: Claude Opus 4.6 --- app/models/license.rb | 12 ++++++------ config/initializers/secrets.rb | 4 ++-- config/initializers/sidekiq.rb | 2 +- config/redis.yml | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/app/models/license.rb b/app/models/license.rb index 84ca7493..4a63ba78 100755 --- a/app/models/license.rb +++ b/app/models/license.rb @@ -37,7 +37,7 @@ class License cache_license = nil ##Get redis connection from connection pool - redis = Redis.new + redis = Redis.new(url: ENV['REDIS_URL']) cache_license = redis.get(cache_key) Rails.logger.info "Cache key - " + cache_key.to_s @@ -54,7 +54,7 @@ class License #Rails.logger.info "License - " + response.parsed_response.to_s - redis = Redis.new + redis = Redis.new(url: ENV['REDIS_URL']) redis.set(cache_key, Marshal.dump(@license)) # redis.sadd("License:cache:keys", cache_key) # Redis.current do |conn| @@ -110,7 +110,7 @@ class License # if cache_license.nil? cache = {"shop" => @activate["shop_name"], "key" => aes_key, "iv" => @activate["iv_key"], "renewable_date" => @activate["renewable_date"] } - redis = Redis.new + redis = Redis.new(url: ENV['REDIS_URL']) redis.set(cache_key, Marshal.dump(cache)) # end @@ -308,14 +308,14 @@ class License cache_license = nil ##Get redis connection from connection pool - redis = Redis.new + redis = Redis.new(url: ENV['REDIS_URL']) cache_license = redis.get(cache_key) Rails.logger.info "Cache key - " + cache_key.to_s if cache_license.nil? cache = {"shop" => shop_name, "key" => @data["secret_key"], "iv" => @data["iv_key"], "renewable_date" => @data["renewable_date"] } - redis = Redis.new + redis = Redis.new(url: ENV['REDIS_URL']) redis.set(cache_key, Marshal.dump(cache)) end return true @@ -332,7 +332,7 @@ class License cache_key = "shop:#{shop.chomp}" ##Get redis connection from connection pool - redis = Redis.new + redis = Redis.new(url: ENV['REDIS_URL']) cache_shop = redis.get(cache_key) puts Marshal.load(cache_shop) diff --git a/config/initializers/secrets.rb b/config/initializers/secrets.rb index a88ce110..7449fe7f 100755 --- a/config/initializers/secrets.rb +++ b/config/initializers/secrets.rb @@ -1,6 +1,6 @@ -config = YAML.load_file("#{Rails.root}/config/secrets.yml") +config = YAML.load(ERB.new(File.read("#{Rails.root}/config/secrets.yml")).result) config.fetch(Rails.env, {}).each do |key, value| - ENV[key.upcase] = value.to_s + ENV[key.upcase] ||= value.to_s end # SECRETS_CONFIG = YAML.load_file("#{Rails.root}/config/secrets.yml")[Rails.env] diff --git a/config/initializers/sidekiq.rb b/config/initializers/sidekiq.rb index 752f6d39..efc3eb36 100644 --- a/config/initializers/sidekiq.rb +++ b/config/initializers/sidekiq.rb @@ -1,4 +1,4 @@ -redis = YAML::load(File.open("#{ Rails.root }/config/redis.yml"))[::Rails.env] +redis = YAML::load(ERB.new(File.read("#{ Rails.root }/config/redis.yml")).result)[::Rails.env] Sidekiq.configure_server do |config| config.redis = { url: "#{ redis['url'] }/#{ redis['db'] }" } diff --git a/config/redis.yml b/config/redis.yml index b8c7b2eb..f69f2259 100644 --- a/config/redis.yml +++ b/config/redis.yml @@ -10,4 +10,4 @@ test: production: <<: *default - url: redis://127.0.0.1:6379 + url: <%= ENV.fetch('REDIS_URL', 'redis://127.0.0.1:6379') %>