modulorails 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/.dockerignore +14 -0
  3. data/.gitignore +2 -0
  4. data/.travis.yml +23 -4
  5. data/Appraisals +18 -0
  6. data/CHANGELOG.md +12 -0
  7. data/Dockerfile.ruby25 +34 -0
  8. data/Dockerfile.ruby26 +28 -0
  9. data/Dockerfile.ruby27 +25 -0
  10. data/Dockerfile.ruby30 +25 -0
  11. data/Dockerfile.ruby31 +25 -0
  12. data/Gemfile.lock +59 -52
  13. data/README.md +16 -4
  14. data/Rakefile +1 -1
  15. data/docker-compose.yml +37 -0
  16. data/entrypoints/appraisal_test.sh +7 -0
  17. data/gemfiles/rails_52.gemfile +9 -0
  18. data/gemfiles/rails_60.gemfile +9 -0
  19. data/gemfiles/rails_61.gemfile +9 -0
  20. data/gemfiles/rails_70.gemfile +9 -0
  21. data/lib/generators/{docker → modulorails/docker}/docker_generator.rb +1 -1
  22. data/lib/generators/{docker → modulorails/docker}/templates/Dockerfile.prod.tt +14 -9
  23. data/lib/generators/{docker → modulorails/docker}/templates/Dockerfile.tt +5 -7
  24. data/lib/generators/{docker → modulorails/docker}/templates/config/database.yml.tt +11 -0
  25. data/lib/generators/{docker → modulorails/docker}/templates/docker-compose.prod.yml.tt +18 -4
  26. data/lib/generators/modulorails/docker/templates/docker-compose.yml.tt +71 -0
  27. data/lib/generators/{docker → modulorails/docker}/templates/entrypoints/docker-entrypoint.sh.tt +0 -0
  28. data/lib/generators/modulorails/docker/templates/entrypoints/webpack-entrypoint.sh.tt +7 -0
  29. data/lib/generators/{gitlabci → modulorails/gitlabci}/gitlabci_generator.rb +4 -23
  30. data/lib/generators/modulorails/gitlabci/templates/.gitlab-ci.yml.tt +118 -0
  31. data/lib/generators/modulorails/gitlabci/templates/.modulorails-gitlab-ci +6 -0
  32. data/lib/generators/{gitlabci → modulorails/gitlabci}/templates/config/database-ci.yml.tt +0 -0
  33. data/lib/generators/modulorails/healthcheck/health_check_generator.rb +41 -0
  34. data/lib/generators/modulorails/healthcheck/templates/.modulorails-health_check +6 -0
  35. data/lib/generators/modulorails/healthcheck/templates/config/initializers/health_check.rb.tt +100 -0
  36. data/lib/generators/modulorails/self_update/self_update_generator.rb +32 -0
  37. data/lib/modulorails/configuration.rb +8 -2
  38. data/lib/modulorails/data.rb +21 -2
  39. data/lib/modulorails/railtie.rb +19 -4
  40. data/lib/modulorails/validators/database_configuration.rb +1 -1
  41. data/lib/modulorails/version.rb +1 -1
  42. data/lib/modulorails.rb +34 -15
  43. data/modulorails.gemspec +2 -0
  44. metadata +69 -24
  45. data/lib/generators/docker/templates/docker-compose.yml.tt +0 -37
  46. data/lib/generators/gitlabci/templates/.gitlab-ci.yml.tt +0 -79
  47. data/lib/generators/gitlabci/templates/.modulorails-gitlab-ci +0 -3
  48. data/lib/modulorails/updater.rb +0 -46
data/lib/modulorails.rb CHANGED
@@ -2,9 +2,10 @@ require 'modulorails/version'
2
2
  require 'modulorails/configuration'
3
3
  require 'modulorails/data'
4
4
  require 'modulorails/validators/database_configuration'
5
- require 'modulorails/updater'
6
5
  require 'modulorails/railtie' if defined?(Rails::Railtie)
7
- require 'generators/gitlabci/gitlabci_generator'
6
+ require 'generators/modulorails/gitlabci/gitlabci_generator'
7
+ require 'generators/modulorails/healthcheck/health_check_generator'
8
+ require 'generators/modulorails/self_update/self_update_generator'
8
9
  require 'httparty'
