modulorails 1.0.2 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +216 -12
  3. data/Appraisals +6 -6
  4. data/CHANGELOG.md +18 -0
  5. data/app/helpers/modulorails/application_helper.rb +4 -2
  6. data/gemfiles/rails_52.gemfile +5 -5
  7. data/gemfiles/rails_60.gemfile +5 -5
  8. data/gemfiles/rails_61.gemfile +5 -5
  9. data/gemfiles/rails_70.gemfile +5 -5
  10. data/lib/generators/modulorails/bundleraudit/bundleraudit_generator.rb +26 -0
  11. data/lib/generators/modulorails/docker/docker_generator.rb +10 -1
  12. data/lib/generators/modulorails/docker/templates/Dockerfile.prod.tt +6 -1
  13. data/lib/generators/modulorails/docker/templates/Dockerfile.tt +3 -0
  14. data/lib/generators/modulorails/docker/templates/config/database.yml.tt +1 -1
  15. data/lib/generators/modulorails/docker/templates/docker-compose.yml.tt +6 -1
  16. data/lib/generators/modulorails/docker/templates/entrypoints/docker-entrypoint.sh.tt +2 -2
  17. data/lib/generators/modulorails/gitlabci/gitlabci_generator.rb +4 -2
  18. data/lib/generators/modulorails/gitlabci/templates/.gitlab-ci.yml.tt +7 -0
  19. data/lib/generators/modulorails/healthcheck/health_check_generator.rb +8 -5
  20. data/lib/generators/modulorails/rubocop/rubocop_generator.rb +8 -6
  21. data/lib/generators/modulorails/rubocop/templates/rubocop.yml.tt +252 -3
  22. data/lib/generators/modulorails/self_update/self_update_generator.rb +6 -3
  23. data/lib/generators/modulorails/service/service_generator.rb +3 -1
  24. data/lib/modulorails/configuration.rb +4 -0
  25. data/lib/modulorails/data.rb +113 -62
  26. data/lib/modulorails/error_data.rb +2 -0
  27. data/lib/modulorails/errors/invalid_format_error.rb +2 -0
  28. data/lib/modulorails/errors/invalid_value_error.rb +2 -0
  29. data/lib/modulorails/railtie.rb +8 -1
  30. data/lib/modulorails/services/base_service.rb +17 -15
  31. data/lib/modulorails/services/logs_for_method_service.rb +1 -0
  32. data/lib/modulorails/success_data.rb +2 -0
  33. data/lib/modulorails/validators/database_configuration.rb +19 -9
  34. data/lib/modulorails/version.rb +3 -1
  35. data/lib/modulorails.rb +48 -33
  36. data/modulorails.gemspec +9 -7
  37. metadata +46 -32
  38. data/lib/generators/modulorails/gitlabci/templates/config/database-ci.yml.tt +0 -8
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9b121fa34b63e6fbbfdf692179220af29060c9b0efc74f1979add163f88fb4b1
4
- data.tar.gz: d88cf22d0ab3638b2c3e9816efbbcfc7560ef182e049a553901cc46d9c00a076
3
+ metadata.gz: 74b7d68847f4e32d43a53990e8e400702a1c667334ad7c862e2e9f6d4197c31b
4
+ data.tar.gz: 4aedbb6cc5e066b49f710d43a721f8b3a5a4e6869c98979815f8564b1a34fa5d
5
5
  SHA512:
6
- metadata.gz: 9a343a8f832ef6c6e3461140c1d4bcca427610424a0dfb81d582503b44b1a37b955c5a6c614166df18870bde41372dabe6658b3d7a57971b8548ed8ba02b2986
7
- data.tar.gz: 132aebb2697f088e6a528647b24ef577291eac1796b5d72ea77b3eebd4ac20d2ea32166ece2cf2f0cafb9a483948a024562d8a4f2ad00af055307f2021855021
6
+ metadata.gz: b079774bb4f3e9cfb2eb18bd31745f641d68712426498a859ac6bb8033b1ab274f1fbb708ff9d8519484d39b2dd28676845ed2809b1d04e622bf849a696bcfe8
7
+ data.tar.gz: d29668cb45b4078b5d7b780d25281cd700cdb96f1d24e6679af5e6aa8871ae23ce1cc71b613ad1b8522c85b23ddd3c60fad766d62f61916bcbb0f0363e1b4fce
data/.rubocop.yml CHANGED
@@ -12,27 +12,30 @@
12
12
  # Enabling Rails-specific cops.
