exercism_config 0.14.0 → 0.19.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ac25eddfab6f5189cbeeace2f871ed2e5f3e3c7f8604c29b3acd7075374c5f9b
4
- data.tar.gz: 2ffb5ae56efa786c3b7726774250a24e3058cfc94827841d5fb2ba2c7c1b487a
3
+ metadata.gz: 3d8f9947448e72f417cd4da6d1ba5700a8cf3b171b387d3a1112dc23d9d953b6
4
+ data.tar.gz: 07c32a1e10c2ea8e7599086a3038e98ef11e1580e59b833ac45aea4510066d13
5
5
  SHA512:
6
- metadata.gz: 25f501c4b986003944faf82fdf7bf760cb54235d5e7ffdaf2820e22d0c4620ffe6c51439dbc16bcff62e4b91a136c8fd886556daf5d4c1ad83da16bd6ff4a4f1
7
- data.tar.gz: 27b2e746e4f226d86f9bbc285bb8191cd5388dacb990265879a052c5d617d0f4996f7cf3db553f6a6b0b192eda97cfa2068a783b450916662ceba6ded0603774
6
+ metadata.gz: abc918c726bb0810528365950c4363901a124815daa5f44356021e8f07d2dd3dec61ed29fb09fc7a4b482ee1b53208a866ccbed473ef501e5616dab0254dab2a
7
+ data.tar.gz: 05c42ebedca84160661fc68f2bc4d6d3115978da15295eded25f19e2d2c21d60ac18b0983c6067a7b3e2df931e1a76f8565b5ae48c77a68efcf316b211447025
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- exercism_config (0.11.0)
4
+ exercism_config (0.18.0)
5
5
  aws-sdk-dynamodb (~> 1.0)
6
6
  mandate
7
7
  zeitwerk
@@ -10,7 +10,7 @@ GEM
10
10
  remote: https://rubygems.org/
11
11
  specs:
12
12
  aws-eventstream (1.1.0)
13
- aws-partitions (1.345.0)
13
+ aws-partitions (1.346.0)
14
14
  aws-sdk-core (3.104.3)
15
15
  aws-eventstream (~> 1, >= 1.0.2)
16
16
  aws-partitions (~> 1, >= 1.239.0)
data/README.md CHANGED
@@ -19,8 +19,3 @@ require 'exercism_config'
19
19
  ExercismConfig.config.webservers_alb_dns_name
20
20
  ```
21
21
 
22
- To print out all the config from the command-line, you can run:
23
-
24
- ```bash
25
- AWS_PROFILE=exercism_terraform ./bin/run
26
- ```
data/bin/setup CHANGED
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env bash
1
+ setup_#!/usr/bin/env bash
2
2
  set -euo pipefail
3
3
  IFS=$'\n\t'
4
4
  set -vx
@@ -0,0 +1,81 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "exercism_config"
5
+ require 'yaml'
6
+
7
+ env = ExercismConfig::DetermineEnvironment.()
8
+ if env == :production
9
+ puts "Aborted! This script should not be run in production."
10
+ exit
11
+ end
12
+
13
+ def create_table(client)
14
+ client.create_table(
15
+ table_name: :config,
16
+ attribute_definitions: [
17
+ {
18
+ attribute_name: "id",
19
+ attribute_type: "S",
20
+ },
21
+ ],
22
+ key_schema: [
23
+ {
24
+ attribute_name: "id",
25
+ key_type: "HASH",
26
+ }
27
+ ],
28
+ provisioned_throughput: {
29
+ read_capacity_units: 1,
30
+ write_capacity_units: 1,
31
+ }
32
+ )
33
+ end
34
+
35
+ def delete_table(client)
36
+ client.delete_table(
37
+ table_name: :config,
38
+ )
39
+ end
40
+
41
+ def set_config_value(client, id, value)
42
+ client.put_item(
43
+ table_name: :config,
44
+ item: {
45
+ id: id,
46
+ value: value
47
+ }
48
+ )
49
+ end
50
+
51
+ client = ExercismConfig::SetupDynamoDBClient.()
52
+
53
+ begin
54
+ create_table(client)
55
+ rescue Aws::DynamoDB::Errors::ResourceInUseException => e
56
+ if ARGV.include?("--force")
57
+ puts "Table exists. Recreating..."
58
+ delete_table(client)
59
+ create_table(client)
60
+ puts "Table recreated."
61
+ else
62
+ puts "Table exists. Not recreating."
63
+ end
64
+ end
65
+
66
+ settings_file_arg = ARGV.select{|arg|arg.start_with?("--settings-file=")}.first
67
+ settings_file =
68
+ if settings_file_arg
69
+ settings_file_arg.split("=").last
70
+ elsif ENV["EXERCISM_DOCKER"]
71
+ File.expand_path("../../settings-docker.yml", __FILE__)
72
+ else
73
+ File.expand_path("../../settings-development.yml", __FILE__)
74
+ end
75
+
76
+ puts "Using settings file: #{settings_file}"
77
+ settings = YAML.load(File.read(settings_file))
78
+
79
+ settings.each do |key, value|
80
+ set_config_value(client, key, value)
81
+ end
@@ -18,8 +18,8 @@ Gem::Specification.new do |spec|
18
18
  spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
19
19
  `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
