modulorails 1.3.1 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6a06133e9c157d574ab3cc83ffd931e7e61873d7c8deff63c22b8a0657def075
4
- data.tar.gz: d345aa7aa32575496041762e43f198001260a003dc811c69ae704f889dde0411
3
+ metadata.gz: 760fd66e14c2550bed2b01153e1ffbf34feefd585c106f5efb908d1830bfdda9
4
+ data.tar.gz: 57eb6276ff9fd86b507f6821109787c9475a0590cc8d0a55d52f84d85f69c57e
5
5
  SHA512:
6
- metadata.gz: 1594ae1f801bf28f08ec2a86ecc6040f48c513d2c47a2dfb9f0a8a3b69bf2dd7f04d6465aff1041faf80759fb70610ff57a8b02b83bddf4cbdc3ab9c553bdb9b
7
- data.tar.gz: 4e4652c68c1ba65d1ce429c5acffbb5e11c8f82effdcdd55735d91cb8c12e442f6a00b5b5099a316b26f8620ef20873c96b5349df4ea58ec24566aaebe75abb1
6
+ metadata.gz: '06768653acec08475061e970b53c159a5aa46abba7d5ba7978329b8808239e692fc52795e99edc4ecee1ff3a23b56ebf742dfd3facc430ad0cdfb0a31a697b25'
7
+ data.tar.gz: f221ee806067c428292088a0a2fe65d8e241a63386abd2e30cece257fb294151911fc271bce731d60136ffb0dea96bd458dcf3a5b6c3563be1e518809b0f9407
data/CHANGELOG.md CHANGED
@@ -2,6 +2,20 @@
2
2
 
3
3
  This file is used to list changes made in each version of the gem.
4
4
 
5
+ # Unreleased
6
+
7
+ # 1.4.0
8
+
9
+ - Remove custom from standard health_check checks.
10
+ - Update Postgres version from 15 to 16 in templates.
11
+ - Fix template of `Dockerfile.prod` to install valid version of `bundler`.
12
+ - Check required Ruby version of next Modulorails version before auto-update.
13
+ - Remove Modulorails::Validators::DatabaseConfiguration since, with Docker Compose, it is no more necessary.
14
+
15
+ # 1.3.2
16
+
17
+ - Fix missing symbol in docker and gitlabci generators.
18
+
5
19
  # 1.3.1
6
20
 
7
21
  - Update templates according to new devops standards:
@@ -9,8 +9,8 @@ class Modulorails::DockerGenerator < Rails::Generators::Base
9
9
 
10
10
  def create_config_file
11
11
  @data = Modulorails.data
12
- @adapter = data.adapter
13
- @webpack_container_needed = data.webpacker_version.present?
12
+ @adapter = @data.adapter
13
+ @webpack_container_needed = @data.webpacker_version.present?
14
14
  @image_name = @data.name.parameterize
15
15
  @environment_name = @data.environment_name
16
16
 
@@ -52,6 +52,7 @@ RUN apk add --update --no-cache \
52
52
  postgresql-dev \
53
53
  <%- end -%>
54
54
  && rm -rf .git/
55
+ RUN gem install bundler -v <%= @data.bundler_version %>
55
56
 
56
57
  COPY --from=builder /app .
57
58
 
@@ -30,7 +30,7 @@ services:
30
30
  MYSQL_ROOT_HOST: '%'
31
31
  <%- else -%>
32
32
  database:
33
- image: postgres:15-alpine
33
+ image: postgres:16-alpine
34
34
  volumes:
35
35
  - db_data:/var/lib/postgresql/data
36
36
  environment:
@@ -34,7 +34,7 @@ services:
34
34
  MYSQL_ROOT_HOST: '%'
35
35
  <%- else -%>
36
36
  database:
37
- image: postgres:15-alpine
37
+ image: postgres:16-alpine
38
38
  volumes:
39
39
  - db_data:/var/lib/postgresql/data
40
40
  environment:
@@ -11,7 +11,7 @@ class Modulorails::GitlabciGenerator < Rails::Generators::Base
11
11
  @data = Modulorails.data
12
12
  @image_name = @data.name.parameterize
13
13
  @environment_name = @data.environment_name
