modulorails 1.3.2 → 1.4.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +14 -0
- data/lib/generators/modulorails/docker/templates/Dockerfile.prod.tt +1 -0
- data/lib/generators/modulorails/docker/templates/docker-compose.prod.yml.tt +1 -1
- data/lib/generators/modulorails/docker/templates/docker-compose.yml.tt +1 -1
- data/lib/generators/modulorails/gitlabci/templates/.gitlab-ci.yml.tt +1 -1
- data/lib/generators/modulorails/healthcheck/templates/config/initializers/health_check.rb.tt +1 -1
- data/lib/generators/modulorails/self_update/self_update_generator.rb +30 -8
- data/lib/modulorails/railtie.rb +17 -20
- data/lib/modulorails/version.rb +1 -1
- data/lib/modulorails.rb +3 -21
- metadata +2 -3
- data/lib/modulorails/validators/database_configuration.rb +0 -109
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8b498ef768fd2c2f4bafdc603425d8e7125428410d2f74a2632df2fb7787767f
|
4
|
+
data.tar.gz: 73eb3a056a2407d5ff4140b63377e56019512a388bed98b4aa78853c69d88569
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4212615e5046474bc07d0f2a8d1393bd44fe8472fc107301cc3fd70437af2b692b4d14bde4ddc290eee6b5cfb7edd4107ce74579cc7b20960887fc463f8b6ed9
|
7
|
+
data.tar.gz: acd8a6ea0d748f60a8c621219b8a488a8e111158ba6aa0edc83045aab1d81db7a57c608b01c1302c7025e1d1ca61110b835a8ad14f567d035385ea4a8de22a43
|
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.1
|
8
|
+
|
9
|
+
- Fix auto-update.
|
10
|
+
|
11
|
+
# 1.4.0
|
12
|
+
|
13
|
+
- Remove custom from standard health_check checks.
|
14
|
+
- Update Postgres version from 15 to 16 in templates.
|
15
|
+
- Fix template of `Dockerfile.prod` to install valid version of `bundler`.
|
16
|
+
- Check required Ruby version of next Modulorails version before auto-update.
|
17
|
+
- Remove Modulorails::Validators::DatabaseConfiguration since, with Docker Compose, it is no more necessary.
|
18
|
+
|
5
19
|
# 1.3.2
|
6
20
|
|
7
21
|
- Fix missing symbol in docker and gitlabci generators.
|
data/lib/generators/modulorails/healthcheck/templates/config/initializers/health_check.rb.tt
CHANGED
@@ -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
|
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
|
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
|
-
|
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
|
-
|
23
|
-
|
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', '= #{
|
35
|
+
"gem 'modulorails', '= #{version}'"
|
28
36
|
|
29
37
|
# Update the gem and the Gemfile.lock
|
30
38
|
system('bundle install')
|
@@ -32,4 +40,18 @@ 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
|
+
Modulorails::COMPARABLE_RUBY_VERSION.send(comparison_method, required_version)
|
50
|
+
rescue StandardError => e
|
51
|
+
warn("[ruby_version_supported_by_next_gem_version?] An error occured: #{e.message}")
|
52
|
+
|
53
|
+
# If we cannot be sure of Ruby compatibility, do nothing
|
54
|
+
false
|
55
|
+
end
|
56
|
+
|
35
57
|
end
|
data/lib/modulorails/railtie.rb
CHANGED
@@ -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
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
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
|
-
|
39
|
-
# Load translations
|
40
|
-
I18n.load_path += [File.expand_path('../../config/locales/en.yml', __dir__)]
|
38
|
+
next unless Rails.env.development?
|
41
39
|
|
42
|
-
|
43
|
-
|
40
|
+
# Load translations
|
41
|
+
I18n.load_path += [File.expand_path('../../config/locales/en.yml', __dir__)]
|
44
42
|
|
45
|
-
|
46
|
-
|
43
|
+
# Effectively send the data to the intranet
|
44
|
+
Modulorails.send_data
|
47
45
|
|
48
|
-
|
49
|
-
|
46
|
+
# Generate a template for CI/CD
|
47
|
+
Modulorails.generate_ci_template
|
50
48
|
|
51
|
-
|
52
|
-
|
49
|
+
# Add/update Rubocop config
|
50
|
+
Modulorails.generate_rubocop_template
|
53
51
|
|
54
|
-
|
55
|
-
|
52
|
+
# Add/update Bundler-audit config
|
53
|
+
Modulorails.generate_bundleraudit_template
|
56
54
|
|
57
|
-
|
58
|
-
|
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
|
data/lib/modulorails/version.rb
CHANGED
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
|
-
|
145
|
-
|
146
|
-
|
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.
|
4
|
+
version: 1.4.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matthieu Ciappara
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-04-11 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
|