20
20
  end
21
- spec.bindir = "exe"
22
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.bindir = "bin"
22
+ spec.executables = ["setup_exercism_config"]
23
23
  spec.require_paths = ["lib"]
24
24
 
25
25
  spec.add_dependency "aws-sdk-dynamodb", "~> 1.0"
@@ -3,8 +3,9 @@ require 'mandate'
3
3
  require "ostruct"
4
4
  require 'json'
5
5
 
6
+ require_relative 'exercism_config/determine_environment'
6
7
  require_relative 'exercism_config/generate_aws_settings'
7
- require_relative 'exercism_config/setup_dynamodb_client.rb'
8
+ require_relative 'exercism_config/setup_dynamodb_client'
8
9
  require_relative 'exercism_config/retrieve'
9
10
  require_relative 'exercism_config/generate_aws_settings'
10
11
  require_relative "exercism_config/version"
@@ -15,6 +16,10 @@ module Exercism
15
16
  class ConfigError < RuntimeError
16
17
  end
17
18
 
19
+ def self.environment
20
+ @environment ||= ExercismConfig::DetermineEnvironment.()
21
+ end
22
+
18
23
  def self.config
19
24
  @config ||= ExercismConfig::Retrieve.()
20
25
  end
@@ -0,0 +1,16 @@
1
+ module ExercismConfig
2
+ class DetermineEnvironment
3
+ include Mandate
4
+
5
+ def call
6
+ env = ENV["EXERCISM_ENV"] || ENV["RAILS_ENV"] || ENV["APP_ENV"]
7
+ raise Exercism::ConfigError, "No environment set - set one of EXERCISM_ENV, RAILS_ENV or APP_ENV" unless env
8
+
9
+ unless %w[development test production].include?(env)
10
+ raise Exercism::ConfigError, "environments must be one of development test production. Got #{env}"
11
+ end
12
+
13
+ env.to_sym
14
+ end
15
+ end
16
+ end
@@ -2,10 +2,6 @@ module ExercismConfig
2
2
  class GenerateAwsSettings
3
3
  include Mandate
4
4
 
5
- def initialize(environment)
6
- @environment = environment
7
- end
8
-
9
5
  def call