14
- @adapter = data.adapter
14
+ @adapter = @data.adapter
15
15
  @review_base_url = @data.review_base_url
16
16
  @staging_url = @data.staging_url
17
17
  @production_url = @data.production_url
@@ -32,7 +32,7 @@ test:
32
32
  <%- if @adapter =~ /mysql/ -%>
33
33
  - mysql:8-alpine
34
34
  <%- else -%>
35
- - postgres:15-alpine
35
+ - postgres:16-alpine
36
36
  <%- end -%>
37
37
  - redis:7-alpine
38
38
  variables:
@@ -35,7 +35,7 @@ HealthCheck.setup do |config|
35
35
  # config.buckets = { 'bucket_name' => %i[R W D] }
36
36
 
37
37
  # You can customize which checks happen on a standard health check, eg to set an explicit list use:
38
- config.standard_checks = %w[database migrations custom]
38
+ config.standard_checks = %w[database migrations]
39
39
 
40
40
  # Or to exclude one check:
41
41
  config.standard_checks -= %w[emailconf]
@@ -9,22 +9,30 @@ class Modulorails::SelfUpdateGenerator < Rails::Generators::Base
9
9
  source_root File.expand_path('templates', __dir__)
10
10
  desc 'This generator updates Modulorails if required'
11
11
 
12
- LATEST_VERSION_URL = 'https://rubygems.org/api/v1/versions/modulorails/latest.json'
12
+ LATEST_VERSION_URL = 'https://rubygems.org/api/v1/versions/modulorails.json'
13
13
 
14
14
  def create_config_file
15
- modulorails_version = Gem::Version.new(Modulorails::VERSION)
16
-
17
15
  # Get the last published version
18
- last_published_version_s = HTTParty.get(LATEST_VERSION_URL).parsed_response['version']
19
- last_published_version = Gem::Version.new(last_published_version_s)
16
+ last_published_version = HTTParty.get(LATEST_VERSION_URL).parsed_response.first
20
17
 
21
18
  # Do nothing if we could not fetch the last published version (whatever the reason)
22
- # Or if the current version is the same as the last published version
23
- return if last_published_version <= modulorails_version
19
+ return if last_published_version.nil?
20
+
21
+ requirement = last_published_version['ruby_version']
22
+ unless ruby_version_supported_by_next_gem_version?(requirement)
23
+ warn("Next Modulorails version requires Ruby version #{requirement}. You should update.")
24
+ return
25
+ end
26
+
27
+ modulorails_version = Gem::Version.new(Modulorails::VERSION)
28
+
29
+ # Do nothing if the current version is the same as the last published version
30
+ version = Gem::Version.new(last_published_version['number'])
31
+ return if version <= modulorails_version
24
32
 
25
33
  # Add gem to Gemfile
