modulorails 1.5.1 → 1.5.2.pre.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (29) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +1 -0
  3. data/CHANGELOG.md +10 -1
  4. data/lib/generators/modulorails/bundleraudit/bundleraudit_generator.rb +2 -0
  5. data/lib/generators/modulorails/docker/compose/compose_generator.rb +32 -0
  6. data/lib/generators/modulorails/docker/config/config_generator.rb +33 -0
  7. data/lib/generators/modulorails/docker/{templates → config/templates}/config/database.yml.tt +1 -1
  8. data/lib/generators/modulorails/docker/docker_generator.rb +18 -79
  9. data/lib/generators/modulorails/docker/dockerfile/dockerfile_generator.rb +47 -0
  10. data/lib/generators/modulorails/docker/{templates → dockerfile/templates}/dockerfiles/rails/Dockerfile.prod.tt +5 -0
  11. data/lib/generators/modulorails/docker/entrypoint/entrypoint_generator.rb +43 -0
  12. data/lib/generators/modulorails/docker/{templates → entrypoint/templates}/entrypoints/docker-entrypoint.sh.tt +6 -0
  13. data/lib/generators/modulorails/githooks/githooks_generator.rb +3 -0
  14. data/lib/generators/modulorails/githooks/templates/dockeruby.rb +10 -12
  15. data/lib/generators/modulorails/gitlabci/gitlabci_generator.rb +5 -0
  16. data/lib/generators/modulorails/health_check/health_check_generator.rb +2 -4
  17. data/lib/generators/modulorails/health_check/templates/config/initializers/health_check.rb.tt +75 -73
  18. data/lib/generators/modulorails/moduloproject/moduloproject_generator.rb +3 -0
  19. data/lib/modulorails/generators/base.rb +56 -16
  20. data/lib/modulorails/generators/docker_base.rb +19 -0
  21. data/lib/modulorails/version.rb +1 -1
  22. metadata +17 -12
  23. /data/lib/generators/modulorails/docker/{templates → compose/templates}/docker-compose.yml.tt +0 -0
  24. /data/lib/generators/modulorails/docker/{templates → config/templates}/config/cable.yml.tt +0 -0
  25. /data/lib/generators/modulorails/docker/{templates → config/templates}/config/initializers/0_redis.rb +0 -0
  26. /data/lib/generators/modulorails/docker/{templates → config/templates}/config/puma.rb +0 -0
  27. /data/lib/generators/modulorails/docker/{templates → dockerfile/templates}/dockerfiles/modulotech/Dockerfile.prod.tt +0 -0
  28. /data/lib/generators/modulorails/docker/{templates → dockerfile/templates}/dockerfiles/modulotech/Dockerfile.tt +0 -0
  29. /data/lib/generators/modulorails/docker/{templates → entrypoint/templates}/entrypoints/webpack-entrypoint.sh.tt +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 49cd77852f9aee93c053c1722f8332ad44fa712f2ff00830ddd44ab0e873a722
4
- data.tar.gz: 6ce2b6f0314ee71f843bdc4f012ceda11ead2b326e98e954b517e334e1646fde
3
+ metadata.gz: 642a5558736412d881a524f70520f9b87a822cae9c214bc466d85275fa7e8da0
4
+ data.tar.gz: d8a2f4ce6c322adc97bcaa307a9d962fd4f4fba9584d53ca7570bcf84dbce78c
5
5
  SHA512:
6
- metadata.gz: 104ac0e4ab98f6194fec633367c0a87b25198fa5c8f0aef3cadac808ff8328c1c96fa1b11bd6881690f414c0400b9eacfc86a083c982a60e87039358c5ad8274
7
- data.tar.gz: 3652ed356e878e708d54ae4d17cb18707afd7deabe57846cacdb2fc53caff699ae1c0cb3a932699a0829fd01be80978a406960df7eb534fec1c16daa1b124c36
6
+ metadata.gz: 22d1f0cd41c5735472424928d1730d2a5654c5c18eceaa305222023ba1b4d6dcbfc706ab3869c56ef003a4f6df17ba9c0b48a31e76cda540767f297ac5ae48e4
7
+ data.tar.gz: 3e534b69d74a1aec16bd9bece3b1e52ca9d6c108ce66e8cacd6d2eb804b4cc941cadb3851beef0e4aba6ed0db11a922d1c7cd3fc332edcf93e5bb6530ec90fd5
data/.rubocop.yml CHANGED
@@ -38,6 +38,7 @@ AllCops:
38
38
  - 'test/**/*'
39
39
  - 'node_modules/**/*'
40
40
  - 'spec/**/*'
41
+ - '**/templates/**/*'
41
42
 
42
43
  # Instructing rubocop about all standard Modulotech environments.
