Files
Alvand-P/scripts/bootstrap-app-staging.rb
2026-08-13 19:42:08 +03:30

72 lines
1.9 KiB
Ruby

#!/usr/bin/env ruby
# frozen_string_literal: true
# Build config/app.staging.yml from app.production.yml (preferred) or example template.
# Usage: ruby scripts/bootstrap-app-staging.rb
#
# Run from Alvand-P root. Does not overwrite if app.staging.yml is already a valid Hash
# unless BOOTSTRAP_FORCE=1.
require 'yaml'
ROOT = File.expand_path('..', __dir__)
STAGING_PATH = File.join(ROOT, 'config/app.staging.yml')
PRODUCTION_PATH = File.join(ROOT, 'config/app.production.yml')
EXAMPLE_PATH = File.join(ROOT, 'config/app.staging.yml.example')
def load_hash(path)
return nil unless File.exist?(path)
data = YAML.load_file(path)
return data if data.is_a?(Hash)
warn "WARN: #{path} is #{data.class}, not Hash — ignored"
nil
end
def deep_merge(base, overlay)
base.merge(overlay) do |_key, old_val, new_val|
if old_val.is_a?(Hash) && new_val.is_a?(Hash)
deep_merge(old_val, new_val)
else
new_val
end
end
end
staging_overlay = {
'app' => {
'domain' => 'fibitex.com',
'subdomain' => 'beta',
'shahoo_subdomain' => 'shahoo'
},
'images' => {
'peatio' => 'custom/dena:1',
'barong' => 'custom/dalan:1',
'frontend' => 'custom/gereh:1',
'gereh' => 'custom/gereh:1',
'shahoo' => 'custom/shahoo:1',
'shahoo_bff' => 'custom/shahoo-bff:1'
}
}
existing = load_hash(STAGING_PATH)
if existing && ENV['BOOTSTRAP_FORCE'] != '1'
puts "OK: #{STAGING_PATH} already exists and is a valid Hash."
puts 'Set BOOTSTRAP_FORCE=1 to regenerate.'
exit 0
end
source = load_hash(PRODUCTION_PATH) || load_hash(EXAMPLE_PATH)
unless source
warn 'ERROR: Need config/app.production.yml or config/app.staging.yml.example'
exit 1
end
merged = deep_merge(source, staging_overlay)
File.write(STAGING_PATH, merged.to_yaml)
puts "Wrote #{STAGING_PATH}"
puts 'Next:'
puts ' export OPENDAX_ENV=staging'
puts ' bundle exec rake render:config'