13
13
  require: rubocop-rails
14
14
 
15
+ inherit_mode:
16
+ merge:
17
+ - Exclude
18
+ - Include
19
+
15
20
  AllCops:
16
- # Disable all cops by default to ease the migration. This will probably be removed one day.
17
- DisabledByDefault: true
18
21
  # No suggestions since the gem is the sole truth for rubocop configuration.
19
22
  SuggestExtensions: false
20
23
 
24
+ # Enable new cops by default
25
+ NewCops: enable
26
+
21
27
  # Excluding most directories with generated files and directories with configuration files.
22
28
  Exclude:
23
29
  - 'vendor/**/*'
24
30
  - 'db/**/*'
25
31
  - 'tmp/**/*'
26
- - 'bin/**/*'
27
- - 'builds/**/*'
28
- - 'Gemfile'
29
- - 'config/environments/*'
30
- - 'config/puma.rb'
31
- - 'config/spring.rb'
32
- - 'test/application_system_test_case.rb'
33
- - 'test/test_helper.rb'
34
- - 'config/initializers/*.rb'
35
- - 'spec/spec_helper.rb'
32
+ - 'bin'
33
+ - '**/Gemfile'
34
+ - '**/Guardfile'
35
+ - '**/Capfile'
36
+ - '**/Rakefile'
37
+ - 'config/**/*'
38
+ - 'test/**/*'
36
39
  - 'node_modules/**/*'
37
40
  - 'spec/**/*'
38
41
 
@@ -60,3 +63,204 @@ Style/QuotedSymbols:
60
63
  Lint/SymbolConversion:
61
64
  Enabled: true
62
65
  EnforcedStyle: strict