43
44
  Rails/UnknownEnv:
data/CHANGELOG.md CHANGED
@@ -4,6 +4,15 @@ This file is used to list changes made in each version of the gem.
4
4
 
5
5
  # Unreleased
6
6
 
7
+ # 1.5.2
8
+
9
+ - Fix typo in `database.yml` template for test database.
10
+ - Fix removal of rails' server's pidfile in docker entrypoint.
11
+ - Split DockerGenerator in multiple sub-generators to version each one individually.
12
+ - Merge all keepfiles in one.
13
+ - Wrap health_check initializer in a reloader.to_prepare block.
14
+ - Always use latest ruby in dockeruby.
15
+
7
16
  # 1.5.1
8
17
 
9
18
  - Update templates according to new standards:
@@ -30,7 +39,7 @@ This file is used to list changes made in each version of the gem.
30
39
 
31
40
  # 1.5.0
32
41
 
33
- - Released then
42
+ - Released then yanked for critical bugs.
34
43
 
35
44
  # 1.4.0.1
36
45
 
@@ -4,6 +4,8 @@ require 'modulorails/generators/base'
4
4
 
5
5
  class Modulorails::BundlerauditGenerator < Modulorails::Generators::Base
6
6
 
7
+ VERSION = 1
8
+
7
9
  desc 'This generator creates a configuration for Bundler-Audit'
8
10
 
9
11
  protected
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'modulorails/generators/docker_base'
4
+
5
+ module Modulorails
6
+
7
+ module Docker
8
+
9
+ class ComposeGenerator < ::Modulorails::Generators::DockerBase
10
+
11
+ VERSION = 1
12
+
13
+ desc 'This generator creates Docker Compose configuration'
14
+
15
+ protected
16
+
17
+ def create_config
18
+ @data = Modulorails.data
19
+ @adapter = @data.adapter
20
+ @webpack_container_needed = @data.webpacker_version.present?
21
+ @image_name = @data.name.parameterize
22
+
23
+ create_new_file('docker-compose.yml', 'compose.yml', executable: false)
24
+ rescue StandardError => e
25
+ warn("[Modulorails] Error: cannot generate Docker Compose configuration: #{e.message}")
26
+ end
27
+
28
+ end
29
+
30
+ end
31
+
32
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'modulorails/generators/docker_base'
4
+
5
+ module Modulorails
6
+
7
+ module Docker
8
+
9
+ class ConfigGenerator < Modulorails::Generators::DockerBase
10
+
11
+ VERSION = 1
12
+
13
+ desc 'This generator creates application configuration'
14
+
15
+ protected
16
+
17
+ def create_config
18
+ @data = Modulorails.data
19
+ @adapter = @data.adapter
20
+
21
+ template 'config/database.yml'
22
+ template 'config/cable.yml'
23
+ template 'config/initializers/0_redis.rb'
24
+ template 'config/puma.rb'
25
+ rescue StandardError => e
26
+ warn("[Modulorails] Error: cannot generate application configuration: #{e.message}")
27
+ end
28
+
29
+ end
30
+
31
+ end
32
+
33
+ end
@@ -8,7 +8,7 @@ development: &default
8
8
 
9
9
  test:
10
10
  <<: *default
11
- database: <%%= ENV['DTABASE_TEST_URL'] %>
11
+ database: <%%= ENV['DATABASE_TEST_URL'] %>
12
12
 
13
13
  staging:
14
14
  <<: *default
@@ -1,94 +1,33 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'modulorails/generators/base'
4
+ require 'generators/modulorails/docker/entrypoint/entrypoint_generator'
5
+ require 'generators/modulorails/docker/dockerfile/dockerfile_generator'
6
+ require 'generators/modulorails/docker/compose/compose_generator'
7
+ require 'generators/modulorails/docker/config/config_generator'
4
8
 
5
- class Modulorails::DockerGenerator < Modulorails::Generators::Base
9
+ module Modulorails
6
10
 
7
- VERSION = 2
11
+ class DockerGenerator < Modulorails::Generators::Base
8
12
 
9
- desc 'This generator creates Docker configuration for an app'
13
+ VERSION = false
10
14
 
11
- protected
15
+ desc 'This generator creates Docker configuration for an app'
12
16
 
13
- def create_config
14
- @data = Modulorails.data
15
- @adapter = @data.adapter
16
- @webpack_container_needed = @data.webpacker_version.present?
17
- @image_name = @data.name.parameterize
18
- @environment_name = @data.environment_name
17
+ protected
19
18
 
20
- create_dockerfile
21
- create_dockerfile_prod
22
- create_compose_yml
23
- create_docker_entrypoint
24
- template 'config/database.yml'
25
- template 'config/cable.yml'
26
- template 'config/initializers/0_redis.rb'
27
- template 'config/puma.rb'
19
+ def create_config
20
+ remove_old_keepfile('.modulorails-docker')
28
21
 
