Как и где установить переменные среды в рельсах? - PullRequest
1 голос
/ 22 февраля 2020

Так что я работаю над чужим проектом Rails. Я клонировал репо и нажал bundle install, но когда использовал команды rails db:migrate или rake db:migrate или rails s. Я получаю длинный список ошибок стека. это выглядит так (ПОЖАЛУЙСТА, ПРОЧИТАЙТЕ ПОСЛЕДНЮЮ СТРОКУ ОШИБКИ, ОСОБЕННО БИТ В КОНЦЕ):

Traceback (most recent call last):
58: from bin/rails:4:in `<main>'
57: from bin/rails:4:in `require'
56: from /Users/macbook/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/railties-4.2.11/lib/rails/commands.rb:17:in `<top (required)>'
55: from /Users/macbook/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/railties-4.2.11/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
54: from /Users/macbook/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/railties-4.2.11/lib/rails/commands/commands_tasks.rb:75:in `server'
53: from /Users/macbook/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/railties-4.2.11/lib/rails/commands/commands_tasks.rb:75:in `tap'
52: from /Users/macbook/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/railties-4.2.11/lib/rails/commands/commands_tasks.rb:80:in `block in server'
51: from /Users/macbook/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/railties-4.2.11/lib/rails/commands/server.rb:78:in `start'
50: from /Users/macbook/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/railties-4.2.11/lib/rails/commands/server.rb:139:in `log_to_stdout'
49: from /Users/macbook/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rack-1.6.13/lib/rack/server.rb:337:in `wrapped_app'
48: from /Users/macbook/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/railties-4.2.11/lib/rails/commands/server.rb:61:in `app'
47: from /Users/macbook/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rack-1.6.13/lib/rack/server.rb:209:in `app'
46: from /Users/macbook/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rack-1.6.13/lib/rack/server.rb:300:in `build_app_and_options_from_config'
45: from /Users/macbook/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rack-1.6.13/lib/rack/builder.rb:40:in `parse_file'
44: from /Users/macbook/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rack-1.6.13/lib/rack/builder.rb:49:in `new_from_string'
43: from /Users/macbook/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rack-1.6.13/lib/rack/builder.rb:49:in `eval'
42: from /Users/macbook/Desktop/develop/rails-projects/audiogon-staging/config.ru:in `<main>'
41: from /Users/macbook/Desktop/develop/rails-projects/audiogon-staging/config.ru:in `new'
40: from /Users/macbook/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rack-1.6.13/lib/rack/builder.rb:55:in `initialize'
39: from /Users/macbook/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rack-1.6.13/lib/rack/builder.rb:55:in `instance_eval'
38: from /Users/macbook/Desktop/develop/rails-projects/audiogon-staging/config.ru:3:in `block in <main>'
37: from /Users/macbook/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activesupport-4.2.11/lib/active_support/dependencies.rb:274:in `require'
36: from /Users/macbook/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activesupport-4.2.11/lib/active_support/dependencies.rb:240:in `load_dependency'
35: from /Users/macbook/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activesupport-4.2.11/lib/active_support/dependencies.rb:274:in `block in require'
34: from /Users/macbook/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activesupport-4.2.11/lib/active_support/dependencies.rb:274:in `require'
33: from /Users/macbook/Desktop/develop/rails-projects/audiogon-staging/config/environment.rb:15:in `<top (required)>'
32: from /Users/macbook/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/railties-4.2.11/lib/rails/railtie.rb:194:in `method_missing'
31: from /Users/macbook/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/railties-4.2.11/lib/rails/railtie.rb:194:in `public_send'
30: from /Users/macbook/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/railties-4.2.11/lib/rails/application.rb:352:in `initialize!'
29: from /Users/macbook/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/railties-4.2.11/lib/rails/initializable.rb:54:in `run_initializers'
28: from /Users/macbook/.rbenv/versions/2.6.3/lib/ruby/2.6.0/tsort.rb:205:in `tsort_each'
27: from /Users/macbook/.rbenv/versions/2.6.3/lib/ruby/2.6.0/tsort.rb:226:in `tsort_each'
26: from /Users/macbook/.rbenv/versions/2.6.3/lib/ruby/2.6.0/tsort.rb:347:in `each_strongly_connected_component'
25: from /Users/macbook/.rbenv/versions/2.6.3/lib/ruby/2.6.0/tsort.rb:347:in `call'
24: from /Users/macbook/.rbenv/versions/2.6.3/lib/ruby/2.6.0/tsort.rb:347:in `each'
23: from /Users/macbook/.rbenv/versions/2.6.3/lib/ruby/2.6.0/tsort.rb:349:in `block in each_strongly_connected_component'
22: from /Users/macbook/.rbenv/versions/2.6.3/lib/ruby/2.6.0/tsort.rb:415:in `each_strongly_connected_component_from'
21: from /Users/macbook/.rbenv/versions/2.6.3/lib/ruby/2.6.0/tsort.rb:415:in `call'
20: from /Users/macbook/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/railties-4.2.11/lib/rails/initializable.rb:44:in `tsort_each_child'
19: from /Users/macbook/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/railties-4.2.11/lib/rails/initializable.rb:44:in `each'
18: from /Users/macbook/.rbenv/versions/2.6.3/lib/ruby/2.6.0/tsort.rb:421:in `block in each_strongly_connected_component_from'
17: from /Users/macbook/.rbenv/versions/2.6.3/lib/ruby/2.6.0/tsort.rb:431:in `each_strongly_connected_component_from'
16: from /Users/macbook/.rbenv/versions/2.6.3/lib/ruby/2.6.0/tsort.rb:422:in `block (2 levels) in each_strongly_connected_component_from'
15: from /Users/macbook/.rbenv/versions/2.6.3/lib/ruby/2.6.0/tsort.rb:350:in `block (2 levels) in each_strongly_connected_component'
14: from /Users/macbook/.rbenv/versions/2.6.3/lib/ruby/2.6.0/tsort.rb:228:in `block in tsort_each'
13: from /Users/macbook/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/railties-4.2.11/lib/rails/initializable.rb:55:in `block in run_initializers'
12: from /Users/macbook/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/railties-4.2.11/lib/rails/initializable.rb:30:in `run'
11: from /Users/macbook/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/railties-4.2.11/lib/rails/initializable.rb:30:in `instance_exec'
10: from /Users/macbook/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/railties-4.2.11/lib/rails/engine.rb:615:in `block in <class:Engine>'
 9: from /Users/macbook/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/railties-4.2.11/lib/rails/engine.rb:615:in `each'
 8: from /Users/macbook/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/railties-4.2.11/lib/rails/engine.rb:616:in `block (2 levels) in <class:Engine>'
 7: from /Users/macbook/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/railties-4.2.11/lib/rails/engine.rb:651:in `load_config_initializer'
 6: from /Users/macbook/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activesupport-4.2.11/lib/active_support/notifications.rb:166:in `instrument'
 5: from /Users/macbook/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/railties-4.2.11/lib/rails/engine.rb:652:in `block in load_config_initializer'
 4: from /Users/macbook/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activesupport-4.2.11/lib/active_support/dependencies.rb:268:in `load'
 3: from /Users/macbook/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activesupport-4.2.11/lib/active_support/dependencies.rb:240:in `load_dependency'
 2: from /Users/macbook/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activesupport-4.2.11/lib/active_support/dependencies.rb:268:in `block in load'
 1: from /Users/macbook/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activesupport-4.2.11/lib/active_support/dependencies.rb:268:in `load'
 /Users/macbook/Desktop/develop/rails-projects/audiogon-staging/config/initializers/aws.rb:3:in `<top (required)>': Must set AWS_ACCESS_KEY_ID environment variable (RuntimeError)

