modulorails 1.5.2.pre.1 → 1.6.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 +4 -4
- data/.rubocop.yml +2 -1
- data/CHANGELOG.md +40 -7
- data/README.md +69 -9
- data/lib/generators/modulorails/claude_code/claude_code_generator.rb +64 -0
- data/lib/generators/modulorails/claude_code/templates/.gitlab-ci.yml.tt +120 -0
- data/lib/generators/modulorails/claude_code/templates/.modulorails-gitlab-ci +6 -0
- data/lib/generators/modulorails/claude_code/templates/bin/init-firewall.sh.tt +118 -0
- data/lib/generators/modulorails/docker/compose/compose_generator.rb +7 -6
- data/lib/generators/modulorails/docker/config/config_generator.rb +11 -5
- data/lib/generators/modulorails/docker/config/templates/config/database.yml.tt +7 -2
- data/lib/generators/modulorails/docker/devcontainer/devcontainer_generator.rb +52 -0
- data/lib/generators/modulorails/docker/devcontainer/templates/devcontainer/Dockerfile.tt +53 -0
- data/lib/generators/modulorails/docker/devcontainer/templates/devcontainer/compose.yml.tt +97 -0
- data/lib/generators/modulorails/docker/devcontainer/templates/devcontainer/devcontainer.json.tt +80 -0
- data/lib/generators/modulorails/docker/docker_generator.rb +7 -0
- data/lib/generators/modulorails/docker/dockerfile/dockerfile_generator.rb +15 -11
- data/lib/generators/modulorails/docker/dockerfile/templates/dockerfiles/{rails/Dockerfile.prod.tt → Dockerfile.prod.tt} +31 -12
- data/lib/generators/modulorails/docker/dockerfile/templates/dockerfiles/dockerignore.tt +120 -0
- data/lib/generators/modulorails/docker/entrypoint/entrypoint_generator.rb +11 -5
- data/lib/generators/modulorails/docker/entrypoint/templates/entrypoints/docker-entrypoint.sh.tt +5 -0
- data/lib/generators/modulorails/githooks/githooks_generator.rb +5 -3
- data/lib/generators/modulorails/githooks/templates/dc.sh +30 -0
- data/lib/generators/modulorails/githooks/templates/dcr.sh +47 -0
- data/lib/generators/modulorails/githooks/templates/post-rewrite.sh +1 -1
- data/lib/generators/modulorails/githooks/templates/pre-merge-commit.sh +1 -1
- data/lib/generators/modulorails/githooks/templates/refresh_generations.sh +17 -9
- data/lib/generators/modulorails/gitlabci/gitlabci_generator.rb +7 -1
- data/lib/generators/modulorails/gitlabci/templates/.gitlab-ci.yml.tt +15 -13
- data/lib/generators/modulorails/gitlabci/templates/bin/test.sh.tt +36 -0
- data/lib/generators/modulorails/gitlabci/templates/config/deploy/production.yaml.tt +4 -4
- data/lib/generators/modulorails/gitlabci/templates/config/deploy/review.yaml.tt +4 -4
- data/lib/generators/modulorails/gitlabci/templates/config/deploy/staging.yaml.tt +7 -7
- data/lib/generators/modulorails/moduloproject/moduloproject_generator.rb +8 -3
- data/lib/generators/modulorails/moduloproject/templates/config/environments/production.rb.tt +21 -51
- data/lib/generators/modulorails/rubocop/templates/rubocop.yml.tt +7 -1
- data/lib/generators/modulorails/self_update/self_update_generator.rb +4 -0
- data/lib/generators/modulorails/sidekiq/sidekiq_generator.rb +95 -38
- data/lib/generators/modulorails/sidekiq/templates/config/initializers/sidekiq.rb.tt +4 -4
- data/lib/modulorails/configuration.rb +17 -7
- data/lib/modulorails/data.rb +39 -12
- data/lib/modulorails/generators/base.rb +1 -1
- data/lib/modulorails/railtie.rb +7 -0
- data/lib/modulorails/services/base_service.rb +1 -1
- data/lib/modulorails/services/logs_for_method_service.rb +1 -1
- data/lib/modulorails/version.rb +1 -1
- data/lib/modulorails.rb +13 -0
- metadata +16 -13
- data/lib/generators/modulorails/docker/compose/templates/docker-compose.yml.tt +0 -81
- data/lib/generators/modulorails/docker/dockerfile/templates/dockerfiles/modulotech/Dockerfile.prod.tt +0 -66
- data/lib/generators/modulorails/docker/dockerfile/templates/dockerfiles/modulotech/Dockerfile.tt +0 -30
- data/lib/generators/modulorails/docker/entrypoint/templates/entrypoints/webpack-entrypoint.sh.tt +0 -7
- data/lib/generators/modulorails/githooks/templates/dockeruby.rb +0 -124
- data/lib/generators/modulorails/sidekiq/templates/entrypoints/sidekiq-entrypoint.sh.tt +0 -7
data/lib/modulorails/data.rb
CHANGED
|
@@ -13,7 +13,7 @@ module Modulorails
|
|
|
13
13
|
ATTRIBUTE_KEYS = %i[
|
|
14
14
|
name main_developer project_manager repository type rails_name ruby_version rails_version
|
|
15
15
|
bundler_version modulorails_version adapter db_version adapter_version webpacker_version
|
|
16
|
-
importmap_version
|
|
16
|
+
importmap_version js_engine
|
|
17
17
|
production_url staging_url review_base_url
|
|
18
18
|
environment_name
|
|
19
19
|
].freeze
|
|
@@ -48,6 +48,10 @@ module Modulorails
|
|
|
48
48
|
}
|
|
49
49
|
end
|
|
50
50
|
|
|
51
|
+
def authentication_type
|
|
52
|
+
@authentication_type ||= authentication_data
|
|
53
|
+
end
|
|
54
|
+
|
|
51
55
|
private
|
|
52
56
|
|
|
53
57
|
def initialize_from_constants
|
|
@@ -104,20 +108,16 @@ module Modulorails
|
|
|
104
108
|
|
|
105
109
|
def initialize_from_database
|
|
106
110
|
# Get the database connection to identify the database used by the application
|
|
107
|
-
|
|
108
|
-
db_connection = begin
|
|
109
|
-
ActiveRecord::Base.connection
|
|
110
|
-
rescue ActiveRecord::NoDatabaseError, ActiveRecord::ConnectionNotEstablished => e
|
|
111
|
-
warn("[Modulorails] Error: #{e.message}")
|
|
112
|
-
nil
|
|
113
|
-
end
|
|
111
|
+
db_connection = ActiveRecord::Base.connection || return
|
|
114
112
|
|
|
115
113
|
# The name of the ActiveRecord adapter; it gives the name of the database system too
|
|
116
|
-
@adapter = db_connection
|
|
114
|
+
@adapter = db_connection.adapter_name.downcase
|
|
117
115
|
|
|
118
116
|
# The version of the database engine; this request works only on MySQL and PostgreSQL
|
|
119
117
|
# It should not be a problem since those are the sole database engines used at Modulotech
|
|
120
|
-
@db_version = db_connection
|
|
118
|
+
@db_version = db_connection.select_value('SELECT version()')
|
|
119
|
+
rescue ActiveRecord::NoDatabaseError, ActiveRecord::ConnectionNotEstablished => e
|
|
120
|
+
warn("[Modulorails] Error: #{e.message}")
|
|
121
121
|
end
|
|
122
122
|
|
|
123
123
|
def initialize_from_gem_specs
|
|
@@ -134,14 +134,28 @@ module Modulorails
|
|
|
134
134
|
# The version of the ActiveRecord adapter
|
|
135
135
|
@adapter_version = gem_version(loaded_specs[@adapter])
|
|
136
136
|
|
|
137
|
+
initialize_from_js_specs(loaded_specs)
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
def initialize_from_js_specs(loaded_specs)
|
|
137
141
|
# The version of the webpacker gem - might be nil
|
|
138
142
|
@webpacker_version = gem_version(loaded_specs['webpacker'])
|
|
139
143
|
|
|
140
144
|
# The version of the importmap-rails gem - might be nil
|
|
141
145
|
@importmap_version = gem_version(loaded_specs['importmap-rails'])
|
|
142
146
|
|
|
143
|
-
|
|
144
|
-
|
|
147
|
+
@js_engine =
|
|
148
|
+
if @webpacker_version
|
|
149
|
+
:webpacker
|
|
150
|
+
elsif @importmap_version
|
|
151
|
+
:importmap
|
|
152
|
+
else
|
|
153
|
+
find_js_engine
|
|
154
|
+
end
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
def find_js_engine
|
|
158
|
+
File.exist?(Rails.root.join('bun.config.js')) ? :bun : :unknown
|
|
145
159
|
end
|
|
146
160
|
|
|
147
161
|
def gem_version(spec)
|
|
@@ -182,6 +196,19 @@ module Modulorails
|
|
|
182
196
|
}
|
|
183
197
|
end
|
|
184
198
|
|
|
199
|
+
def authentication_data
|
|
200
|
+
loaded_specs = Gem.loaded_specs
|
|
201
|
+
|
|
202
|
+
# The version of the devise gem - might be nil
|
|
203
|
+
devise_version = gem_version(loaded_specs['devise'])
|
|
204
|
+
|
|
205
|
+
if devise_version
|
|
206
|
+
:devise
|
|
207
|
+
elsif File.exist?(Rails.root.join('app/controllers/concerns/authentication.rb'))
|
|
208
|
+
:rails
|
|
209
|
+
end
|
|
210
|
+
end
|
|
211
|
+
|
|
185
212
|
end
|
|
186
213
|
|
|
187
214
|
end
|
data/lib/modulorails/railtie.rb
CHANGED
|
@@ -31,6 +31,10 @@ module Modulorails
|
|
|
31
31
|
end
|
|
32
32
|
end
|
|
33
33
|
|
|
34
|
+
initializer "modulorails.deprecator" do |app|
|
|
35
|
+
app.deprecators[:modulorails] = Modulorails.deprecator if app.respond_to?(:deprecators)
|
|
36
|
+
end
|
|
37
|
+
|
|
34
38
|
# Sending data after the initialization ensures we can access
|
|
35
39
|
# all gems, constants and configurations we might need.
|
|
36
40
|
config.after_initialize do
|
|
@@ -58,6 +62,9 @@ module Modulorails
|
|
|
58
62
|
# Add/update Bundler-audit config
|
|
59
63
|
Modulorails.generate_bundleraudit_template
|
|
60
64
|
|
|
65
|
+
# Add/update Claude Code config
|
|
66
|
+
Modulorails.configure_claude_code
|
|
67
|
+
|
|
61
68
|
# Gem's self-update if a new version was released
|
|
62
69
|
Modulorails.self_update
|
|
63
70
|
end
|
|
@@ -45,7 +45,7 @@ class Modulorails::BaseService
|
|
|
45
45
|
# @param method [#to_s] The method calling `#log`
|
|
46
46
|
# @param message [Hash,#to_s] The message to log; Hash will be logged after a #to_json call
|
|
47
47
|
def log(method, message)
|
|
48
|
-
|
|
48
|
+
Modulorails.deprecator.warn(<<~MESSAGE)
|
|
49
49
|
Modulorails::BaseService#log is deprecated and will be removed with version 2.0.
|
|
50
50
|
Use Rails.logger.debug directly with objects instead.
|
|
51
51
|
MESSAGE
|
|
@@ -14,7 +14,7 @@ class Modulorails::LogsForMethodService < Modulorails::BaseService
|
|
|
14
14
|
|
|
15
15
|
# Write a formatted debug log using given initialization parameters
|
|
16
16
|
def call
|
|
17
|
-
|
|
17
|
+
Modulorails.deprecator.warn(<<~MESSAGE)
|
|
18
18
|
Modulorails::LogsForMethodService is deprecated and will be removed with version 2.0.
|
|
19
19
|
Use Rails.logger.debug directly with objects instead.
|
|
20
20
|
MESSAGE
|
data/lib/modulorails/version.rb
CHANGED
data/lib/modulorails.rb
CHANGED
|
@@ -9,6 +9,7 @@ require 'generators/modulorails/self_update/self_update_generator'
|
|
|
9
9
|
require 'generators/modulorails/rubocop/rubocop_generator'
|
|
10
10
|
require 'generators/modulorails/bundleraudit/bundleraudit_generator'
|
|
11
11
|
require 'generators/modulorails/githooks/githooks_generator'
|
|
12
|
+
require 'generators/modulorails/claude_code/claude_code_generator'
|
|
12
13
|
require 'httparty'
|
|
13
14
|
require 'modulorails/error_data'
|
|
14
15
|
require 'modulorails/success_data'
|
|
@@ -166,6 +167,18 @@ module Modulorails
|
|
|
166
167
|
Modulorails::GithooksGenerator.new([], {}, {}).invoke_all
|
|
167
168
|
end
|
|
168
169
|
|
|
170
|
+
# @author Matthieu 'ciappa_m' Ciappara
|
|
171
|
+
#
|
|
172
|
+
# Configure devcontainer for Claude code unless it was already done.
|
|
173
|
+
# The check is done using a 'keepfile'.
|
|
174
|
+
def configure_claude_code
|
|
175
|
+
Modulorails::ClaudeCodeGenerator.new([], {}, {}).invoke_all
|
|
176
|
+
end
|
|
177
|
+
|
|
178
|
+
def deprecator
|
|
179
|
+
@deprecator ||= ActiveSupport::Deprecation.new('2.0', 'Modulorails')
|
|
180
|
+
end
|
|
181
|
+
|
|
169
182
|
end
|
|
170
183
|
|
|
171
184
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: modulorails
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.6.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Matthieu Ciappara
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: bin
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
13
|
name: bundler-audit
|
|
@@ -171,29 +170,36 @@ files:
|
|
|
171
170
|
- gemfiles/rails_61.gemfile
|
|
172
171
|
- gemfiles/rails_70.gemfile
|
|
173
172
|
- lib/generators/modulorails/bundleraudit/bundleraudit_generator.rb
|
|
173
|
+
- lib/generators/modulorails/claude_code/claude_code_generator.rb
|
|
174
|
+
- lib/generators/modulorails/claude_code/templates/.gitlab-ci.yml.tt
|
|
175
|
+
- lib/generators/modulorails/claude_code/templates/.modulorails-gitlab-ci
|
|
176
|
+
- lib/generators/modulorails/claude_code/templates/bin/init-firewall.sh.tt
|
|
174
177
|
- lib/generators/modulorails/docker/compose/compose_generator.rb
|
|
175
|
-
- lib/generators/modulorails/docker/compose/templates/docker-compose.yml.tt
|
|
176
178
|
- lib/generators/modulorails/docker/config/config_generator.rb
|
|
177
179
|
- lib/generators/modulorails/docker/config/templates/config/cable.yml.tt
|
|
178
180
|
- lib/generators/modulorails/docker/config/templates/config/database.yml.tt
|
|
179
181
|
- lib/generators/modulorails/docker/config/templates/config/initializers/0_redis.rb
|
|
180
182
|
- lib/generators/modulorails/docker/config/templates/config/puma.rb
|
|
183
|
+
- lib/generators/modulorails/docker/devcontainer/devcontainer_generator.rb
|
|
184
|
+
- lib/generators/modulorails/docker/devcontainer/templates/devcontainer/Dockerfile.tt
|
|
185
|
+
- lib/generators/modulorails/docker/devcontainer/templates/devcontainer/compose.yml.tt
|
|
186
|
+
- lib/generators/modulorails/docker/devcontainer/templates/devcontainer/devcontainer.json.tt
|
|
181
187
|
- lib/generators/modulorails/docker/docker_generator.rb
|
|
182
188
|
- lib/generators/modulorails/docker/dockerfile/dockerfile_generator.rb
|
|
183
|
-
- lib/generators/modulorails/docker/dockerfile/templates/dockerfiles/
|
|
184
|
-
- lib/generators/modulorails/docker/dockerfile/templates/dockerfiles/
|
|
185
|
-
- lib/generators/modulorails/docker/dockerfile/templates/dockerfiles/rails/Dockerfile.prod.tt
|
|
189
|
+
- lib/generators/modulorails/docker/dockerfile/templates/dockerfiles/Dockerfile.prod.tt
|
|
190
|
+
- lib/generators/modulorails/docker/dockerfile/templates/dockerfiles/dockerignore.tt
|
|
186
191
|
- lib/generators/modulorails/docker/entrypoint/entrypoint_generator.rb
|
|
187
192
|
- lib/generators/modulorails/docker/entrypoint/templates/entrypoints/docker-entrypoint.sh.tt
|
|
188
|
-
- lib/generators/modulorails/docker/entrypoint/templates/entrypoints/webpack-entrypoint.sh.tt
|
|
189
193
|
- lib/generators/modulorails/githooks/githooks_generator.rb
|
|
190
|
-
- lib/generators/modulorails/githooks/templates/
|
|
194
|
+
- lib/generators/modulorails/githooks/templates/dc.sh
|
|
195
|
+
- lib/generators/modulorails/githooks/templates/dcr.sh
|
|
191
196
|
- lib/generators/modulorails/githooks/templates/post-rewrite.sh
|
|
192
197
|
- lib/generators/modulorails/githooks/templates/pre-merge-commit.sh
|
|
193
198
|
- lib/generators/modulorails/githooks/templates/refresh_generations.sh
|
|
194
199
|
- lib/generators/modulorails/gitlabci/gitlabci_generator.rb
|
|
195
200
|
- lib/generators/modulorails/gitlabci/templates/.gitlab-ci.yml.tt
|
|
196
201
|
- lib/generators/modulorails/gitlabci/templates/.modulorails-gitlab-ci
|
|
202
|
+
- lib/generators/modulorails/gitlabci/templates/bin/test.sh.tt
|
|
197
203
|
- lib/generators/modulorails/gitlabci/templates/config/deploy/production.yaml.tt
|
|
198
204
|
- lib/generators/modulorails/gitlabci/templates/config/deploy/review.yaml.tt
|
|
199
205
|
- lib/generators/modulorails/gitlabci/templates/config/deploy/staging.yaml.tt
|
|
@@ -210,7 +216,6 @@ files:
|
|
|
210
216
|
- lib/generators/modulorails/service/templates/service.rb.tt
|
|
211
217
|
- lib/generators/modulorails/sidekiq/sidekiq_generator.rb
|
|
212
218
|
- lib/generators/modulorails/sidekiq/templates/config/initializers/sidekiq.rb.tt
|
|
213
|
-
- lib/generators/modulorails/sidekiq/templates/entrypoints/sidekiq-entrypoint.sh.tt
|
|
214
219
|
- lib/modulorails.rb
|
|
215
220
|
- lib/modulorails/configuration.rb
|
|
216
221
|
- lib/modulorails/data.rb
|
|
@@ -236,7 +241,6 @@ metadata:
|
|
|
236
241
|
source_code_uri: https://github.com/moduloTech/modulorails
|
|
237
242
|
changelog_uri: https://github.com/moduloTech/modulorails/blob/master/CHANGELOG.md
|
|
238
243
|
rubygems_mfa_required: 'true'
|
|
239
|
-
post_install_message:
|
|
240
244
|
rdoc_options: []
|
|
241
245
|
require_paths:
|
|
242
246
|
- lib
|
|
@@ -251,8 +255,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
251
255
|
- !ruby/object:Gem::Version
|
|
252
256
|
version: '0'
|
|
253
257
|
requirements: []
|
|
254
|
-
rubygems_version:
|
|
255
|
-
signing_key:
|
|
258
|
+
rubygems_version: 4.0.3
|
|
256
259
|
specification_version: 4
|
|
257
260
|
summary: Common base for Ruby on Rails projects at Modulotech
|
|
258
261
|
test_files: []
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
services:
|
|
2
|
-
app:
|
|
3
|
-
image: modulotechgroup/<%= @image_name %>:dev
|
|
4
|
-
build:
|
|
5
|
-
context: .
|
|
6
|
-
dockerfile: Dockerfile
|
|
7
|
-
depends_on:
|
|
8
|
-
- database
|
|
9
|
-
- redis
|
|
10
|
-
ports:
|
|
11
|
-
- '3000:3000'
|
|
12
|
-
volumes:
|
|
13
|
-
- .:/app
|
|
14
|
-
environment:
|
|
15
|
-
RAILS_ENV: development
|
|
16
|
-
URL: http://localhost:3000
|
|
17
|
-
<%- if @adapter =~ /mysql/ -%>
|
|
18
|
-
DATABASE_URL: mysql2://root@database/<%= @image_name %>
|
|
19
|
-
DATABASE_TEST_URL: mysql2://root@database/<%= @image_name %>-test
|
|
20
|
-
<%- else -%>
|
|
21
|
-
DATABASE_URL: postgresql://postgres:postgres@database/<%= @image_name %>
|
|
22
|
-
DATABASE_TEST_URL: postgresql://postgres:postgres@database/<%= @image_name %>-test
|
|
23
|
-
<%- end -%>
|
|
24
|
-
REDIS_URL: redis://redis:6379/1
|
|
25
|
-
stdin_open: true
|
|
26
|
-
tty: true
|
|
27
|
-
|
|
28
|
-
<%- if @adapter =~ /mysql/ -%>
|
|
29
|
-
database:
|
|
30
|
-
image: mysql/mysql-server:8.0
|
|
31
|
-
volumes:
|
|
32
|
-
- db_data:/var/lib/mysql
|
|
33
|
-
ports:
|
|
34
|
-
- '3306:3306'
|
|
35
|
-
environment:
|
|
36
|
-
MYSQL_ALLOW_EMPTY_PASSWORD: 'true'
|
|
37
|
-
MYSQL_DATABASE: <%= @image_name %>
|
|
38
|
-
MYSQL_ROOT_HOST: '%'
|
|
39
|
-
<%- else -%>
|
|
40
|
-
database:
|
|
41
|
-
image: postgres:16-alpine
|
|
42
|
-
volumes:
|
|
43
|
-
- db_data:/var/lib/postgresql/data
|
|
44
|
-
ports:
|
|
45
|
-
- '5432:5432'
|
|
46
|
-
environment:
|
|
47
|
-
POSTGRES_USER: postgres
|
|
48
|
-
POSTGRES_PASSWORD: postgres
|
|
49
|
-
POSTGRES_DB: <%= @image_name %>
|
|
50
|
-
LC_COLLATE: 'en_US.UTF-8'
|
|
51
|
-
LC_CTYPE: 'en_US.UTF-8'
|
|
52
|
-
<%- end -%>
|
|
53
|
-
|
|
54
|
-
redis:
|
|
55
|
-
image: redis:7-alpine
|
|
56
|
-
|
|
57
|
-
mailcatcher:
|
|
58
|
-
image: dockage/mailcatcher
|
|
59
|
-
ports:
|
|
60
|
-
- '1080:1080'
|
|
61
|
-
- '1025:1025'
|
|
62
|
-
|
|
63
|
-
<%- if @webpack_container_needed -%>
|
|
64
|
-
webpack:
|
|
65
|
-
image: modulotechgroup/<%= @image_name %>:dev
|
|
66
|
-
build:
|
|
67
|
-
context: .
|
|
68
|
-
dockerfile: Dockerfile
|
|
69
|
-
entrypoint: ./bin/webpack-entrypoint
|
|
70
|
-
volumes:
|
|
71
|
-
- .:/app
|
|
72
|
-
ports:
|
|
73
|
-
- '3035:3035'
|
|
74
|
-
environment:
|
|
75
|
-
NODE_ENV: development
|
|
76
|
-
RAILS_ENV: development
|
|
77
|
-
WEBPACKER_DEV_SERVER_HOST: 0.0.0.0
|
|
78
|
-
<%- end -%>
|
|
79
|
-
|
|
80
|
-
volumes:
|
|
81
|
-
db_data:
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
# BUILD IMAGE
|
|
2
|
-
FROM ruby:<%= @data.ruby_version %>-alpine as builder
|
|
3
|
-
|
|
4
|
-
ENV RAILS_ENV=production \
|
|
5
|
-
SECRET_KEY_BASE=1
|
|
6
|
-
WORKDIR /app
|
|
7
|
-
|
|
8
|
-
RUN apk add --update --no-cache \
|
|
9
|
-
alpine-sdk \
|
|
10
|
-
nodejs \
|
|
11
|
-
tzdata \
|
|
12
|
-
yarn \
|
|
13
|
-
shared-mime-info \
|
|
14
|
-
gcompat \
|
|
15
|
-
<%- if @adapter =~ /mysql/ -%>
|
|
16
|
-
mysql-dev
|
|
17
|
-
<%- else -%>
|
|
18
|
-
postgresql-dev
|
|
19
|
-
<%- end -%>
|
|
20
|
-
RUN gem install bundler -v <%= @data.bundler_version %>
|
|
21
|
-
|
|
22
|
-
COPY Gemfile Gemfile.lock ./
|
|
23
|
-
RUN bundle config set --local deployment 'true' \
|
|
24
|
-
&& bundle check || bundle install --jobs=2 \
|
|
25
|
-
&& rm -rf vendor/bundle/ruby/*/cache/*
|
|
26
|
-
|
|
27
|
-
<%- if @webpack_container_needed -%>
|
|
28
|
-
COPY package.json yarn.lock ./
|
|
29
|
-
RUN yarn install
|
|
30
|
-
<%- end-%>
|
|
31
|
-
|
|
32
|
-
COPY . .
|
|
33
|
-
RUN bundle exec rake assets:precompile
|
|
34
|
-
|
|
35
|
-
# FINAL IMAGE
|
|
36
|
-
FROM ruby:<%= @data.ruby_version %>-alpine
|
|
37
|
-
|
|
38
|
-
ENV RAILS_ENV=development \
|
|
39
|
-
EDITOR=vim
|
|
40
|
-
WORKDIR /app
|
|
41
|
-
RUN adduser -D user
|
|
42
|
-
|
|
43
|
-
RUN apk add --update --no-cache \
|
|
44
|
-
git \
|
|
45
|
-
nodejs \
|
|
46
|
-
tzdata \
|
|
47
|
-
shared-mime-info \
|
|
48
|
-
vim \
|
|
49
|
-
<%- if @adapter =~ /mysql/ -%>
|
|
50
|
-
mysql-dev \
|
|
51
|
-
<%- else -%>
|
|
52
|
-
postgresql-dev \
|
|
53
|
-
<%- end -%>
|
|
54
|
-
&& rm -rf .git/
|
|
55
|
-
RUN gem install bundler -v <%= @data.bundler_version %>
|
|
56
|
-
|
|
57
|
-
COPY --chown=user:user --from=builder /app .
|
|
58
|
-
|
|
59
|
-
RUN bundle config --local path vendor/bundle \
|
|
60
|
-
&& bundle config --local without development:test:assets
|
|
61
|
-
|
|
62
|
-
EXPOSE 3000
|
|
63
|
-
|
|
64
|
-
ENTRYPOINT ["./bin/docker-entrypoint"]
|
|
65
|
-
|
|
66
|
-
CMD ["./bin/rails", "server"]
|
data/lib/generators/modulorails/docker/dockerfile/templates/dockerfiles/modulotech/Dockerfile.tt
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
FROM ruby:<%= @data.ruby_version %>-alpine
|
|
2
|
-
|
|
3
|
-
ENV RAILS_ENV=development
|
|
4
|
-
ENV EDITOR=vim
|
|
5
|
-
WORKDIR /app
|
|
6
|
-
|
|
7
|
-
RUN apk add --update --no-cache \
|
|
8
|
-
alpine-sdk \
|
|
9
|
-
nodejs \
|
|
10
|
-
yarn \
|
|
11
|
-
tzdata \
|
|
12
|
-
gcompat \
|
|
13
|
-
vim \
|
|
14
|
-
<%- if @adapter =~ /mysql/ -%>
|
|
15
|
-
mysql-dev
|
|
16
|
-
<%- else -%>
|
|
17
|
-
postgresql-dev
|
|
18
|
-
<%- end -%>
|
|
19
|
-
RUN gem install bundler -v <%= @data.bundler_version %>
|
|
20
|
-
|
|
21
|
-
COPY Gemfile Gemfile.lock ./
|
|
22
|
-
RUN bundle install --jobs=2
|
|
23
|
-
|
|
24
|
-
COPY . .
|
|
25
|
-
|
|
26
|
-
EXPOSE 3000
|
|
27
|
-
|
|
28
|
-
ENTRYPOINT ["./bin/docker-entrypoint"]
|
|
29
|
-
|
|
30
|
-
CMD ["./bin/rails", "server"]
|
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/ruby
|
|
2
|
-
# frozen_string_literal: true
|
|
3
|
-
|
|
4
|
-
def require_or_install(gem_name, version=nil)
|
|
5
|
-
gem(gem_name, "~> #{version}") unless version.nil?
|
|
6
|
-
require gem_name
|
|
7
|
-
rescue LoadError
|
|
8
|
-
warn "Installing gem #{gem_name}"
|
|
9
|
-
if version.nil?
|
|
10
|
-
Gem.install(gem_name)
|
|
11
|
-
else
|
|
12
|
-
Gem.install(gem_name, "~> #{version}")
|
|
13
|
-
gem(gem_name, "~> #{version}")
|
|
14
|
-
end
|
|
15
|
-
require gem_name
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
require_or_install('shellwords')
|
|
19
|
-
|
|
20
|
-
def check_dockerfile(verbose: false)
|
|
21
|
-
return true if File.exist?('Dockerfile')
|
|
22
|
-
|
|
23
|
-
puts('No Dockerfile') if verbose
|
|
24
|
-
false
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
def entrypoint_location
|
|
28
|
-
entrypoint_line = File.readlines('Dockerfile').find { |line| line.start_with?('ENTRYPOINT') }
|
|
29
|
-
|
|
30
|
-
return nil if entrypoint_line.nil?
|
|
31
|
-
|
|
32
|
-
md = /\[["'](.+)["']\]/.match(entrypoint_line)
|
|
33
|
-
return nil if md.nil? || md[1].nil?
|
|
34
|
-
|
|
35
|
-
md[1]
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
VALID_LAST_INSTRUCTION = /exec "\$\{?@}?"/.freeze
|
|
39
|
-
|
|
40
|
-
def check_entrypoint(verbose: false)
|
|
41
|
-
el = entrypoint_location
|
|
42
|
-
return true if el.nil?
|
|
43
|
-
|
|
44
|
-
unless File.exist?(el)
|
|
45
|
-
warn("Entrypoint not found at location: #{el}") if verbose
|
|
46
|
-
return false
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
last_line = File.readlines(el).last&.strip
|
|
50
|
-
return true if VALID_LAST_INSTRUCTION.match?(last_line)
|
|
51
|
-
|
|
52
|
-
warn("Invalid entrypoint: Last instruction should be 'exec \"${@}\"' instead of '#{last_line}'") if verbose
|
|
53
|
-
|
|
54
|
-
false
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
def executer_docker_run(docker_args, verbose: false)
|
|
58
|
-
pwd = Dir.pwd
|
|
59
|
-
working_directory = File.basename(pwd)
|
|
60
|
-
|
|
61
|
-
volumes = `docker volume ls -q -f name=modulogem`
|
|
62
|
-
volumes = volumes.split("\n").map(&:strip)
|
|
63
|
-
modulogem_gems = volumes.find { |volume| volume.include?('modulogem_gems') }
|
|
64
|
-
modulogem = volumes.find { |volume| volume.include?('modulogem') }
|
|
65
|
-
modulogem_gems_option = modulogem_gems.nil? ? '' : "-v #{modulogem_gems}:/usr/local/bundle"
|
|
66
|
-
modulogem_option = modulogem.nil? ? '' : "-v #{modulogem}:/root"
|
|
67
|
-
|
|
68
|
-
# Check if the shell is a TTY
|
|
69
|
-
tty_option = $stdout.isatty ? '-ti' : ''
|
|
70
|
-
|
|
71
|
-
# Build the command string
|
|
72
|
-
# rubocop:disable Layout/LineLength
|
|
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
|
-
# rubocop:enable Layout/LineLength
|
|
75
|
-
|
|
76
|
-
puts(command) if verbose
|
|
77
|
-
exec(command)
|
|
78
|
-
end
|
|
79
|
-
|
|
80
|
-
def executer_compose_run(docker_args, verbose: false)
|
|
81
|
-
entrypoint_option = check_entrypoint(verbose: verbose) ? '' : '--entrypoint "sh -c"'
|
|
82
|
-
git_email = `git config --get user.email`.strip
|
|
83
|
-
git_name = `git config --get user.name`.strip
|
|
84
|
-
|
|
85
|
-
# Check if the shell is a TTY
|
|
86
|
-
tty_option = $stdout.isatty ? '-ti' : ''
|
|
87
|
-
|
|
88
|
-
# rubocop:disable Layout/LineLength
|
|
89
|
-
command = %(docker compose build && docker compose run --rm #{tty_option} -e "GIT_AUTHOR_EMAIL=#{git_email}" -e "GIT_AUTHOR_NAME=#{git_name}" -e "GIT_COMMITTER_EMAIL=#{git_email}" -e "GIT_COMMITTER_NAME=#{git_name}" #{entrypoint_option} app)
|
|
90
|
-
command = if entrypoint_option == ''
|
|
91
|
-
"#{command} #{docker_args}"
|
|
92
|
-
else
|
|
93
|
-
"#{command} '#{docker_args}'"
|
|
94
|
-
end
|
|
95
|
-
# rubocop:enable Layout/LineLength
|
|
96
|
-
puts(command) if verbose
|
|
97
|
-
exec(command)
|
|
98
|
-
end
|
|
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
|
-
|
|
106
|
-
def main(args, verbose: false)
|
|
107
|
-
# Escape each argument individually
|
|
108
|
-
escaped_args = args.map { |arg| Shellwords.escape(arg) }
|
|
109
|
-
|
|
110
|
-
# Prefix the arguments with a `ruby` command if there is not already one
|
|
111
|
-
docker_args = if contains_command(escaped_args)
|
|
112
|
-
escaped_args.join(' ')
|
|
113
|
-
else
|
|
114
|
-
"ruby #{escaped_args.join(' ')}"
|
|
115
|
-
end
|
|
116
|
-
|
|
117
|
-
if check_dockerfile(verbose: verbose)
|
|
118
|
-
executer_compose_run(docker_args, verbose: verbose)
|
|
119
|
-
else
|
|
120
|
-
executer_docker_run(docker_args, verbose: verbose)
|
|
121
|
-
end
|
|
122
|
-
end
|
|
123
|
-
|
|
124
|
-
main(ARGV, verbose: true)
|