29
- # Useless unless project is using Webpacker
30
- return unless @webpack_container_needed
31
-
32
- create_webpack_entrypoint
33
- rescue StandardError => e
34
- warn("[Modulorails] Error: cannot generate Docker configuration: #{e.message}")
35
- end
36
-
37
- private
38
-
39
- def create_dockerfile
40
- say('WARNING: The entrypoint was moved. Check that your Dockerfile still works.') if File.exist?('Dockerfile')
41
- template 'dockerfiles/modulotech/Dockerfile', 'Dockerfile'
42
- end
43
-
44
- def create_webpack_entrypoint
45
- create_new_file('entrypoints/webpack-entrypoint.sh', 'bin/webpack-entrypoint')
46
- end
47
-
48
- def create_docker_entrypoint
49
- create_new_file 'entrypoints/docker-entrypoint.sh', 'bin/docker-entrypoint'
50
- end
51
-
52
- def create_compose_yml
53
- create_new_file 'docker-compose.yml', 'compose.yml', executable: false
54
- end
55
-
56
- def create_dockerfile_prod
57
- if File.exist?('Dockerfile.prod')
58
- say('WARNING: The entrypoint was moved. Check that your Dockerfile.prod still works.')
59
- end
60
-
61
- if Gem::Version.new(@data.rails_version) >= Gem::Version.new('7.2')
62
- template 'dockerfiles/rails/Dockerfile.prod', 'Dockerfile.prod'
63
- else
64
- template 'dockerfiles/modulotech/Dockerfile.prod', 'Dockerfile.prod'
65
- end
66
- end
67
-
68
- def create_new_file(old_file, new_file, executable: true)
69
- if File.exist?(old_file)
70
- copy_original_file old_file, new_file
71
- remove_file old_file
72
- else
73
- template old_file, new_file
22
+ # Running first since the Dockerfile generator checks for existence of entrypoint
23
+ Modulorails::Docker::EntrypointGenerator.new([], {}, {}).invoke_all
24
+ Modulorails::Docker::DockerfileGenerator.new([], {}, {}).invoke_all
25
+ Modulorails::Docker::ComposeGenerator.new([], {}, {}).invoke_all
26
+ Modulorails::Docker::ConfigGenerator.new([], {}, {}).invoke_all
27
+ rescue StandardError => e
28
+ warn("[Modulorails] Error: cannot generate Docker configuration: #{e.message}")
74
29
  end
75
- chmod new_file, 0o755 if executable
76
- end
77
-
78
- def copy_original_file(source, *args, &block)
79
- config = args.last.is_a?(Hash) ? args.pop : {}
80
- destination = args.first || source
81
- source = File.expand_path(source, destination_root)
82
30
 
83
- create_file destination, nil, config do
84
- content = File.binread(source)
85
- content = yield(content) if block
86
- content
87
- end
88
- if config[:mode] == :preserve
89
- mode = File.stat(source).mode
90
- chmod(destination, mode, config)
91
- end
92
31
  end
93
32
 