10
6
  {
11
7
  region: 'eu-west-2',
@@ -17,7 +13,7 @@ module ExercismConfig
17
13
 
18
14
  memoize
19
15
  def aws_access_key_id
20
- case environment
16
+ case Exercism.environment
21
17
  when :development, :test
22
18
  "FAKE"
23
19
  else
@@ -27,7 +23,7 @@ module ExercismConfig
27
23
 
28
24
  memoize
29
25
  def aws_secret_access_key
30
- case environment
26
+ case Exercism.environment
31
27
  when :development, :test
32
28
  "FAKE"
33
29
  else
@@ -37,24 +33,10 @@ module ExercismConfig
37
33
 
38
34
  memoize
39
35
  def profile
40
- case environment
36
+ case Exercism.environment
41
37
  when :production
42
38
  "exercism_staging"
43
39
  end
44
40
  end
45
-
46
- memoize
47
- def environment
48
- return @environment.to_sym if @environment
49
-
50
- env = ENV["EXERCISM_ENV"] || ENV["RAILS_ENV"] || ENV["APP_ENV"]
51
- raise Exercism::ConfigError, "No environment set - set one of EXERCISM_ENV, RAILS_ENV or APP_ENV" unless env
52
-
53
- unless %w[development test production].include?(env)
54
- raise Exercism::ConfigError, "environments must be one of development test production. Got #{env}"
55
- end
56
-
57
- env.to_sym
58
- end
59
41
  end
60
42
  end
@@ -2,12 +2,8 @@ module ExercismConfig
2
2
  class Retrieve
3
3
  include Mandate
4
4
 
5
- def initialize(environment = nil)
6
- @environment = environment
7
- end
8
-
9
5
  def call
10
- client = SetupDynamodbClient.(environment)
6
+ client = SetupDynamoDBClient.()
11
7
 
12
8
  resp = client.scan({table_name: "config"})
13
9
  items = resp.to_h[:items]
@@ -16,13 +12,13 @@ module ExercismConfig
16
12
  end
17
13
 
18
14
  # Tweak things for dynamodb when we're running in test mode
19
- if environment == :test
15
+ if Exercism.environment == :test
20
16
  %w{dynamodb_tooling_jobs_table}.each do |key|
21
17
  data[key] = "#{data[key]}-test"
22
18
  end
23
19
  end
24
20
 
25
- aws_settings = GenerateAwsSettings.(environment)
21
+ aws_settings = GenerateAwsSettings.()
26
22
  Exercism::Config.new(data, aws_settings)
27
23
  rescue Exercism::ConfigError
28
24
  raise
@@ -43,20 +39,6 @@ module ExercismConfig
43
39
 
44
40
  Aws::DynamoDB::Client.new(config)
45
41
  end
46
-
47
- memoize
48
- def environment
49
- return @environment.to_sym if @environment
50
-
51
- env = ENV["EXERCISM_ENV"] || ENV["RAILS_ENV"] || ENV["APP_ENV"]
52
- raise Exercism::ConfigError, "No environment set - set one of EXERCISM_ENV, RAILS_ENV or APP_ENV" unless env
53
-
54
- unless %w[development test production].include?(env)
55
- raise Exercism::ConfigError, "environments must be one of development test production. Got #{env}"
56
- end
57
-
58
- env.to_sym
59
- end
60
42
  end
61
43
  end
62
44
 
@@ -1,13 +1,9 @@
1
1
  module ExercismConfig
2
- class SetupDynamodbClient
2
+ class SetupDynamoDBClient
3
3
  include Mandate
4
4
 
5
- def initialize(environment)
6
- @environment = environment
7
- end
8
-
9
5
  def call
10
- aws_settings = GenerateAwsSettings.(environment).merge(
6
+ aws_settings = GenerateAwsSettings.().merge(
11
7
  endpoint: config_endpoint,
12
8
 
13
9
  # We don't want a profile for this AWS service
@@ -23,7 +19,7 @@ module ExercismConfig
23
19
 
24
20
  memoize
25
21
  def config_endpoint
26
- case environment
22
+ case Exercism.environment
27
23
  when :development, :test
28
24
  host = ENV["EXERCISM_DOCKER"] ? "dynamodb:8000" : "localhost:3039"
29
25
  "http://#{host}"
@@ -1,3 +1,3 @@
1
1
  module ExercismConfig
2
- VERSION = "0.14.0"
2
+ VERSION = "0.19.0"
3
3
  end
@@ -0,0 +1,7 @@
1
+ aws_iterations_bucket: exercism-staging-iterations
2
+ dynamodb_tooling_jobs_table: tooling_jobs
3
+ tooling_orchestrator_url: http://127.0.0.1:3021
4
+ anycable_redis_url: 'redis://127.0.0.1:6379/1'
5
+ anycable_rpc_host: '127.0.0.1:50051'
6
+ rds_master_endpoint: localhost
7
+ mysql_socket: /tmp/mysql.sock
@@ -0,0 +1,7 @@
1
+ aws_iterations_bucket: exercism-staging-iterations
2
+ dynamodb_tooling_jobs_table: tooling_jobs
3
+ tooling_orchestrator_url: http://tooling-orchestrator:3021
4
+ anycable_redis_url: redis://redis:6379/1
5
+ anycable_rpc_host: 0.0.0.0:50051
6
+ rds_master_endpoint: mysql
7
+ rds_port: 3306
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: exercism_config
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.14.0
4
+ version: 0.19.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Walker
8
8
  autorequire:
9
- bindir: exe
9
+ bindir: bin
10
10
  cert_chain: []
11
- date: 2020-07-28 00:00:00.000000000 Z
11
+ date: 2020-07-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk-dynamodb
@@ -111,7 +111,8 @@ dependencies:
111
111
  description:
112
112
  email:
113
113
  - jez.walker@gmail.com
114
- executables: []
114
+ executables:
115
+ - setup_exercism_config
115
116
  extensions: []
116
117
  extra_rdoc_files: []
117
118
  files:
@@ -122,15 +123,18 @@ files:
122
123
  - README.md
123
124
  - Rakefile
124
125
  - bin/console
125
- - bin/run
126
126
  - bin/setup
127
+ - bin/setup_exercism_config
127
128
  - exercism_config.gemspec
128
129
  - lib/exercism/config.rb
129
130
  - lib/exercism_config.rb
131
+ - lib/exercism_config/determine_environment.rb
130
132
  - lib/exercism_config/generate_aws_settings.rb
131
133
  - lib/exercism_config/retrieve.rb
132
134
  - lib/exercism_config/setup_dynamodb_client.rb
133
135
  - lib/exercism_config/version.rb
136
+ - settings-development.yml
137
+ - settings-docker.yml
134
138
  homepage: https://exercism.io
135
139
  licenses: []
136
140
  metadata:
data/bin/run DELETED
@@ -1,6 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "bundler/setup"
4
- require "exercism_config"
5
-
6
- p ExercismConfig.config.to_h