66
+
67
+ # Useless cop. It checks for unnecessary safe navigations.
68
+ # Example:
69
+ # obj&.a && obj.b
70
+ # Triggers rubocop error: it requires to add safe navigation for "obj.b" call => "obj&.b".
71
+ # but it is not necessary. obj&.a will return nil if obj is nil, and it will stop
72
+ # execution of the operation because `&&` right part executes only when left part is truthy.
73
+ Lint/SafeNavigationConsistency:
74
+ Enabled: false
75
+
76
+ # Checks for places where keyword arguments can be used instead of boolean arguments when defining methods.
77
+ # Disabled because moving from default arguments to keywords is not that easy.
78
+ Style/OptionalBooleanParameter:
79
+ Enabled: false
80
+
81
+ # Checks for use of the lambda.(args) syntax.
82
+ # Disabled while the Ruby team has not voted on this.
83
+ Style/LambdaCall:
84
+ Enabled: false
85
+ EnforcedStyle: braces
86
+
87
+ # Checks for presence or absence of braces around hash literal as a last array item depending on configuration.
88
+ # Disabled because it would break a lot of permitted_params definitions
89
+ Style/HashAsLastArrayItem:
90
+ Enabled: false
91
+
92
+ # Checks for grouping of accessors in class and module bodies.
93
+ # Useless.
94
+ Style/AccessorGrouping:
95
+ Enabled: false
96
+
97
+ # Makes our lives happier: we don't need to disable it in each case/when method
98
+ # with more than 5 "when"s.
99
+ Metrics/CyclomaticComplexity:
100
+ Max: 10
101
+
102
+ # Commonly used screens these days easily fit more than 80 characters.
103
+ Layout/LineLength:
104
+ Max: 100
105
+
106
+ # Too short methods lead to extraction of single-use methods, which can make
107
+ # the code easier to read (by naming things), but can also clutter the class
108
+ Metrics/MethodLength:
109
+ Max: 20
110
+
111
+ # The guiding principle of classes is SRP, SRP can't be accurately measured by LoC
112
+ Metrics/ClassLength:
113
+ Max: 1500
114
+
115
+ # No space makes the method definition shorter and differentiates
116
+ # from a regular assignment.
117
+ Layout/SpaceAroundEqualsInParameterDefault:
118
+ EnforcedStyle: no_space
119
+
120
+ # We do not need to support Ruby 1.9, so this is good to use.
121
+ Style/SymbolArray:
122
+ Enabled: true
123
+
124
+ # Most readable form.
125
+ Layout/HashAlignment:
126
+ EnforcedHashRocketStyle: table
127
+ EnforcedColonStyle: table
128
+
129
+ # Mixing the styles looks just silly.
130
+ Style/HashSyntax:
131
+ EnforcedStyle: ruby19_no_mixed_keys
132
+
133
+ # has_key? and has_value? are far more readable than key? and value?
134
+ Style/PreferredHashMethods:
135
+ Enabled: false
136
+
137
+ # String#% is by far the least verbose and only object oriented variant.
138
+ Style/FormatString:
139
+ EnforcedStyle: percent
140
+
141
+ # Annotated or template are too verbose and rarely needed.
142
+ Style/FormatStringToken:
143
+ EnforcedStyle: unannotated
144
+
145
+ Style/CollectionMethods:
146
+ Enabled: true
147
+ PreferredMethods:
148
+ # inject seems more common in the community.
149
+ reduce: "inject"
150
+
151
+ # Either allow this style or don't. Marking it as safe with parenthesis
152
+ # is silly. Let's try to live without them for now.
153
+ Style/ParenthesesAroundCondition:
154
+ AllowSafeAssignment: false
155
+ Lint/AssignmentInCondition:
156
+ AllowSafeAssignment: false
157
+
158
+ # A specialized exception class will take one or more arguments and construct the message from it.
159
+ # So both variants make sense.
160
+ Style/RaiseArgs:
161
+ Enabled: false
162
+
163
+ # Indenting the chained dots beneath each other is not supported by this cop,
164
+ # see https://github.com/bbatsov/rubocop/issues/1633
165
+ Layout/MultilineOperationIndentation:
166
+ Enabled: false
167
+
168
+ # Fail is an alias of raise. Avoid aliases, it's more cognitive load for no gain.
169
+ # The argument that fail should be used to abort the program is wrong too,
170
+ # there's Kernel#abort for that.
171
+ Style/SignalException:
172
+ EnforcedStyle: only_raise
173
+
174
+ # Suppressing exceptions can be perfectly fine, and be it to avoid to
175
+ # explicitly type nil into the rescue since that's what you want to return,
176
+ # or suppressing LoadError for optional dependencies
177
+ Lint/SuppressedException:
178
+ Enabled: false
179
+
180
+ # { ... } for multi-line blocks is okay, follow Weirichs rule instead:
181
+ # https://web.archive.org/web/20140221124509/http://onestepback.org/index.cgi/Tech/Ruby/BraceVsDoEnd.rdoc
182
+ Style/BlockDelimiters:
183
+ Enabled: false
184
+
185
+ # do / end blocks should be used for side effects,
186
+ # methods that run a block for side effects and have
187
+ # a useful return value are rare, assign the return
188
+ # value to a local variable for those cases.
189
+ Style/MethodCalledOnDoEndBlock:
190
+ Enabled: true
191
+
192
+ # Enforcing the names of variables? To single letter ones? Just no.
193
+ Style/SingleLineBlockParams:
194
+ Enabled: false
195
+
196
+ # Shadowing outer local variables with block parameters is often useful
197
+ # to not reinvent a new name for the same thing, it highlights the relation
198
+ # between the outer variable and the parameter. The cases where it's actually
199
+ # confusing are rare, and usually bad for other reasons already, for example
200
+ # because the method is too long.
201
+ Lint/ShadowingOuterLocalVariable:
202
+ Enabled: false
203
+
204
+ # Check with yard instead.
205
+ Style/Documentation:
206
+ Enabled: false
207
+
208
+ # This is just silly. Calling the argument `other` in all cases makes no sense.
209
+ Naming/BinaryOperatorParameterName:
210
+ Enabled: false
211
+
212
+ # Disable frozen string
213
+ Style/FrozenStringLiteralComment:
214
+ Enabled: false
215
+
216
+ # Disable No ASCII char in comments
217
+ Style/AsciiComments:
218
+ Enabled: false
219
+
220
+ # Disable ordered Gems By ascii
221
+ Bundler/OrderedGems:
222
+ Enabled: false
223
+
224
+ # Change ABC max value
225
+ Metrics/AbcSize:
226
+ Max: 35
227
+
228
+ # Disable empty method in one line
229
+ Style/EmptyMethod:
230
+ EnforcedStyle: expanded
231
+
232
+ # Disable max height block
233
+ Metrics/BlockLength:
234
+ Enabled: true
235
+ Exclude:
236
+ - 'app/admin/**/*'
237
+
238
+ # Checks if empty lines around the bodies of classes match the configuration.
239
+ Layout/EmptyLinesAroundClassBody:
240
+ EnforcedStyle: empty_lines
241
+ # Checks if empty lines around the bodies of modules match the configuration.
242
+ Layout/EmptyLinesAroundModuleBody:
243
+ EnforcedStyle: empty_lines
244
+
245
+ # Enforces the consistent usage of %-literal delimiters.
246
+ Style/PercentLiteralDelimiters:
247
+ PreferredDelimiters:
248
+ default: '()'
249
+ '%i': '[]'
250
+ '%I': '[]'
251
+ '%r': '{}'
252
+ '%w': '[]'
253
+ '%W': '[]'
254
+
255
+ # Unnecessary cop. In what universe "A || B && C" or "A && B || C && D" is ambiguous? looks
256
+ # like a cop for those who can't in boolean.
257
+ Lint/AmbiguousOperatorPrecedence:
258
+ Enabled: false
259
+
260
+ # Checks for simple usages of parallel assignment.
261
+ Style/ParallelAssignment:
262
+ Enabled: false
263
+
264
+ # Checks the style of children definitions at classes and modules.
265
+ Style/ClassAndModuleChildren:
266
+ Enabled: false
data/Appraisals CHANGED
@@ -1,18 +1,18 @@
1
- appraise "rails-52" do
1
+ appraise 'rails-52' do
2
2
  gem 'rails', '~> 5.2', '>= 5.2.6'
