diff --git a/container/config-generator/generate.rb b/container/config-generator/generate.rb index cf0b0af..bb65c8f 100644 --- a/container/config-generator/generate.rb +++ b/container/config-generator/generate.rb @@ -3,21 +3,12 @@ require 'fileutils' class ConfigGenerator - REQUIRED_VARS = %w[ - SAGITTARIUS_RAILS_HOST - SAGITTARIUS_RAILS_PORT - SAGITTARIUS_GRPC_HOST - SAGITTARIUS_GRPC_PORT - SCULPTOR_HOST - SCULPTOR_PORT - HOSTNAME - ] TEMPLATES_DIR = '/config-generator/templates' OUTPUT_DIR = '/generated-configs' def initialize @env = ENV.to_h - validate_env! + @missing_envs = [] end def generate_all @@ -34,19 +25,15 @@ def generate_all generate_from_template(template_path) end + if @missing_envs.any? + abort "ERROR: Missing required environment variables: #{@missing_envs.join(', ')}" + end + puts "Configuration generation complete! Generated #{template_files.size} file(s)." end private - def validate_env! - missing = REQUIRED_VARS.reject { |var| @env[var] } - - if missing.any? - abort "ERROR: Missing required environment variables: #{missing.join(', ')}" - end - end - def generate_from_template(template_path) # Calculate relative path from templates directory relative_path = template_path.sub("#{TEMPLATES_DIR}/", '') @@ -76,6 +63,14 @@ def env(key, default = nil) @env.fetch(key, default) end + def env!(key) + result = @env.fetch(key, nil) + + @missing_envs << key if result.nil? + + result + end + def env?(key) @env[key] == 'true' end diff --git a/container/config-generator/templates/aquila.service.configuration.json.erb b/container/config-generator/templates/aquila.service.configuration.json.erb index 836db8f..23450ee 100644 --- a/container/config-generator/templates/aquila.service.configuration.json.erb +++ b/container/config-generator/templates/aquila.service.configuration.json.erb @@ -2,15 +2,15 @@ "runtimes": [ { "identifier": "taurus", - "token": "<%= env('TAURUS_AQUILA_TOKEN') %>" + "token": "<%= env!('TAURUS_AQUILA_TOKEN') %>" }, { "identifier": "draco-rest", - "token": "<%= env('DRACO_REST_AQUILA_TOKEN') %>" + "token": "<%= env!('DRACO_REST_AQUILA_TOKEN') %>" }, { "identifier": "draco-cron", - "token": "<%= env('DRACO_CRON_AQUILA_TOKEN') %>" + "token": "<%= env!('DRACO_CRON_AQUILA_TOKEN') %>" } ] } diff --git a/container/config-generator/templates/nginx.default.conf.erb b/container/config-generator/templates/nginx.default.conf.erb index 8190cb8..d00103a 100644 --- a/container/config-generator/templates/nginx.default.conf.erb +++ b/container/config-generator/templates/nginx.default.conf.erb @@ -1,5 +1,5 @@ upstream sagittarius_rails_web { - server <%= env('SAGITTARIUS_RAILS_HOST') %>:<%= env('SAGITTARIUS_RAILS_PORT') %>; + server <%= env!('SAGITTARIUS_RAILS_HOST') %>:<%= env!('SAGITTARIUS_RAILS_PORT') %>; } <% if env_set?('SAGITTARIUS_CABLE_HOST') && env_set?('SAGITTARIUS_CABLE_PORT') %> @@ -9,24 +9,24 @@ upstream sagittarius_cable { <% end %> upstream sagittarius_grpc { - server <%= env('SAGITTARIUS_GRPC_HOST') %>:<%= env('SAGITTARIUS_GRPC_PORT') %>; + server <%= env!('SAGITTARIUS_GRPC_HOST') %>:<%= env!('SAGITTARIUS_GRPC_PORT') %>; } upstream sculptor { - server <%= env('SCULPTOR_HOST') %>:<%= env('SCULPTOR_PORT') %>; + server <%= env!('SCULPTOR_HOST') %>:<%= env!('SCULPTOR_PORT') %>; } <% if env?('SSL_ENABLED') %> server { listen 80; - server_name <%= env('HOSTNAME') %>; + server_name <%= env!('HOSTNAME') %>; return 301 https://$host$request_uri; } server { listen 443 ssl http2; - server_name <%= env('HOSTNAME') %>; + server_name <%= env!('HOSTNAME') %>; ssl_certificate /etc/nginx/certs/<%= env('SSL_CERT_FILE', "#{env('HOSTNAME')}.pem") %>; ssl_certificate_key /etc/nginx/certs/<%= env('SSL_KEY_FILE', "#{env('HOSTNAME')}.key") %>; @@ -39,7 +39,7 @@ server { <% else %> server { listen 80 http2; - server_name <%= env('HOSTNAME') %>; + server_name <%= env!('HOSTNAME') %>; <% end %> location = /graphql { diff --git a/container/config-generator/templates/sagittarius.sagittarius.yml.erb b/container/config-generator/templates/sagittarius.sagittarius.yml.erb index 1354775..3875765 100644 --- a/container/config-generator/templates/sagittarius.sagittarius.yml.erb +++ b/container/config-generator/templates/sagittarius.sagittarius.yml.erb @@ -4,9 +4,13 @@ rails: log_level: <%= env('SAGITTARIUS_LOG_LEVEL', 'info') %> threads: 3 db: - host: <%= env('POSTGRES_HOST') %> - port: <%= env('POSTGRES_PORT') %> + host: <%= env!('POSTGRES_HOST') %> + port: <%= env!('POSTGRES_PORT') %> + velorum: - enabled: <%= env_set?('VELORUM_ENABLED') ? env('VELORUM_ENABLED') : env('COMPOSE_PROFILES').include?('ide_velorum') %> - host: <%= env('VELORUM_HOST') %>:<%= env('VELORUM_PORT') %> - jwt_secret: <%= env('VELORUM_JWT_SECRET') %> +<% velorum_enabled = env_set?('VELORUM_ENABLED') ? env?('VELORUM_ENABLED') : env('COMPOSE_PROFILES', '').include?('ide_velorum') -%> + enabled: <%= velorum_enabled %> +<% if velorum_enabled -%> + host: <%= env!('VELORUM_HOST') %>:<%= env!('VELORUM_PORT') %> + jwt_secret: <%= env!('VELORUM_JWT_SECRET') %> +<% end -%>