94
33
  end
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'modulorails/generators/docker_base'
4
+
5
+ module Modulorails
6
+
7
+ module Docker
8
+
9
+ class DockerfileGenerator < ::Modulorails::Generators::DockerBase
10
+
11
+ VERSION = 1
12
+
13
+ desc 'This generator creates Dockerfiles'
14
+
15
+ protected
16
+
17
+ def create_config
18
+ @data = Modulorails.data
19
+ @adapter = @data.adapter
20
+ @webpack_container_needed = @data.webpacker_version.present?
21
+
22
+ EntrypointGenerator.new([], {}, {}).invoke_all unless File.exist?('bin/docker-entrypoint')
23
+ create_dockerfile
24
+ create_dockerfile_prod
25
+ rescue StandardError => e
26
+ warn("[Modulorails] Error: cannot generate Dockerfiles: #{e.message}")
27
+ end
28
+
29
+ private
30
+
31
+ def create_dockerfile
32
+ template 'dockerfiles/modulotech/Dockerfile', 'Dockerfile'
33
+ end
34
+
35
+ def create_dockerfile_prod
36
+ if Gem::Version.new(@data.rails_version) >= Gem::Version.new('7.2')
37
+ template 'dockerfiles/rails/Dockerfile.prod', 'Dockerfile.prod'
38
+ else
39
+ template 'dockerfiles/modulotech/Dockerfile.prod', 'Dockerfile.prod'
40
+ end
41
+ end
42
+
43
+ end
44
+
45
+ end
46
+
47
+ end
@@ -54,6 +54,11 @@ RUN bundle install && \
54
54
  rm -rf ~/.bundle/ "${BUNDLE_PATH}"/ruby/*/cache "${BUNDLE_PATH}"/ruby/*/bundler/gems/*/.git && \
55
55
  bundle exec bootsnap precompile --gemfile
56
56
 
57
+ <%- if @webpack_container_needed -%>
58
+ COPY package.json yarn.lock ./
59
+ RUN yarn install
60
+ <%- end-%>
61
+
57
62
  # Copy application code
58
63
  COPY . .
59
64
 
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'modulorails/generators/docker_base'
4
+ require 'generators/modulorails/sidekiq/sidekiq_generator'
5
+
6
+ module Modulorails
7
+
8
+ module Docker
9
+
10
+ class EntrypointGenerator < Modulorails::Generators::DockerBase
11
+
12
+ VERSION = 1
13
+
14
+ desc 'This generator creates Docker entrypoints'
15
+
16
+ protected
17
+
18
+ def create_config
19
+ create_docker_entrypoint
20
+ create_webpack_entrypoint if Modulorails.data.webpacker_version.present?
21
+
22
+ if File.exist?('entrypoints/sidekiq-entrypoint.sh') || File.exist?('bin/sidekiq-entrypoint')
23
+ SidekiqGenerator.new([], {}, {}).invoke('add_entrypoint')
24
+ end
25
+ rescue StandardError => e
26
+ warn("[Modulorails] Error: cannot generate Docker entrypoints: #{e.message}")
27
+ end
28
+
29
+ private
30
+
31
+ def create_webpack_entrypoint
32
+ create_new_file('entrypoints/webpack-entrypoint.sh', 'bin/webpack-entrypoint')
33
+ end
34
+
35
+ def create_docker_entrypoint
36
+ create_new_file 'entrypoints/docker-entrypoint.sh', 'bin/docker-entrypoint'
37
+ end
38
+
39
+ end
40
+
41
+ end
42
+
43
+ end
@@ -15,6 +15,12 @@ then
15
15
  yarn install
16
16
  fi
17
17
 
18
+ # Remove pidfile if it exists else the server will not launch
19
+ if [ -f tmp/pids/server.pid ]
20
+ then
21
+ rm tmp/pids/server.pid
22
+ fi
23
+
18
24
  # If running the rails server then create or migrate existing database
19
25
  if [ "$1" = "./bin/rails" ] && [ "$2" = "server" ]; then
20
26
  ./bin/rails db:prepare
@@ -6,9 +6,12 @@ module Modulorails
6
6
 
7
7
  class GithooksGenerator < Modulorails::Generators::Base
8
8
 
9
+ VERSION = 1
10
+
9
11
  protected
10
12
 
11
13
  def create_config
14
+ remove_old_keepfile('.modulorails-githooks')
12
15
  create_hook_executor
13
16
  create_refresh_generations_script
14
17
  create_git_hooks
@@ -35,7 +35,7 @@ def entrypoint_location
35
35
  md[1]
36
36
  end
37
37
 
38
- VALID_LAST_INSTRUCTION = /exec "\$\{?@}?"/
38
+ VALID_LAST_INSTRUCTION = /exec "\$\{?@}?"/.freeze
39
39
 
40
40
  def check_entrypoint(verbose: false)
41
41
  el = entrypoint_location
@@ -70,7 +70,7 @@ def executer_docker_run(docker_args, verbose: false)
70
70
 
71
71
  # Build the command string
72
72
  # rubocop:disable Layout/LineLength
73
- command = %(docker run --rm #{modulogem_gems_option} #{modulogem_option} -v '#{pwd}:/app/#{working_directory}' #{tty_option} -w '/app/#{working_directory}' ezveus/ruby:latest #{docker_args})
73
+ command = %(docker run --pull=always --rm #{modulogem_gems_option} #{modulogem_option} -v '#{pwd}:/app/#{working_directory}' #{tty_option} -w '/app/#{working_directory}' ruby:latest #{docker_args})
74
74
  # rubocop:enable Layout/LineLength
75
75
 
76
76
  puts(command) if verbose
@@ -97,20 +97,18 @@ def executer_compose_run(docker_args, verbose: false)
97
97
  exec(command)
98
98
  end
99
99
 
100
+ def contains_command(escaped_args)
101
+ escaped_args.each_with_index.any? do |arg, index|
102
+ !arg.start_with?('-') && (index.zero? || !escaped_args[index - 1].start_with?('-'))
103
+ end
104
+ end
105
+
100
106
  def main(args, verbose: false)
101
107
  # Escape each argument individually
102
108
  escaped_args = args.map { |arg| Shellwords.escape(arg) }
103
109
 
104
- # Check if the arguments contain a Ruby command or only options
105
- contains_command = false
106
- escaped_args.each_with_index do |arg, index|
107
- if !arg.start_with?('-') && (index.zero? || !escaped_args[index - 1].start_with?('-'))
108
- contains_command = true
109
- break
110
- end
111
- end
112
-
113
- docker_args = if contains_command
110
+ # Prefix the arguments with a `ruby` command if there is not already one
111
+ docker_args = if contains_command(escaped_args)
114
112
  escaped_args.join(' ')
115
113
  else
116
114
  "ruby #{escaped_args.join(' ')}"
@@ -4,11 +4,16 @@ require 'modulorails/generators/base'
4
4
 
5
5
  class Modulorails::GitlabciGenerator < Modulorails::Generators::Base
6
6
 
7
+ VERSION = 1
8
+
7
9
  desc 'This generator creates a template for a .gitlab-ci.yml file at root'
8
10
 
9
11
  protected
10
12
 
11
13
  def create_config
14
+ remove_old_keepfile('.modulorails-gitlab-ci')
15
+ remove_old_keepfile('.modulorails-gitlabci')
16
+
12
17
  @data = Modulorails.data
13
18
  @image_name = @data.name.parameterize
14
19
  @environment_name = @data.environment_name
@@ -11,6 +11,8 @@ class Modulorails::HealthCheckGenerator < Modulorails::Generators::Base
11
11
  protected
12
12
 
13
13
  def create_config
14
+ remove_old_keepfile('.modulorails-health_check')
15
+
14
16
  # Update the template
15
17
  template 'config/initializers/health_check.rb'
16
18
 
@@ -22,8 +24,4 @@ class Modulorails::HealthCheckGenerator < Modulorails::Generators::Base
22
24
  warn("[Modulorails] Error: cannot generate health_check configuration: #{e.message}")
23
25
  end
24
26
 
25
- def keep_file_name
26
- '.modulorails-health_check'
27
- end
28
-
29
27
  end
@@ -1,100 +1,102 @@
1
- HealthCheck.setup do |config|
1
+ Rails.application.reloader.to_prepare do
2
+ HealthCheck.setup do |config|
2
3
 
3
- # uri prefix (no leading slash)
4
- config.uri = 'health'
4
+ # uri prefix (no leading slash)
5
+ config.uri = 'health'
5
6
 
6
- # Text output upon success
7
- config.success = 'success'
7
+ # Text output upon success
8
+ config.success = 'success'
8
9
 
9
- # Text output upon failure
10
- config.failure = 'health_check failed'
10
+ # Text output upon failure
11
+ config.failure = 'health_check failed'
11
12
 
12
- # Disable the error message to prevent /health_check from leaking
13
- # sensitive information
14
- config.include_error_in_response_body = false
13
+ # Disable the error message to prevent /health_check from leaking
14
+ # sensitive information
15
+ config.include_error_in_response_body = false
15
16
 
16
- # Log level (success or failure message with error details is sent to rails log unless this is set to nil)
17
- config.log_level = 'info'
17
+ # Log level (success or failure message with error details is sent to rails log unless this is set to nil)
18
+ config.log_level = 'info'
18
19
 
19
- # Timeout in seconds used when checking smtp server
20
- config.smtp_timeout = 30.0
20
+ # Timeout in seconds used when checking smtp server
21
+ config.smtp_timeout = 30.0
21
22
 
22
- # http status code used when plain text error message is output
23
- # Set to 200 if you want your want to distinguish between partial (text does not include success) and
24
- # total failure of rails application (http status of 500 etc)
23
+ # http status code used when plain text error message is output
24
+ # Set to 200 if you want your want to distinguish between partial (text does not include success) and
25
+ # total failure of rails application (http status of 500 etc)
25
26
 
26
- config.http_status_for_error_text = 500
27
+ config.http_status_for_error_text = 500
27
28
 
28
- # http status code used when an error object is output (json or xml)
29
- # Set to 200 if you want to distinguish between partial (healthy property == false) and
30
- # total failure of rails application (http status of 500 etc)
29
+ # http status code used when an error object is output (json or xml)
30
+ # Set to 200 if you want to distinguish between partial (healthy property == false) and
31
+ # total failure of rails application (http status of 500 etc)
31
32
 
32
- config.http_status_for_error_object = 500
33
+ config.http_status_for_error_object = 500
33
34
 
34
- # bucket names to test connectivity - required only if s3 check used, access permissions can be mixed
35
- # config.buckets = { 'bucket_name' => %i[R W D] }
35
+ # bucket names to test connectivity - required only if s3 check used, access permissions can be mixed
36
+ # config.buckets = { 'bucket_name' => %i[R W D] }
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
+ # You can customize which checks happen on a standard health check, eg to set an explicit list use:
39
+ config.standard_checks = %w[database migrations]
39
40
 
40
- # Or to exclude one check:
41
- config.standard_checks -= %w[emailconf]
41
+ # Or to exclude one check:
42
+ config.standard_checks -= %w[emailconf]
42
43
 
43
- # You can set what tests are run with the 'full' or 'all' parameter
44
- config.full_checks = %w[database migrations custom email cache redis]
45
- # config.full_checks = %w[database migrations custom email cache redis sidekiq-redis s3]
44
+ # You can set what tests are run with the 'full' or 'all' parameter
45
+ config.full_checks = %w[database migrations custom email cache redis]
46
+ # config.full_checks = %w[database migrations custom email cache redis sidekiq-redis s3]
46
47
 
47
- # Add one or more custom checks that return a blank string if ok, or an error message if there is an error
48
- # config.add_custom_check do
49
- # CustomHealthCheck.perform_check # any code that returns blank on success and non blank string upon failure
50
- # end
48
+ # Add one or more custom checks that return a blank string if ok, or an error message if there is an error
49
+ # config.add_custom_check do
50
+ # CustomHealthCheck.perform_check # any code that returns blank on success and non blank string upon failure
51
+ # end
51
52
 
52
- # Add another custom check with a name, so you can call just specific custom checks. This can also be run using
53
- # the standard 'custom' check.
54
- # You can define multiple tests under the same name - they will be run one after the other.
55
- # config.add_custom_check('sometest') do
56
- # CustomHealthCheck.perform_another_check # any code that returns blank on success and non blank string upon failure
57
- # end
53
+ # Add another custom check with a name, so you can call just specific custom checks. This can also be run using
54
+ # the standard 'custom' check.
55
+ # You can define multiple tests under the same name - they will be run one after the other.
56
+ # config.add_custom_check('sometest') do
57
+ # CustomHealthCheck.perform_another_check # any code that returns blank on success and non blank string upon failure
58
+ # end
58
59
 
59
- # max-age of response in seconds
60
- # cache-control is public when max_age > 1 and basic_auth_username is not set
61
- # You can force private without authentication for longer max_age by
62
- # setting basic_auth_username but not basic_auth_password
63
- config.max_age = 1
60
+ # max-age of response in seconds
61
+ # cache-control is public when max_age > 1 and basic_auth_username is not set
62
+ # You can force private without authentication for longer max_age by
63
+ # setting basic_auth_username but not basic_auth_password
64
+ config.max_age = 1
64
65
 
65
- # Protect health endpoints with basic auth
66
- # These default to nil and the endpoint is not protected
67
- # config.basic_auth_username = 'my_username'
68
- # config.basic_auth_password = 'my_password'
66
+ # Protect health endpoints with basic auth
67
+ # These default to nil and the endpoint is not protected
68
+ # config.basic_auth_username = 'my_username'
69
+ # config.basic_auth_password = 'my_password'
69
70
 
70
- # Whitelist requesting IPs by a list of IP and/or CIDR ranges, either IPv4 or IPv6 (uses IPAddr.include? method to check)
71
- # Defaults to blank which allows any IP
72
- # config.origin_ip_whitelist = %w(123.123.123.123 10.11.12.0/24 2400:cb00::/32)
71
+ # Whitelist requesting IPs by a list of IP and/or CIDR ranges, either IPv4 or IPv6 (uses IPAddr.include? method to check)
72
+ # Defaults to blank which allows any IP
73
+ # config.origin_ip_whitelist = %w(123.123.123.123 10.11.12.0/24 2400:cb00::/32)
73
74
 
74
- # Use ActionDispatch::Request's remote_ip method when behind a proxy to pick up the real remote IP for origin_ip_whitelist check
75
- # Otherwise uses Rack::Request's ip method (the default, and always used by Middleware), which is more susceptible to spoofing
76
- # See https://stackoverflow.com/questions/10997005/whats-the-difference-between-request-remote-ip-and-request-ip-in-rails
77
- config.accept_proxied_requests = false
75
+ # Use ActionDispatch::Request's remote_ip method when behind a proxy to pick up the real remote IP for origin_ip_whitelist check
76
+ # Otherwise uses Rack::Request's ip method (the default, and always used by Middleware), which is more susceptible to spoofing
77
+ # See https://stackoverflow.com/questions/10997005/whats-the-difference-between-request-remote-ip-and-request-ip-in-rails
78
+ config.accept_proxied_requests = false
78
79
 
79
- # http status code used when the ip is not allowed for the request
80
- config.http_status_for_ip_whitelist_error = 403
80
+ # http status code used when the ip is not allowed for the request
81
+ config.http_status_for_ip_whitelist_error = 403
81
82
 
82
- # rabbitmq
83
- # config.rabbitmq_config = {}
83
+ # rabbitmq
84
+ # config.rabbitmq_config = {}
84
85
 
85
- # When redis url/password is non-standard
86
- config.redis_url = ENV.fetch('REDIS_URL', 'redis://redis:6379')
87
- # Only included if set, as url can optionally include passwords as well
88
- # config.redis_password = 'redis_password' # default ENV['REDIS_PASSWORD']
86
+ # When redis url/password is non-standard
87
+ config.redis_url = ENV.fetch('REDIS_URL', 'redis://redis:6379')
88
+ # Only included if set, as url can optionally include passwords as well
89
+ # config.redis_password = 'redis_password' # default ENV['REDIS_PASSWORD']
89
90
 
90
- # Failure Hooks to do something more ...
91
- # checks lists the checks requested
92
- config.on_failure do |checks, msg|
93
- # log msg somewhere
94
- end
91
+ # Failure Hooks to do something more ...
92
+ # checks lists the checks requested
93
+ config.on_failure do |checks, msg|
94
+ # log msg somewhere
95
+ end
95
96
 
96
- config.on_success do |checks|
97
- # flag that everything is well
98
- end
97
+ config.on_success do |checks|
98
+ # flag that everything is well
99
+ end
99
100
 
101
+ end
100
102
  end
@@ -4,9 +4,12 @@ require 'rails/generators'
4
4
 
5
5
  class Modulorails::ModuloprojectGenerator < Modulorails::Generators::Base
6
6
 
7
+ VERSION = 1
8
+
7
9
  desc 'This generator creates templates for Moduloproject'
8
10
 
9
11
  def create_config
12
+ remove_old_keepfile(".modulorails-#{generator_name}")
10
13
  template 'config/environments/production.rb'
11
14
  copy_file('config/environments/production.rb', 'config/environments/staging.rb')
12
15
  update_application_rb
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'rails/generators'
4
+ require 'yaml'
4
5
 
5
6
  module Modulorails
6
7
 
@@ -31,38 +32,47 @@ module Modulorails
31
32
  def version
32
33
  self.class.const_get('VERSION')
33
34
  rescue NameError
34
- 1
35
+ false
35
36
  end
36
37
 
37
38
  def generator_name
38
- self.class.name.split('::').last.gsub('Generator', '').parameterize
39
+ @generator_name ||= self.class.generator_name
39
40
  end
40
41
 
41
42
  def keep_file_name
42
- ".modulorails-#{generator_name}"
43
+ '.modulorails.yml'
43
44
  end
44
45
 
45
- def keep_file_present?
46
+ def keep_file_version
47
+ return @keep_file_version if @keep_file_version
48
+
46
49
  pathname = Rails.root.join(keep_file_name)
50
+ keep_file_exist = pathname.exist?
51
+ @keep_file_version = if keep_file_exist
52
+ YAML.load_file(pathname).dig(generator_name, 'version').to_i
53
+ else
54
+ 0
55
+ end
56
+ end
47
57
 
48
- res = pathname.exist?
49
- return res if version < 2
58
+ def keep_file_present?
59
+ v = version
60
+ return false unless v
50
61
 
51
- res && pathname.readlines(keep_file_name).first
52
- .match(/version: (\d+)/i)&.send(:[], 1).to_i >= version
62
+ Rails.root.join(keep_file_name).exist? && keep_file_version >= v
53
63
  end
54
64
 
55
65
  def create_keep_file
56
- file = keep_file_name
66
+ v = version
67
+ return unless v
57
68
 
58
- remove_file(file)
59
-
60
- content = <<~TEXT
61
- Version: #{version}
69
+ file = keep_file_name
70
+ config = File.exist?(file) ? YAML.load_file(file) : {}
71
+ config[generator_name] = {
72
+ 'version' => v
73
+ }
62
74
 
63
- If you want to reset your configuration, you can run `rails g modulorails:#{generator_name} --force`.
64
- TEXT
65
- create_file(file, content)
75
+ create_file(file, config.to_yaml)
66
76
 
67
77
  say "Add #{file} to git"
68
78
  git add: file
@@ -72,6 +82,36 @@ module Modulorails
72
82
  raise NotImplementedError
73
83
  end
74
84
 
85
+ def create_new_file(old_file, new_file, executable: true)
86
+ if File.exist?(old_file)
87
+ copy_original_file old_file, new_file
88
+ remove_file old_file
89
+ else
90
+ template old_file, new_file
91
+ end
92
+ chmod new_file, 0o755 if executable
93
+ end
94
+
95
+ def copy_original_file(source, *args, &block)
96
+ config = args.last.is_a?(Hash) ? args.pop : {}
97
+ destination = args.first || source
98
+ source = File.expand_path(source, destination_root)
99
+
100
+ create_file destination, nil, config do
101
+ content = File.binread(source)
102
+ content = yield(content) if block
103
+ content
104
+ end
105
+ return unless config[:mode] == :preserve
106
+
107
+ mode = File.stat(source).mode
108
+ chmod(destination, mode, config)
109
+ end
110
+
111
+ def remove_old_keepfile(filename)
112
+ FileUtils.rm_f(filename)
113
+ end
114
+
75
115
  end
76
116
 
77
117
  end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'modulorails/generators/base'
4
+
5
+ module Modulorails
6
+
7
+ module Generators
8
+
9
+ class DockerBase < Modulorails::Generators::Base
10
+
11
+ def self.default_generator_root
12
+ File.expand_path("modulorails/docker/#{generator_name}", base_root)
13
+ end
14
+
15
+ end
16
+
17
+ end
18
+
19
+ end
@@ -1,6 +1,6 @@
1
1
  module Modulorails
2
2
 
3
- VERSION = '1.5.1'.freeze
3
+ VERSION = '1.5.2.pre.1'.freeze
4
4
 
5
5
  # Useful to compare the current Ruby version
6
6
  COMPARABLE_RUBY_VERSION = Gem::Version.new(RUBY_VERSION)
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.5.1
4
+ version: 1.5.2.pre.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: 2024-10-23 00:00:00.000000000 Z
11
+ date: 2024-11-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler-audit
@@ -171,17 +171,21 @@ files:
171
171
  - gemfiles/rails_61.gemfile
172
172
  - gemfiles/rails_70.gemfile
173
173
  - lib/generators/modulorails/bundleraudit/bundleraudit_generator.rb
174
+ - lib/generators/modulorails/docker/compose/compose_generator.rb
175
+ - lib/generators/modulorails/docker/compose/templates/docker-compose.yml.tt
176
+ - lib/generators/modulorails/docker/config/config_generator.rb
177
+ - lib/generators/modulorails/docker/config/templates/config/cable.yml.tt
178
+ - lib/generators/modulorails/docker/config/templates/config/database.yml.tt
179
+ - lib/generators/modulorails/docker/config/templates/config/initializers/0_redis.rb
180
+ - lib/generators/modulorails/docker/config/templates/config/puma.rb
174
181
  - lib/generators/modulorails/docker/docker_generator.rb
175
- - lib/generators/modulorails/docker/templates/config/cable.yml.tt
176
- - lib/generators/modulorails/docker/templates/config/database.yml.tt
177
- - lib/generators/modulorails/docker/templates/config/initializers/0_redis.rb
178
- - lib/generators/modulorails/docker/templates/config/puma.rb
179
- - lib/generators/modulorails/docker/templates/docker-compose.yml.tt
180
- - lib/generators/modulorails/docker/templates/dockerfiles/modulotech/Dockerfile.prod.tt
181
- - lib/generators/modulorails/docker/templates/dockerfiles/modulotech/Dockerfile.tt
182
- - lib/generators/modulorails/docker/templates/dockerfiles/rails/Dockerfile.prod.tt
183
- - lib/generators/modulorails/docker/templates/entrypoints/docker-entrypoint.sh.tt
184
- - lib/generators/modulorails/docker/templates/entrypoints/webpack-entrypoint.sh.tt
182
+ - lib/generators/modulorails/docker/dockerfile/dockerfile_generator.rb
183
+ - lib/generators/modulorails/docker/dockerfile/templates/dockerfiles/modulotech/Dockerfile.prod.tt
184
+ - lib/generators/modulorails/docker/dockerfile/templates/dockerfiles/modulotech/Dockerfile.tt
185
+ - lib/generators/modulorails/docker/dockerfile/templates/dockerfiles/rails/Dockerfile.prod.tt
186
+ - lib/generators/modulorails/docker/entrypoint/entrypoint_generator.rb
187
+ - lib/generators/modulorails/docker/entrypoint/templates/entrypoints/docker-entrypoint.sh.tt
188
+ - lib/generators/modulorails/docker/entrypoint/templates/entrypoints/webpack-entrypoint.sh.tt
185
189
  - lib/generators/modulorails/githooks/githooks_generator.rb
186
190
  - lib/generators/modulorails/githooks/templates/dockeruby.rb
187
191
  - lib/generators/modulorails/githooks/templates/post-rewrite.sh
@@ -216,6 +220,7 @@ files:
216
220
  - lib/modulorails/errors/invalid_format_error.rb
217
221
  - lib/modulorails/errors/invalid_value_error.rb
218
222
  - lib/modulorails/generators/base.rb
223
+ - lib/modulorails/generators/docker_base.rb
219
224
  - lib/modulorails/railtie.rb
220
225
  - lib/modulorails/services/base_service.rb
221
226
  - lib/modulorails/services/logs_for_method_service.rb