3
3
  end
4
4
 
5
- appraise "rails-60" do
5
+ appraise 'rails-60' do
6
6
  gem 'rails', '~> 6.0', '>= 6.0.4.4'
7
7
  end
8
8
 
9
- appraise "rails-61" do
9
+ appraise 'rails-61' do
10
10
  gem 'rails', '~> 6.1', '>= 6.1.4.4'
11
11
  end
12
12
 
13
13
  # Rails 7 requires at least Ruby 2.7
14
14
  if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.7')
15
- appraise "rails-70" do
16
- gem 'rails', '~> 7.0'
17
- end
15
+ appraise 'rails-70' do
16
+ gem 'rails', '~> 7.0'
17
+ end
18
18
  end
data/CHANGELOG.md CHANGED
@@ -2,6 +2,24 @@
2
2
 
3
3
  This file is used to list changes made in each version of the gem.
4
4
 
5
+ # 1.2.0
6
+
7
+ The 'audit' release.
8
+
9
+ - Add bundler-audit in CI.
10
+ - Make the rubocop configuration work during CI.
11
+ - Fix generation of .gitlab-ci.yml for PG databases.
12
+ - Remove deprecated `--deployment` flag from Dockerfile.prod
13
+
14
+ # 1.1.0
15
+
16
+ The 'new project' release.
17
+
18
+ - Add lot of Rubocop rules.
19
+ - Fix rubocop offenses for the gem.
20
+ - Ensure Modulorails will work with Moduloproject.
21
+ - Add `webpacker`, `importmap` and `jsbundling` versions to `Modulorails::Data`.
22
+
5
23
  # 1.0.2