9
10
 
10
11
  # Author: Matthieu 'ciappa_m' Ciappara
@@ -77,17 +78,25 @@ module Modulorails
77
78
  # Define the JSON body of the request
78
79
  body = data.to_params.to_json
79
80
 
80
- # Post to the configured endpoint on the Intranet
81
- response = HTTParty.post(configuration.endpoint, headers: headers, body: body)
82
-
83
- # According to the API specification, on a "Bad request" response, the server explicits what
84
- # went wrong with an `errors` field. We do not want to raise since the gem's user is not
85
- # (necessarily) responsible for the error but we still need to display it somewhere to warn
86
- # the user something went wrong.
87
- puts("[Modulorails] Error: #{response['errors'].join(', ')}") if response.code == 400
88
-
89
- # Return the response to allow users to do some more
90
- response
81
+ # Prevent HTTParty to raise error and crash the server in dev
82
+ begin
83
+ # Post to the configured endpoint on the Intranet
84
+ response = HTTParty.post(configuration.endpoint, headers: headers, body: body)
85
+
86
+ # According to the API specification, on a "Bad request" response, the server explicits what
87
+ # went wrong with an `errors` field. We do not want to raise since the gem's user is not
88
+ # (necessarily) responsible for the error but we still need to display it somewhere to warn
89
+ # the user something went wrong.
90
+ puts("[Modulorails] Error: #{response['errors'].join(', ')}") if response.code == 400
91
+
92
+ # Return the response to allow users to do some more
93
+ response
94
+ rescue StandardError => e
95
+ # Still need to notify the user
96
+ puts("[Modulorails] Error: Could not post to #{configuration.endpoint}")
97
+ puts e.message
98
+ nil
99
+ end
91
100
  else
92
101
  raise Error.new('No endpoint or api key')
93
102
  end
@@ -100,7 +109,7 @@ module Modulorails
100
109
  def generate_ci_template
101
110
  return if File.exists?(Rails.root.join('.modulorails-gitlab-ci'))
102
111
 
103
- GitlabciGenerator.new([], {}, {}).invoke_all
112
+ Modulorails::GitlabciGenerator.new([], {}, {}).invoke_all
104
113
  end
105
114
 
106
115
  # @author Matthieu 'ciappa_m' Ciappara
@@ -124,9 +133,19 @@ module Modulorails
124
133
  # Check the last version of Modulorails available on rubygems and update if there was a
125
134
  # publication
126
135
  def self_update
127
- Modulorails::Updater.call unless configuration.no_auto_update
136
+ Modulorails::SelfUpdateGenerator.new([], {}, {}).invoke_all unless configuration.no_auto_update
128
137
  rescue StandardError => e
129
138
  puts("[Modulorails] An error occured: #{e.class} - #{e.message}")
130
139
  end
140
+
141
+ # @author Matthieu 'ciappa_m' Ciappara
142
+ #
143
+ # Generate a health_check configuration unless it was already done.
144
+ # The check is done using a 'keepfile'.
145
+ def generate_healthcheck_template
146
+ return if File.exists?(Rails.root.join('.modulorails-health_check'))
147
+
148
+ Modulorails::HealthCheckGenerator.new([], {}, {}).invoke_all
149
+ end
131
150
  end
132
151
  end
data/modulorails.gemspec CHANGED
@@ -33,6 +33,8 @@ Gem::Specification.new do |spec|
33
33
  spec.add_runtime_dependency 'git', '~> 1.7', '>= 1.7.0'
34
34
  spec.add_runtime_dependency 'httparty'
35
35
  spec.add_runtime_dependency 'i18n'
36
+ spec.add_runtime_dependency 'health_check', '~> 3.1'
36
37
 
37
38
  spec.add_development_dependency 'activerecord', '>= 4.2.0'
39
+ spec.add_development_dependency "appraisal"
38
40
  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: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthieu Ciappara
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-04-20 00:00:00.000000000 Z
11
+ date: 2022-01-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -28,22 +28,22 @@ dependencies:
28
28
  name: git
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: '1.7'
34
31
  - - ">="