26
34
  gsub_file 'Gemfile', /^\s*gem\s['"]modulorails['"].*$/,
27
- "gem 'modulorails', '= #{last_published_version}'"
35
+ "gem 'modulorails', '= #{version}'"
28
36
 
29
37
  # Update the gem and the Gemfile.lock
30
38
  system('bundle install')
@@ -32,4 +40,16 @@ class Modulorails::SelfUpdateGenerator < Rails::Generators::Base
32
40
  warn("[Modulorails] Error: cannot generate health_check configuration: #{e.message}")
33
41
  end
34
42
 
43
+ private
44
+
45
+ def ruby_version_supported_by_next_gem_version?(requirement_string)
46
+ requirement = Gem::Requirement.new(requirement_string).requirements.first
47
+ comparison_method, required_version = requirement
48
+
49
+ COMPARABLE_RUBY_VERSION.send(comparison_method, required_version)
50
+ rescue StandardError
51
+ # If we cannot be sure of Ruby compatibility, do nothing
52
+ false
53
+ end
54
+
35
55
  end
@@ -8,10 +8,10 @@ module Modulorails
8
8
  # Update and add gems before we load the configuration
9
9
  config.before_configuration do
10
10
  # Currently, we limit everything to the development environment
11
- if Rails.env.development?
12
- # Check database configuration
13
- Modulorails.generate_healthcheck_template
14
- end
11
+ next unless Rails.env.development?
12
+
13
+ # Check database configuration
14
+ Modulorails.generate_healthcheck_template
15
15
  end
16
16
 
17
17
  # Require the gem before we read the health_check initializer
@@ -35,28 +35,25 @@ module Modulorails
35
35
  # all gems, constants and configurations we might need.
36
36
  config.after_initialize do
37
37
  # Currently, we limit everything to the development environment
38
- if Rails.env.development?
39
- # Load translations
40
- I18n.load_path += [File.expand_path('../../config/locales/en.yml', __dir__)]
38
+ next unless Rails.env.development?
41
39
 
42
- # Effectively send the data to the intranet
43
- Modulorails.send_data
40
+ # Load translations
41
+ I18n.load_path += [File.expand_path('../../config/locales/en.yml', __dir__)]
44
42
 
45
- # Generate a template for CI/CD
46
- Modulorails.generate_ci_template
43
+ # Effectively send the data to the intranet
44
+ Modulorails.send_data
47
45
 
48
- # Check database configuration
49
- Modulorails.check_database_config
46
+ # Generate a template for CI/CD
47
+ Modulorails.generate_ci_template
50
48
 
51
- # Add/update Rubocop config
52
- Modulorails.generate_rubocop_template
49
+ # Add/update Rubocop config
50
+ Modulorails.generate_rubocop_template
53
51
 
54
- # Add/update Bundler-audit config
55
- Modulorails.generate_bundleraudit_template
52
+ # Add/update Bundler-audit config
53
+ Modulorails.generate_bundleraudit_template
56
54
 
57
- # Gem's self-update if a new version was released
58
- Modulorails.self_update
59
- end
55
+ # Gem's self-update if a new version was released
56
+ Modulorails.self_update
60
57
  end
61
58
 
62
59
  end
@@ -1,6 +1,6 @@
1
1
  module Modulorails
2
2
 
3
- VERSION = '1.3.1'.freeze
3
+ VERSION = '1.4.0'.freeze
4
4
 
5
5
  # Useful to compare the current Ruby version
6
6
  COMPARABLE_RUBY_VERSION = Gem::Version.new(RUBY_VERSION)
data/lib/modulorails.rb CHANGED
@@ -1,7 +1,6 @@
1
1
  require 'modulorails/version'
2
2
  require 'modulorails/configuration'
3
3
  require 'modulorails/data'
4
- require 'modulorails/validators/database_configuration'
5
4
  require 'modulorails/railtie' if defined?(Rails::Railtie)
6
5
  require 'generators/modulorails/gitlabci/gitlabci_generator'
7
6
  require 'generators/modulorails/healthcheck/health_check_generator'
@@ -120,31 +119,14 @@ module Modulorails
120
119
  Modulorails::GitlabciGenerator.new([], {}, {}).invoke_all
121
120
  end
122
121
 
123
- # @author Matthieu 'ciappa_m' Ciappara
124
- #
125
- # Check the database configuration respects Modulotech's norms
126
- def check_database_config
127
- invalid_rules = Modulorails::Validators::DatabaseConfiguration.call
128
- return true if invalid_rules.empty?
129
-
130
- puts('[Modulorails] The database configuration (config/database.yml) has warnings:')
131
- invalid_rules.each do |rule|
132
- t_rule = I18n.t(rule, scope: :modulorails, locale: :en)
133
- puts("[Modulorails] Invalid database configuration: #{t_rule}")
134
- end
135
-
136
- false
137
- end
138
-
139
122
  # @author Matthieu 'ciappa_m' Ciappara
140
123
  #
141
124
  # Check the last version of Modulorails available on rubygems and update if there was a
142
125
  # publication
143
126
  def self_update
144
- unless configuration.no_auto_update
145
- Modulorails::SelfUpdateGenerator.new([], {},
146
- {}).invoke_all
147
- end
127
+ return if configuration.no_auto_update
128
+
129
+ Modulorails::SelfUpdateGenerator.new([], {}, {}).invoke_all
148
130
  rescue StandardError => e
149
131
  puts("[Modulorails] An error occured: #{e.class} - #{e.message}")
150
132
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: modulorails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.1
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthieu Ciappara
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-04-19 00:00:00.000000000 Z
11
+ date: 2024-04-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: git
@@ -239,7 +239,6 @@ files:
239
239
  - lib/modulorails/services/logs_for_method_service.rb
240
240
  - lib/modulorails/services/services.rb
241
241
  - lib/modulorails/success_data.rb
242
- - lib/modulorails/validators/database_configuration.rb
243
242
  - lib/modulorails/version.rb
244
243
  - modulorails.gemspec
245
244
  homepage: https://github.com/moduloTech/modulorails
@@ -1,109 +0,0 @@
1
- module Modulorails
2
-
3
- module Validators
4
-
5
- # Author: Matthieu 'ciappa_m' Ciappara
6
- # This holds the rules to configure the database by respecting Modulotech's norms.
7
- class DatabaseConfiguration
8
-
9
- def initialize
10
- # All rules are invalid by default
11
- @rules = {
12
- standard_config_file_location: false,
13
- test_database_not_equals_dev_database: false,
14
- development: {
15
- configurable_username: false,
16
- configurable_password: false,
17
- configurable_database: false,
18
- configurable_host: false,
19
- configurable_port: false
20
- },
21
- test: {
22
- configurable_username: false,
23
- configurable_password: false,
24
- configurable_database: false,
25
- configurable_host: false,
26
- configurable_port: false
27
- }
28
- }
29
- end
30
-
31
- def self.call
32
- new.call
33
- end
34
-
35
- def call
36
- database_configuration = check_standard_config_file_location
37
- return [:standard_config_file_location] unless database_configuration
38
-
39
- check_test_database_not_equals_dev_database(database_configuration)
40
- check_rules_for_environment(database_configuration, :development)
41
- check_rules_for_environment(database_configuration, :test)
42
-
43
- fetch_invalid_rules
44
- end
45
-
46
- private
47
-
48
- def fetch_invalid_rules
49
- dev = select_invalid_keys(@rules[:development]).map { |k| "development.#{k}" }
50
- test = select_invalid_keys(@rules[:test]).map { |k| "test.#{k}" }
51
- general = select_invalid_keys(@rules)
52
-
53
- general + dev + test
54
- end
55
-
56
- def select_invalid_keys(hash)
57
- hash.select { |_k, v| v == false }.keys
58
- end
59
-
60
- def check_standard_config_file_location
61
- # Load the configuration
62
- config = if Modulorails::COMPARABLE_RUBY_VERSION >= Gem::Version.new('3.1')
63
- # Ruby 3.1 uses Psych4 which changes the default way of handling aliases in
64
- # `load_file`.
65
- Psych.load_file(Rails.root.join('config/database.yml'), aliases: true)
66
- else
67
- Psych.load_file(Rails.root.join('config/database.yml'))
68
- end
69
-
70
- # If no exception was raised, then the database configuration file is at standard location
71
- @rules[:standard_config_file_location] = true
72
-
73
- config
74
- rescue StandardError
75
- # An exception was raised, either the file is not a the standard location, either it just
76
- # cannot be read. Either way, we consider the config as invalid
77
- @rules[:standard_config_file_location] = false
78
- nil
79
- end
80
-
81
- # The database for tests MUST NOT be the same as the development database since the test
82
- # database is rewritten each time the tests are launched
83
- def check_test_database_not_equals_dev_database(config)
84
- @rules[:test_database_not_equals_dev_database] =
85
- config['test']['database'] != config['development']['database']
86
- end
87
-
88
- # Check all rules for an environment
89
- def check_rules_for_environment(config, env)
90
- @rules[env].each_key do |rule|
91
- key = rule.to_s.gsub(/configurable_/, '')
92
- check_configurable_key_for_environment(config, env, key)
93
- end
94
- end
95
-
96
- # Check if the given key is configurable for the given environment
97
- def check_configurable_key_for_environment(config, env, key)
98
- valid_rule = config[env.to_s][key] =~ /<%=\s*ENV\.fetch\(\S+,\s*\S+\)\s*%>/
99
- valid_rule ||= config[env.to_s][key] =~ /<%=\s*ENV\.fetch\(.+\)\s*\{\s*\S+\s*\}\s*%>/
100
-
101
- # Use of `!!` to convert `nil` to `false` and `0` to `true`
102
- @rules[env][:"configurable_#{key}"] = !!valid_rule
103
- end
104
-
105
- end
106
-
107
- end
108
-
109
- end