6
24
 
7
25
  Fix error in with_transaction: `uninitialized constant Modulorails::BaseService::ErrorData`.
@@ -1,8 +1,10 @@
1
1
  # @author Matthieu CIAPPARA <ciappa_m@modulotech.fr>
2
2
  module Modulorails::ApplicationHelper
3
+
3
4
  def powered_by
4
- link_to('https://www.modulotech.fr/', target: '_blank', class: 'modulolink') do
5
- raw("Powered by modulo<span>Tech</span>")
5
+ link_to('https://www.modulotech.fr/', target: '_blank', class: 'modulolink', rel: 'noopener') do
6
+ safe_join(['Powered by modulo', content_tag(:span, 'Tech')])
6
7
  end
7
8
  end
9
+
8
10
  end
@@ -1,9 +1,9 @@
1
1
  # This file was generated by Appraisal
2
2
 
3
- source "https://rubygems.org"
3
+ source 'https://rubygems.org'
4
4
 
5
- gem "rake", "~> 12.0"
6
- gem "rspec", "~> 3.0"
7
- gem "rails", "~> 5.2", ">= 5.2.6"
5
+ gem 'rake', '~> 12.0'
6
+ gem 'rspec', '~> 3.0'
7
+ gem 'rails', '~> 5.2', '>= 5.2.6'
8
8
 
9
- gemspec path: "../"
9
+ gemspec path: '../'
@@ -1,9 +1,9 @@
1
1
  # This file was generated by Appraisal
2
2
 
3
- source "https://rubygems.org"
3
+ source 'https://rubygems.org'
4
4
 
5
- gem "rake", "~> 12.0"
6
- gem "rspec", "~> 3.0"
7
- gem "rails", "~> 6.0", ">= 6.0.4.4"
5
+ gem 'rake', '~> 12.0'
6
+ gem 'rspec', '~> 3.0'
7
+ gem 'rails', '~> 6.0', '>= 6.0.4.4'
8
8
 
9
- gemspec path: "../"
9
+ gemspec path: '../'
@@ -1,9 +1,9 @@
1
1
  # This file was generated by Appraisal
2
2
 
3
- source "https://rubygems.org"
3
+ source 'https://rubygems.org'
4
4
 
5
- gem "rake", "~> 12.0"
6
- gem "rspec", "~> 3.0"
7
- gem "rails", "~> 6.1", ">= 6.1.4.4"
5
+ gem 'rake', '~> 12.0'
6
+ gem 'rspec', '~> 3.0'
7
+ gem 'rails', '~> 6.1', '>= 6.1.4.4'
8
8
 
9
- gemspec path: "../"
9
+ gemspec path: '../'
@@ -1,9 +1,9 @@
1
1
  # This file was generated by Appraisal
2
2
 
3
- source "https://rubygems.org"
3
+ source 'https://rubygems.org'
4
4
 
5
- gem "rake", "~> 12.0"
6
- gem "rspec", "~> 3.0"
7
- gem "rails", "~> 7.0"
5
+ gem 'rake', '~> 12.0'
6
+ gem 'rspec', '~> 3.0'
7
+ gem 'rails', '~> 7.0'
8
8
 