35
32
  - !ruby/object:Gem::Version
36
33
  version: 1.7.0
34
+ - - "~>"
35
+ - !ruby/object:Gem::Version
36
+ version: '1.7'
37
37
  type: :runtime
38
38
  prerelease: false
39
39
  version_requirements: !ruby/object:Gem::Requirement
40
40
  requirements:
41
- - - "~>"
42
- - !ruby/object:Gem::Version
43
- version: '1.7'
44
41
  - - ">="
45
42
  - !ruby/object:Gem::Version
46
43
  version: 1.7.0
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '1.7'
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: httparty
49
49
  requirement: !ruby/object:Gem::Requirement
@@ -72,6 +72,20 @@ dependencies:
72
72
  - - ">="
73
73
  - !ruby/object:Gem::Version
74
74
  version: '0'
75
+ - !ruby/object:Gem::Dependency
76
+ name: health_check
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '3.1'
82
+ type: :runtime
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: '3.1'
75
89
  - !ruby/object:Gem::Dependency
76
90
  name: activerecord
77
91
  requirement: !ruby/object:Gem::Requirement
@@ -86,6 +100,20 @@ dependencies:
86
100
  - - ">="
87
101
  - !ruby/object:Gem::Version
88
102
  version: 4.2.0
103
+ - !ruby/object:Gem::Dependency
104
+ name: appraisal
105
+ requirement: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ type: :development
111
+ prerelease: false
112
+ version_requirements: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
89
117
  description: |
90
118
  Modulorails is the common base for the Ruby on Rails project at Modulotech
