Skip to content

Commit dd09ff0

Browse files
authored
Merge pull request #783 from code0-tech/fix-optional-velorum-config
Fix sagittarius config when velorum is unconfigured
2 parents 530ff9c + 7b97540 commit dd09ff0

4 files changed

Lines changed: 31 additions & 32 deletions

File tree

container/config-generator/generate.rb

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,12 @@
33
require 'fileutils'
44

55
class ConfigGenerator
6-
REQUIRED_VARS = %w[
7-
SAGITTARIUS_RAILS_HOST
8-
SAGITTARIUS_RAILS_PORT
9-
SAGITTARIUS_GRPC_HOST
10-
SAGITTARIUS_GRPC_PORT
11-
SCULPTOR_HOST
12-
SCULPTOR_PORT
13-
HOSTNAME
14-
]
156
TEMPLATES_DIR = '/config-generator/templates'
167
OUTPUT_DIR = '/generated-configs'
178

189
def initialize
1910
@env = ENV.to_h
20-
validate_env!
11+
@missing_envs = []
2112
end
2213

2314
def generate_all
@@ -34,19 +25,15 @@ def generate_all
3425
generate_from_template(template_path)
3526
end
3627

28+
if @missing_envs.any?
29+
abort "ERROR: Missing required environment variables: #{@missing_envs.join(', ')}"
30+
end
31+
3732
puts "Configuration generation complete! Generated #{template_files.size} file(s)."
3833
end
3934

4035
private
4136

42-
def validate_env!
43-
missing = REQUIRED_VARS.reject { |var| @env[var] }
44-
45-
if missing.any?
46-
abort "ERROR: Missing required environment variables: #{missing.join(', ')}"
47-
end
48-
end
49-
5037
def generate_from_template(template_path)
5138
# Calculate relative path from templates directory
5239
relative_path = template_path.sub("#{TEMPLATES_DIR}/", '')
@@ -76,6 +63,14 @@ def env(key, default = nil)
7663
@env.fetch(key, default)
7764
end
7865

66+
def env!(key)
67+
result = @env.fetch(key, nil)
68+
69+
@missing_envs << key if result.nil?
70+
71+
result
72+
end
73+
7974
def env?(key)
8075
@env[key] == 'true'
8176
end

container/config-generator/templates/aquila.service.configuration.json.erb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
"runtimes": [
33
{
44
"identifier": "taurus",
5-
"token": "<%= env('TAURUS_AQUILA_TOKEN') %>"
5+
"token": "<%= env!('TAURUS_AQUILA_TOKEN') %>"
66
},
77
{
88
"identifier": "draco-rest",
9-
"token": "<%= env('DRACO_REST_AQUILA_TOKEN') %>"
9+
"token": "<%= env!('DRACO_REST_AQUILA_TOKEN') %>"
1010
},
1111
{
1212
"identifier": "draco-cron",
13-
"token": "<%= env('DRACO_CRON_AQUILA_TOKEN') %>"
13+
"token": "<%= env!('DRACO_CRON_AQUILA_TOKEN') %>"
1414
}
1515
]
1616
}

container/config-generator/templates/nginx.default.conf.erb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
upstream sagittarius_rails_web {
2-
server <%= env('SAGITTARIUS_RAILS_HOST') %>:<%= env('SAGITTARIUS_RAILS_PORT') %>;
2+
server <%= env!('SAGITTARIUS_RAILS_HOST') %>:<%= env!('SAGITTARIUS_RAILS_PORT') %>;
33
}
44

55
<% if env_set?('SAGITTARIUS_CABLE_HOST') && env_set?('SAGITTARIUS_CABLE_PORT') %>
@@ -9,24 +9,24 @@ upstream sagittarius_cable {
99
<% end %>
1010

1111
upstream sagittarius_grpc {
12-
server <%= env('SAGITTARIUS_GRPC_HOST') %>:<%= env('SAGITTARIUS_GRPC_PORT') %>;
12+
server <%= env!('SAGITTARIUS_GRPC_HOST') %>:<%= env!('SAGITTARIUS_GRPC_PORT') %>;
1313
}
1414

1515
upstream sculptor {
16-
server <%= env('SCULPTOR_HOST') %>:<%= env('SCULPTOR_PORT') %>;
16+
server <%= env!('SCULPTOR_HOST') %>:<%= env!('SCULPTOR_PORT') %>;
1717
}
1818

1919
<% if env?('SSL_ENABLED') %>
2020
server {
2121
listen 80;
22-
server_name <%= env('HOSTNAME') %>;
22+
server_name <%= env!('HOSTNAME') %>;
2323

2424
return 301 https://$host$request_uri;
2525
}
2626

2727
server {
2828
listen 443 ssl http2;
29-
server_name <%= env('HOSTNAME') %>;
29+
server_name <%= env!('HOSTNAME') %>;
3030

3131
ssl_certificate /etc/nginx/certs/<%= env('SSL_CERT_FILE', "#{env('HOSTNAME')}.pem") %>;
3232
ssl_certificate_key /etc/nginx/certs/<%= env('SSL_KEY_FILE', "#{env('HOSTNAME')}.key") %>;
@@ -39,7 +39,7 @@ server {
3939
<% else %>
4040
server {
4141
listen 80 http2;
42-
server_name <%= env('HOSTNAME') %>;
42+
server_name <%= env!('HOSTNAME') %>;
4343
<% end %>
4444

4545
location = /graphql {

container/config-generator/templates/sagittarius.sagittarius.yml.erb

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,13 @@ rails:
44
log_level: <%= env('SAGITTARIUS_LOG_LEVEL', 'info') %>
55
threads: 3
66
db:
7-
host: <%= env('POSTGRES_HOST') %>
8-
port: <%= env('POSTGRES_PORT') %>
7+
host: <%= env!('POSTGRES_HOST') %>
8+
port: <%= env!('POSTGRES_PORT') %>
9+
910
velorum:
10-
enabled: <%= env_set?('VELORUM_ENABLED') ? env('VELORUM_ENABLED') : env('COMPOSE_PROFILES').include?('ide_velorum') %>
11-
host: <%= env('VELORUM_HOST') %>:<%= env('VELORUM_PORT') %>
12-
jwt_secret: <%= env('VELORUM_JWT_SECRET') %>
11+
<% velorum_enabled = env_set?('VELORUM_ENABLED') ? env?('VELORUM_ENABLED') : env('COMPOSE_PROFILES', '').include?('ide_velorum') -%>
12+
enabled: <%= velorum_enabled %>
13+
<% if velorum_enabled -%>
14+
host: <%= env!('VELORUM_HOST') %>:<%= env!('VELORUM_PORT') %>
15+
jwt_secret: <%= env!('VELORUM_JWT_SECRET') %>
16+
<% end -%>

0 commit comments

Comments
 (0)