9
- gemspec path: "../"
9
+ gemspec path: '../'
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails/generators'
4
+
5
+ class Modulorails::BundlerauditGenerator < Rails::Generators::Base
6
+
7
+ source_root File.expand_path('templates', __dir__)
8
+ desc 'This generator creates a configuration for Bundler-Audit'
9
+
10
+ def create_config_files
11
+ gitlab_config_path = Rails.root.join('.gitlab-ci.yml')
12
+
13
+ return if File.read(gitlab_config_path).match?(/\s+extends:\s+.bundleraudit\s*$/)
14
+
15
+ append_file gitlab_config_path do
16
+ <<~YAML
17
+ # Scan Gemfile.lock for Common Vulnerabilities and Exposures
18
+ # https://en.wikipedia.org/wiki/Common_Vulnerabilities_and_Exposures
19
+ # https://www.cve.org/
20
+ bundleraudit:
21
+ extends: .bundleraudit
22
+ YAML
23
+ end
24
+ end
25
+
26
+ end
@@ -3,6 +3,7 @@
3
3
  require 'rails/generators'
4
4
 
5
5
  class Modulorails::DockerGenerator < Rails::Generators::Base
6
+
6
7
  source_root File.expand_path('templates', __dir__)
7
8
  desc 'This generator creates Dockerfiles for an app'
8
9
 
@@ -12,8 +13,16 @@ class Modulorails::DockerGenerator < Rails::Generators::Base
12
13
  template 'docker-compose.yml'
13
14
  template 'docker-compose.prod.yml'
14
15
  template 'entrypoints/docker-entrypoint.sh'
16
+ chmod 'entrypoints/docker-entrypoint.sh', 0755
15
17
  template 'config/database.yml'
18
+
19
+ # Useless unless project is using Webpacker
20
+ if Modulorails.data.webpacker_version.present?
21
+ template 'entrypoints/webpack-entrypoint.sh'
22
+ chmod 'entrypoints/webpack-entrypoint.sh', 0755
23
+ end
16
24
  rescue StandardError => e
17
- $stderr.puts("[Modulorails] Error: cannot generate Docker configuration: #{e.message}")
25
+ warn("[Modulorails] Error: cannot generate Docker configuration: #{e.message}")
18
26
  end
27
+
19
28
  end
@@ -10,6 +10,7 @@ RUN apk add --update --no-cache \
10
10
  tzdata \
11
11
  yarn \
12
12
  shared-mime-info \
13
+ gcompat \
13
14
  <%- adapter = Modulorails.data.adapter -%>
14
15
  <%- if adapter =~ /mysql/ -%>
15
16
  mysql-dev
@@ -19,7 +20,8 @@ RUN apk add --update --no-cache \
19
20
  RUN gem install bundler -v <%= Modulorails.data.bundler_version %>
20
21
 
21
22
  COPY Gemfile Gemfile.lock ./