Поэтому я должен установить AWS_ACCESS_KEY_ID environment variable, как говорится в ошибке.

, поэтому файл config/initializers/aws.rb проекта выглядит следующим образом:

 Aws.config.update({
  region: 'us-east-1',
  access_key_id: (ENV['AWS_ACCESS_KEY_ID'] or raise "Must set AWS_ACCESS_KEY_ID environment variable"),
  secret_access_key: (ENV['AWS_SECRET_ACCESS_KEY'] or raise "Must set AWS_SECRET_ACCESS_KEY environment variable")
 }) 

В дальнейшем их config / enviroments / production.rb имеет следующее:

 config.zaius_aws_access_key_id = 'SomeLongStringOFkey'
 config.zaius_aws_secret_access_key = 'TheseAreNotRealJustExamples'

будет копировать эти сделать config / enviroments / development.rb?

Я не хочу хранить ключи в моей среде bash / linux, я хочу настроить их в своем проекте rails, тогда где же делать Я размещаю свои ключи / учетные данные (в проекте). Я неплохо разбираюсь с рельсами, но у меня очень мало опыта в настройке и настройке. Я просто хочу запустить проект, чтобы я мог работать над ним.

Спасибо

1 Ответ

1 голос
/ 23 февраля 2020

Никогда, никогда не проверяйте AWS учетные данные как часть вашего контроля версий.

Для проекта rails вы обычно устанавливаете их как часть сценария запуска в среде linux (если это не AWS ec2).

Если, однако, вы Если у вас есть опция использования EC2, вы вообще не будете использовать учетные данные, а вместо этого создадите AWS профиль экземпляра IAM , содержащий все разрешения, необходимые вашему приложению, и назначите его соответствующему экземпляру EC2. Это позволило бы вашему приложению Rails (и всему остальному в ec2) получить доступ к разрешенным AWS сервисам, но исключило бы любую вероятность утечки учетных данных за пределы AWS.

Снова, проверяя AWS учетные данные в контроль источника злой. Не будь злым.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...