91
119
  (https://www.modulotech.fr/).
@@ -98,11 +126,18 @@ executables: []
98
126
  extensions: []
99
127
  extra_rdoc_files: []
100
128
  files:
129
+ - ".dockerignore"
101
130
  - ".gitignore"
102
131
  - ".rspec"
103
132
  - ".travis.yml"
133
+ - Appraisals
104
134
  - CHANGELOG.md
105
135
  - CODE_OF_CONDUCT.md
136
+ - Dockerfile.ruby25
137
+ - Dockerfile.ruby26
138
+ - Dockerfile.ruby27
139
+ - Dockerfile.ruby30
140
+ - Dockerfile.ruby31
106
141
  - Gemfile
107
142
  - Gemfile.lock
108
143
  - LICENSE.txt
@@ -111,22 +146,32 @@ files:
111
146
  - bin/console
112
147
  - bin/setup
113
148
  - config/locales/en.yml
114
- - lib/generators/docker/docker_generator.rb
115
- - lib/generators/docker/templates/Dockerfile.prod.tt
116
- - lib/generators/docker/templates/Dockerfile.tt
117
- - lib/generators/docker/templates/config/database.yml.tt
118
- - lib/generators/docker/templates/docker-compose.prod.yml.tt
119
- - lib/generators/docker/templates/docker-compose.yml.tt
120
- - lib/generators/docker/templates/entrypoints/docker-entrypoint.sh.tt
121
- - lib/generators/gitlabci/gitlabci_generator.rb
122
- - lib/generators/gitlabci/templates/.gitlab-ci.yml.tt
123
- - lib/generators/gitlabci/templates/.modulorails-gitlab-ci
124
- - lib/generators/gitlabci/templates/config/database-ci.yml.tt
149
+ - docker-compose.yml
150
+ - entrypoints/appraisal_test.sh
151
+ - gemfiles/rails_52.gemfile
152
+ - gemfiles/rails_60.gemfile
153
+ - gemfiles/rails_61.gemfile
154
+ - gemfiles/rails_70.gemfile
155
+ - lib/generators/modulorails/docker/docker_generator.rb
156
+ - lib/generators/modulorails/docker/templates/Dockerfile.prod.tt
157
+ - lib/generators/modulorails/docker/templates/Dockerfile.tt
158
+ - lib/generators/modulorails/docker/templates/config/database.yml.tt
159
+ - lib/generators/modulorails/docker/templates/docker-compose.prod.yml.tt
160
+ - lib/generators/modulorails/docker/templates/docker-compose.yml.tt
161
+ - lib/generators/modulorails/docker/templates/entrypoints/docker-entrypoint.sh.tt
162
+ - lib/generators/modulorails/docker/templates/entrypoints/webpack-entrypoint.sh.tt
163
+ - lib/generators/modulorails/gitlabci/gitlabci_generator.rb
164
+ - lib/generators/modulorails/gitlabci/templates/.gitlab-ci.yml.tt
165
+ - lib/generators/modulorails/gitlabci/templates/.modulorails-gitlab-ci
166
+ - lib/generators/modulorails/gitlabci/templates/config/database-ci.yml.tt
167
+ - lib/generators/modulorails/healthcheck/health_check_generator.rb
168
+ - lib/generators/modulorails/healthcheck/templates/.modulorails-health_check
169
+ - lib/generators/modulorails/healthcheck/templates/config/initializers/health_check.rb.tt
170
+ - lib/generators/modulorails/self_update/self_update_generator.rb
125
171
  - lib/modulorails.rb
126
172
  - lib/modulorails/configuration.rb
127
173
  - lib/modulorails/data.rb
128
174
  - lib/modulorails/railtie.rb
129
- - lib/modulorails/updater.rb
130
175
  - lib/modulorails/validators/database_configuration.rb
131
176
  - lib/modulorails/version.rb
132
177
  - modulorails.gemspec
@@ -137,7 +182,7 @@ metadata:
137
182
  homepage_uri: https://github.com/moduloTech/modulorails
138
183
  source_code_uri: https://github.com/moduloTech/modulorails
139
184
  changelog_uri: https://github.com/moduloTech/modulorails/blob/master/CHANGELOG.md
140
- post_install_message:
185
+ post_install_message:
141
186
  rdoc_options: []
142
187
  require_paths:
143
188
  - lib
@@ -152,8 +197,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
152
197
  - !ruby/object:Gem::Version
153
198
  version: '0'
154
199
  requirements: []
155
- rubygems_version: 3.1.2
156
- signing_key:
200
+ rubygems_version: 3.0.3
201
+ signing_key:
157
202
  specification_version: 4
158
203
  summary: Common base for Ruby on Rails projects at Modulotech
159
204
  test_files: []
@@ -1,37 +0,0 @@
1
- version: '3.7'
2
-
3
- <% image_name = Modulorails.data.name.parameterize %>
4
-
5
- services:
6
- app:
7
- image: modulotechgroup/<%= image_name %>:dev
8
- build:
9
- context: .
10
- dockerfile: Dockerfile
11
- depends_on:
12
- - database
13
- - redis
14
- ports:
15
- - '3000:3000'
16
- volumes:
17
- - .:/app
18
- environment:
19
- RAILS_ENV: development
20
- URL: http://localhost:3000
21
- <%= image_name.upcase %>_DATABASE_HOST: database
22
- <%= image_name.upcase %>_DATABASE_NAME: <%= image_name %>
23
- entrypoint: ./entrypoints/docker-entrypoint.sh
24
-
25
- database:
26
- image: mysql:8.0
27
- volumes:
28
- - db_data:/var/lib/mysql
29
- environment:
30
- MYSQL_ALLOW_EMPTY_PASSWORD: 'true'
31
- MYSQL_DATABASE: <%= image_name %>
32
-
33
- redis:
34
- image: redis:6.2-alpine
35
-
36
- volumes:
37
- db_data:
@@ -1,79 +0,0 @@
1
- <%- adapter = Modulorails.data.adapter -%>
2
- <%- if adapter =~ /mysql/ -%>
3
- <%= GitlabciGenerator::MYSQL_DOCKER_DB -%>
4
- <%- else -%>
5
- <%= GitlabciGenerator::POSTGRES_DOCKER_DB -%>
6
- <%- end -%>
7
-
8
- image: ruby:<%= Modulorails.data.ruby_version %>
9
- stages:
10
- - lint
11
- - test
12
- - deploy
13
- cache:
14
- key: <%= Modulorails.data.rails_name.parameterize %>-ci_cd
15
- paths:
16
- - vendor/ruby
17
-
18
- before_script:
19
- - apt-get update -qy
20
- - 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )'
21
- - eval $(ssh-agent -s)
22
- - ssh-add <(echo "$SSH_PRIVATE_KEY")
23
- - mkdir -p ~/.ssh
24
- - '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'
25
- - apt-get install -y ruby-dev
26
- - gem install bundler -v <%= Modulorails.data.bundler_version %> --no-document
27
- # You might need DPL if you're deploying using Heroku
28
- #- gem install dpl -v 1.10.15 --no-document
29
- # You might need to add some configurations here like a key for a theme
30
- #- bundle config gems.rapidrailsthemes.com "$RRT_CFG"
31
- - bundle install -j $(nproc) --path vendor
32
-
33
- rubocop:
34
- stage: lint
35
- script:
36
- - bundle exec rubocop -D
37
- tags:
38
- - rails
39
- except:
40
- - master
41
- - staging
42
-
43
- test:
44
- stage: test
45
- script:
46
- - cp config/database-ci.yml config/database.yml
47
- - "bundle exec rake db:create RAILS_ENV=test"
48
- - "RAILS_ENV=test bundle exec rake db:migrate:reset"
49
- - bundle exec rspec
50
- tags:
51
- - rails
52
- except:
53
- - master
54
-
55
- staging:
56
- stage: deploy
57
- script:
58
- # Uncomment the next line and update the application name if you're using DPL to deploy on
59
- # Heroku
60
- #- dpl --provider=heroku --app=APP_NAME --api-key=$HEROKU_API_KEY
61
- # Remove the next line if you're not using Capistrano
62
- - bundle exec cap staging deploy
63
- only:
64
- - staging
65
- tags:
66
- - rails
67
-
68
- production:
69
- stage: deploy
70
- script:
71
- # Uncomment the next line and update the application name if you're using DPL to deploy on
72
- # Heroku
73
- #- dpl --provider=heroku --app=APP_NAME --api-key=$HEROKU_API_KEY
74
- # Remove the next line if you're not using Capistrano
75
- - bundle exec cap production deploy
76
- only:
77
- - master
78
- tags:
79
- - rails
@@ -1,3 +0,0 @@
1
- This file ensures the modulorails gem will not try to override your current .gitlab-ci.yml file.
2
-
3
- You can remove this file if you want the generator to rewrite your .gitlab-ci.yml file.
@@ -1,46 +0,0 @@
1
- module Modulorails
2
- # Author: Matthieu 'ciappa_m' Ciappara
3
- # This updates modulorails by editing the gemfile and running a bundle update
4
- class Updater
5
- LATEST_VERSION_URL = 'https://rubygems.org/api/v1/versions/modulorails/latest.json'.freeze
6
-
7
- def self.call(*args)
8
- new(*args).call
9
- end
10
-
11
- def call
12
- # Get the last published version
13
- @last_published_version = HTTParty.get(LATEST_VERSION_URL).parsed_response['version']
14
-
15
- # Do nothing if we could not fetch the last published version (whatever the reason)
16
- # Or if the current version is the same as the last published version
17
- return if @last_published_version.nil? || @last_published_version == Modulorails::VERSION
18
-
19
- # If the last published version is different from the current version, we update the gem
20
- edit_gemfile
21
- end
22
-
23
- private
24
-
25
- def edit_gemfile
26
- # Log to warn the user
27
- puts("[Modulorails] Last version for modulorails is #{@last_published_version} while you "\
28
- "are using version #{Modulorails::VERSION}. Running auto-update.")
29
-
30
- # Read the lines of the Gemfile
31
- gemfile_location = Rails.root.join('Gemfile')
32
- lines = File.readlines gemfile_location
33
-
34
- # Search and replace the modulorails line
35
- index = lines.index { |l| l =~ /gem\s['"]modulorails['"]/ }
36
- lines[index].gsub!(/(\s*)gem\s['"]modulorails['"].*/,
37
- "#{$1}gem 'modulorails', '= #{@last_published_version}'")
38
-
39
- # Update the Gemfile
40
- File.open(gemfile_location, 'w') { |f| f.puts(lines) }
41
-
42
- # Update the gem and the Gemfile.lock
43
- system('bundle install')
44
- end
45
- end
46
- end