22
- RUN bundle check || bundle install --deployment --jobs=2 \
23
+ RUN bundle config set --local deployment 'true'
24
+ RUN bundle check || bundle install --jobs=2 \
23
25
  && rm -rf vendor/bundle/ruby/*/cache/*
24
26
 
25
27
  COPY package.json yarn.lock ./
@@ -31,6 +33,8 @@ RUN bundle exec rake assets:precompile
31
33
  # FINAL IMAGE
32
34
  FROM ruby:<%= Modulorails.data.ruby_version %>-alpine
33
35
 
36
+ ENV RAILS_ENV=development
37
+ ENV EDITOR=vim
34
38
  WORKDIR /app
35
39
 
36
40
  RUN apk add --update --no-cache \
@@ -39,6 +43,7 @@ RUN apk add --update --no-cache \
39
43
  nodejs \
40
44
  tzdata \
41
45
  shared-mime-info \
46
+ vim \
42
47
  <%- adapter = Modulorails.data.adapter -%>
43
48
  <%- if adapter =~ /mysql/ -%>
44
49
  mysql-dev \
@@ -1,6 +1,7 @@
1
1
  FROM ruby:<%= Modulorails.data.ruby_version %>-alpine
2
2
 
3
3
  ENV RAILS_ENV=development
4
+ ENV EDITOR=vim
4
5
  WORKDIR /app
5
6
 
6
7
  RUN apk add --update --no-cache \
@@ -8,6 +9,8 @@ RUN apk add --update --no-cache \
8
9
  nodejs \
9
10
  yarn \
10
11
  tzdata \
12
+ gcompat \
13
+ vim \
11
14
  <%- adapter = Modulorails.data.adapter -%>
12
15
  <%- if adapter =~ /mysql/ -%>
13
16
  mysql-dev
@@ -13,7 +13,7 @@ development: &default
13
13
  port: <%%= ENV.fetch('<%= upper_image_name %>_DATABASE_PORT', 3306) %>
14
14
  <%- else -%>
15
15
  development: &default
16
- adapter: pg
16
+ adapter: postgresql
17
17
  database: <%%= ENV.fetch('<%= upper_image_name %>_DATABASE_NAME', '<%= image_name %>') %>
18
18
  username: <%%= ENV.fetch('<%= upper_image_name %>_DATABASE_USERNAME', 'postgres') %>
19
19
  password: <%%= ENV.fetch('<%= upper_image_name %>_DATABASE_PASSWORD', 'postgres') %>
@@ -20,6 +20,8 @@ services:
20
20
  <%= image_name.upcase %>_DATABASE_HOST: database
21
21
  <%= image_name.upcase %>_DATABASE_NAME: <%= image_name %>
22
22
  entrypoint: ./entrypoints/docker-entrypoint.sh
23
+ stdin_open: true
24
+ tty: true
23
25
 
24
26
  <%- adapter = Modulorails.data.adapter -%>
25
27
  <%- if adapter =~ /mysql/ -%>
@@ -52,7 +54,9 @@ services:
52
54
  ports:
53
55
  - 1080:80
54
56
 
55
- webpack:
57
+ <%- webpack_container_needed = Modulorails.data.webpacker_version.present? -%>
58
+ <%- if webpack_container_needed -%>
59
+ webpack:
56
60
  image: modulotechgroup/<%= image_name %>:dev
57
61
  build:
58
62
  context: .
@@ -66,6 +70,7 @@ services:
66
70
  NODE_ENV: development
67
71
  RAILS_ENV: development
68
72
  WEBPACKER_DEV_SERVER_HOST: 0.0.0.0
73
+ <%- end-%>
69
74
 
70
75
  volumes:
71
76
  db_data:
@@ -4,8 +4,8 @@
4
4
  set -e
5
5
 
6
6
  # No `node_modules` directory means `yarn install` was never launched.
7
- # It is mandatory to install yarn dependencies.
8
- if [ ! -d node_modules ]
7
+ # It is mandatory to install yarn dependencies IF there is a `package.json` file.
8
+ if [ -f package.json ] && [ ! -d node_modules ]
9
9
  then
10
10
  yarn install
11
11
  fi
@@ -3,6 +3,7 @@
3
3
  require 'rails/generators'
4
4
 
5
5
  class Modulorails::GitlabciGenerator < Rails::Generators::Base
6
+
6
7
  source_root File.expand_path('templates', __dir__)
7
8
  desc 'This generator creates a template for a .gitlab-ci.yml file at root'
8
9
 
@@ -17,7 +18,7 @@ class Modulorails::GitlabciGenerator < Rails::Generators::Base
17
18
  # Create file to avoid this generator on next modulorails launch
18
19
  create_keep_file
19
20
  rescue StandardError => e
20
- $stderr.puts("[Modulorails] Error: cannot generate CI configuration: #{e.message}")
21
+ warn("[Modulorails] Error: cannot generate CI configuration: #{e.message}")
21
22
  end
22
23
 
23
24
  private
@@ -29,6 +30,7 @@ class Modulorails::GitlabciGenerator < Rails::Generators::Base
29
30
  copy_file(file, file)
30
31
 
31
32
  say "Add #{file} to git"
32
- %x(git add #{file})
33
+ `git add #{file}`
33
34
  end
35
+
34
36
  end
@@ -17,9 +17,16 @@ services:
17
17
 
18
18
  variables:
19
19
  IMAGE_NAME: <%= image_name %>
20
+ <%- if adapter =~ /mysql/ -%>
20
21
  MYSQL_DATABASE: <%= image_name %>_test
21
22
  MYSQL_ALLOW_EMPTY_PASSWORD: 'true'
22
23
  <%= image_name.upcase %>_DATABASE_HOST: mysql
24
+ <%- else -%>
25
+ POSTGRES_DB: <%= image_name %>_test
26
+ POSTGRES_USER: postgres
27
+ POSTGRES_PASSWORD: postgres
28
+ <%= image_name.upcase %>_DATABASE_HOST: postgres
29
+ <%- end -%>
23
30
 
24
31
  stages:
25
32
  - test
@@ -3,6 +3,7 @@
3
3
  require 'rails/generators'
4
4
 
5
5
  class Modulorails::HealthCheckGenerator < Rails::Generators::Base
6
+
6
7
  source_root File.expand_path('templates', __dir__)
7
8
  desc 'This generator creates a configuration for the health_check gem'
8
9
 
@@ -12,9 +13,10 @@ class Modulorails::HealthCheckGenerator < Rails::Generators::Base
12
13
 
13
14
  # Add the route
14
15
  unless File.read(Rails.root.join('config/routes.rb')).match?('health_check_routes')
15
- inject_into_file 'config/routes.rb', after: "Rails.application.routes.draw do\n" do <<~'RUBY'
16
- health_check_routes
17
- RUBY
16
+ inject_into_file 'config/routes.rb', after: "Rails.application.routes.draw do\n" do
17
+ <<~'RUBY'
18
+ health_check_routes
19
+ RUBY
18
20
  end
19
21
  end
20
22
 
@@ -24,7 +26,7 @@ class Modulorails::HealthCheckGenerator < Rails::Generators::Base
24
26
  # Create file to avoid this generator on next modulorails launch
25
27
  create_keep_file
26
28
  rescue StandardError => e
27
- $stderr.puts("[Modulorails] Error: cannot generate health_check configuration: #{e.message}")
29
+ warn("[Modulorails] Error: cannot generate health_check configuration: #{e.message}")
28
30
  end
29
31
 
30
32
  private
@@ -36,6 +38,7 @@ class Modulorails::HealthCheckGenerator < Rails::Generators::Base
36
38
  copy_file(file, file)
37
39
 
38
40
  say "Add #{file} to git"
39
- %x(git add #{file})
41
+ `git add #{file}`
40
42
  end
43
+
41
44
  end
@@ -3,6 +3,7 @@
3
3
  require 'rails/generators'
4
4
 
5
5
  class Modulorails::RubocopGenerator < Rails::Generators::Base
6
+
6
7
  source_root File.expand_path('templates', __dir__)
7
8
  desc 'This generator creates a configuration for Rubocop'
8
9
 
@@ -10,15 +11,16 @@ class Modulorails::RubocopGenerator < Rails::Generators::Base
10
11
  rubocop_config_path = Rails.root.join('.rubocop.yml')
11
12
  gitlab_config_path = Rails.root.join('.gitlab-ci.yml')
12
13
 
13
- template "rubocop.yml", rubocop_config_path, force: true
14
+ template 'rubocop.yml', rubocop_config_path, force: true
15
+
16
+ return if File.read(gitlab_config_path).match?(/\s+extends:\s+.lint\s*$/)
14
17
 
15
- unless File.read(gitlab_config_path).match?(/\s+extends:\s+.lint\s*$/)
16
- append_file gitlab_config_path do
17
- <<~YAML
18
+ append_file gitlab_config_path do
19
+ <<~YAML
18
20
  rubocop:
19
21
  extends: .lint
20
- YAML
21
- end
22
+ YAML
22
23
  end
23
24
  end
25
+
24
26
  end