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.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +2 -1
  3. data/CHANGELOG.md +40 -7
  4. data/README.md +69 -9
  5. data/lib/generators/modulorails/claude_code/claude_code_generator.rb +64 -0
  6. data/lib/generators/modulorails/claude_code/templates/.gitlab-ci.yml.tt +120 -0
  7. data/lib/generators/modulorails/claude_code/templates/.modulorails-gitlab-ci +6 -0
  8. data/lib/generators/modulorails/claude_code/templates/bin/init-firewall.sh.tt +118 -0
  9. data/lib/generators/modulorails/docker/compose/compose_generator.rb +7 -6
  10. data/lib/generators/modulorails/docker/config/config_generator.rb +11 -5
  11. data/lib/generators/modulorails/docker/config/templates/config/database.yml.tt +7 -2
  12. data/lib/generators/modulorails/docker/devcontainer/devcontainer_generator.rb +52 -0
  13. data/lib/generators/modulorails/docker/devcontainer/templates/devcontainer/Dockerfile.tt +53 -0
  14. data/lib/generators/modulorails/docker/devcontainer/templates/devcontainer/compose.yml.tt +97 -0
  15. data/lib/generators/modulorails/docker/devcontainer/templates/devcontainer/devcontainer.json.tt +80 -0
  16. data/lib/generators/modulorails/docker/docker_generator.rb +7 -0
  17. data/lib/generators/modulorails/docker/dockerfile/dockerfile_generator.rb +15 -11
  18. data/lib/generators/modulorails/docker/dockerfile/templates/dockerfiles/{rails/Dockerfile.prod.tt → Dockerfile.prod.tt} +31 -12
  19. data/lib/generators/modulorails/docker/dockerfile/templates/dockerfiles/dockerignore.tt +120 -0
  20. data/lib/generators/modulorails/docker/entrypoint/entrypoint_generator.rb +11 -5
  21. data/lib/generators/modulorails/docker/entrypoint/templates/entrypoints/docker-entrypoint.sh.tt +5 -0
  22. data/lib/generators/modulorails/githooks/githooks_generator.rb +5 -3
  23. data/lib/generators/modulorails/githooks/templates/dc.sh +30 -0
  24. data/lib/generators/modulorails/githooks/templates/dcr.sh +47 -0
  25. data/lib/generators/modulorails/githooks/templates/post-rewrite.sh +1 -1
  26. data/lib/generators/modulorails/githooks/templates/pre-merge-commit.sh +1 -1
  27. data/lib/generators/modulorails/githooks/templates/refresh_generations.sh +17 -9
  28. data/lib/generators/modulorails/gitlabci/gitlabci_generator.rb +7 -1
  29. data/lib/generators/modulorails/gitlabci/templates/.gitlab-ci.yml.tt +15 -13
  30. data/lib/generators/modulorails/gitlabci/templates/bin/test.sh.tt +36 -0
  31. data/lib/generators/modulorails/gitlabci/templates/config/deploy/production.yaml.tt +4 -4
  32. data/lib/generators/modulorails/gitlabci/templates/config/deploy/review.yaml.tt +4 -4
  33. data/lib/generators/modulorails/gitlabci/templates/config/deploy/staging.yaml.tt +7 -7
  34. data/lib/generators/modulorails/moduloproject/moduloproject_generator.rb +8 -3
  35. data/lib/generators/modulorails/moduloproject/templates/config/environments/production.rb.tt +21 -51
  36. data/lib/generators/modulorails/rubocop/templates/rubocop.yml.tt +7 -1
  37. data/lib/generators/modulorails/self_update/self_update_generator.rb +4 -0
  38. data/lib/generators/modulorails/sidekiq/sidekiq_generator.rb +95 -38
  39. data/lib/generators/modulorails/sidekiq/templates/config/initializers/sidekiq.rb.tt +4 -4
  40. data/lib/modulorails/configuration.rb +17 -7
  41. data/lib/modulorails/data.rb +39 -12
  42. data/lib/modulorails/generators/base.rb +1 -1
  43. data/lib/modulorails/railtie.rb +7 -0
  44. data/lib/modulorails/services/base_service.rb +1 -1
  45. data/lib/modulorails/services/logs_for_method_service.rb +1 -1
  46. data/lib/modulorails/version.rb +1 -1
  47. data/lib/modulorails.rb +13 -0
  48. metadata +16 -13
  49. data/lib/generators/modulorails/docker/compose/templates/docker-compose.yml.tt +0 -81
  50. data/lib/generators/modulorails/docker/dockerfile/templates/dockerfiles/modulotech/Dockerfile.prod.tt +0 -66
  51. data/lib/generators/modulorails/docker/dockerfile/templates/dockerfiles/modulotech/Dockerfile.tt +0 -30
  52. data/lib/generators/modulorails/docker/entrypoint/templates/entrypoints/webpack-entrypoint.sh.tt +0 -7
  53. data/lib/generators/modulorails/githooks/templates/dockeruby.rb +0 -124
  54. data/lib/generators/modulorails/sidekiq/templates/entrypoints/sidekiq-entrypoint.sh.tt +0 -7
@@ -0,0 +1,97 @@
1
+ services:
2
+ app:
3
+ image: modulotechgroup/<%= @image_name %>:dev
4
+ build:
5
+ context: ..
6
+ dockerfile: .devcontainer/Dockerfile
7
+ depends_on:
8
+ - database
9
+ - redis
10
+ volumes:
11
+ - ..:/rails
12
+ environment:
13
+ RAILS_ENV: development
14
+ URL: http://localhost:3000
15
+ env_file:
16
+ - path: .env
17
+ required: false
18
+ stdin_open: true
19
+ tty: true
20
+
21
+ <%- if @adapter =~ /mysql/ -%>
22
+ database:
23
+ image: mysql/mysql-server:8.0
24
+ volumes:
25
+ - db_data:/var/lib/mysql
26
+ expose:
27
+ - '3306'
28
+ environment:
29
+ MYSQL_ALLOW_EMPTY_PASSWORD: 'true'
30
+ MYSQL_DATABASE: <%= @image_name %>
31
+ MYSQL_ROOT_HOST: '%'
32
+ <%- else -%>
33
+ database:
34
+ image: postgres:16-alpine
35
+ volumes:
36
+ - db_data:/var/lib/postgresql/data
37
+ expose:
38
+ - '5432'
39
+ environment:
40
+ POSTGRES_USER: postgres
41
+ POSTGRES_PASSWORD: postgres
42
+ POSTGRES_DB: <%= @image_name %>
43
+ LC_COLLATE: 'en_US.UTF-8'
44
+ LC_CTYPE: 'en_US.UTF-8'
45
+ <%- end -%>
46
+
47
+ redis:
48
+ image: redis:7-alpine
49
+ volumes:
50
+ - redis_data:/data
51
+
52
+ mailcatcher:
53
+ image: dockage/mailcatcher
54
+ expose:
55
+ - '1080'
56
+ - '1025'
57
+
58
+ <%- case @js_engine -%>
59
+ <%- when :webpacker -%>
60
+ webpack:
61
+ image: modulotechgroup/<%= @image_name %>:dev
62
+ build:
63
+ context: ..
64
+ dockerfile: .devcontainer/Dockerfile
65
+ command: ./bin/webpack-dev-server
66
+ volumes:
67
+ - ..:/rails
68
+ environment:
69
+ NODE_ENV: development
70
+ RAILS_ENV: development
71
+ <%- when :bun -%>
72
+ js:
73
+ image: modulotechgroup/<%= @image_name %>:dev
74
+ build:
75
+ context: ..
76
+ dockerfile: .devcontainer/Dockerfile
77
+ command: bun run build --watch
78
+ volumes:
79
+ - ..:/rails
80
+ environment:
81
+ NODE_ENV: development
82
+
83
+ css:
84
+ image: modulotechgroup/<%= @image_name %>:dev
85
+ build:
86
+ context: ..
87
+ dockerfile: .devcontainer/Dockerfile
88
+ command: bun run watch:css
89
+ volumes:
90
+ - ..:/rails
91
+ environment:
92
+ NODE_ENV: development
93
+ <%- end -%>
94
+
95
+ volumes:
96
+ db_data:
97
+ redis_data:
@@ -0,0 +1,80 @@
1
+ // For format details, see https://containers.dev/implementors/json_reference/.
2
+ // For config options, see the README at: https://github.com/devcontainers/templates/tree/main/src/ruby
3
+ {
4
+ "name": "<%= @image_name %>",
5
+ "dockerComposeFile": "./compose.yml",
6
+ "service": "app",
7
+ "workspaceFolder": "/rails",
8
+ "shutdownAction": "stopCompose",
9
+
10
+ // Features to add to the dev container. More info: https://containers.dev/features.
11
+ "features": {
12
+ "ghcr.io/cirolosapio/devcontainers-features/alpine-docker-outside-of-docker:0": {}
13
+ },
14
+
15
+ // Use 'forwardPorts' to make a list of ports inside the container available locally.
16
+ <%- if @adapter =~ /mysql/ -%>
17
+ "forwardPorts": [3000, "database:3306", "mailcatcher:1080"],
18
+ <%- else -%>
19
+ "forwardPorts": [3000, "database:5432", "mailcatcher:1080"],
20
+ <%- end -%>
21
+
22
+ // Configure tool-specific properties.
23
+ "customizations": {
24
+ "vscode": {
25
+ "yard.spacers.beforeDescription": false,
26
+ "yard.spacers.afterDescription": false,
27
+ "yard.spacers.beforeTags": false,
28
+ "yard.spacers.separateTags": false,
29
+ "yard.spacers.afterTags": false,
30
+ "yard.spacers.beforeSingleTag": false,
31
+ "yard.spacers.afterSingleTag": false,
32
+ "yard.tags.paramNameBeforeType": true,
33
+ "extensions": [
34
+ "ecmel.vscode-html-css",
35
+ "Shopify.ruby-lsp",
36
+ "ms-vscode-remote.remote-containers",
37
+ "KoichiSasada.vscode-rdbg",
38
+ "pavlitsky.yard",
39
+ "eamodio.gitlens",
40
+ "GrapeCity.gc-excelviewer",
41
+ "smoore.yaml-path"
42
+ ],
43
+ "settings": {
44
+ "terminal.integrated.profiles.linux": {
45
+ "JavaScript Debug Terminal": null,
46
+ "Rails console": {
47
+ "path": "rails",
48
+ "env": {
49
+ "DEV_LOG_LEVEL": "error",
50
+ "USE_CACHE": "YES"
51
+ },
52
+ "args": [
53
+ "c"
54
+ ],
55
+ "icon": "ruby",
56
+ "color": "terminal.ansiRed"
57
+ },
58
+ "Rails server": {
59
+ "path": "rails",
60
+ "env": {
61
+ "DEV_LOG_LEVEL": "error",
62
+ "USE_CACHE": "YES"
63
+ },
64
+ "args": [
65
+ "s"
66
+ ],
67
+ "icon": "ruby",
68
+ "color": "terminal.ansiRed"
69
+ }
70
+ }
71
+ }
72
+ }
73
+ },
74
+
75
+ // Uncomment to connect as root instead. More info: https://containers.dev/implementors/json_reference/#remoteUser.
76
+ // "remoteUser": "root",
77
+
78
+ // Use 'postCreateCommand' to run commands after the container is created.
79
+ "postCreateCommand": "bin/setup --skip-server"
80
+ }
@@ -5,6 +5,7 @@ require 'generators/modulorails/docker/entrypoint/entrypoint_generator'
5
5
  require 'generators/modulorails/docker/dockerfile/dockerfile_generator'
6
6
  require 'generators/modulorails/docker/compose/compose_generator'
7
7
  require 'generators/modulorails/docker/config/config_generator'
8
+ require 'generators/modulorails/docker/devcontainer/devcontainer_generator'
8
9
 
9
10
  module Modulorails
10
11
 
@@ -17,6 +18,11 @@ module Modulorails
17
18
  protected
18
19
 
19
20
  def create_config
21
+ Modulorails.deprecator.warn(<<~MESSAGE)
22
+ Modulorails::DockerGenerator is deprecated and will be removed in version 2.0.
23
+ Use Moduloproject 3.0 (available later) to initialize new projects with Docker configuration.
24
+ MESSAGE
25
+
20
26
  remove_old_keepfile('.modulorails-docker')
21
27
 
22
28
  # Running first since the Dockerfile generator checks for existence of entrypoint
@@ -24,6 +30,7 @@ module Modulorails
24
30
  Modulorails::Docker::DockerfileGenerator.new([], {}, {}).invoke_all
25
31
  Modulorails::Docker::ComposeGenerator.new([], {}, {}).invoke_all
26
32
  Modulorails::Docker::ConfigGenerator.new([], {}, {}).invoke_all
33
+ Modulorails::Docker::DevcontainerGenerator.new([], {}, {}).invoke_all
27
34
  rescue StandardError => e
28
35
  warn("[Modulorails] Error: cannot generate Docker configuration: #{e.message}")
29
36
  end
@@ -8,36 +8,40 @@ module Modulorails
8
8
 
9
9
  class DockerfileGenerator < ::Modulorails::Generators::DockerBase
10
10
 
11
- VERSION = 1
11
+ VERSION = 2
12
12
 
13
13
  desc 'This generator creates Dockerfiles'
14
14
 
15
15
  protected
16
16
 
17
17
  def create_config
18
+ Modulorails.deprecator.warn(<<~MESSAGE)
19
+ Modulorails::Docker::DockerfileGenerator is deprecated and will be removed in version 2.0.
20
+ Use Moduloproject 3.0 (available later) to initialize new projects with Docker configuration.
21
+ MESSAGE
22
+
18
23
  @data = Modulorails.data
19
24
  @adapter = @data.adapter
20
- @webpack_container_needed = @data.webpacker_version.present?
25
+ @js_engine = @data.js_engine
21
26
 
22
27
  EntrypointGenerator.new([], {}, {}).invoke_all unless File.exist?('bin/docker-entrypoint')
23
- create_dockerfile
24
28
  create_dockerfile_prod
29
+ create_dockerignore
25
30
  rescue StandardError => e
26
31
  warn("[Modulorails] Error: cannot generate Dockerfiles: #{e.message}")
27
32
  end
28
33
 
29
34
  private
30
35
 
31
- def create_dockerfile
32
- template 'dockerfiles/modulotech/Dockerfile', 'Dockerfile'
36
+ def create_dockerfile_prod
37
+ @rails_72_and_more = Gem::Version.new(@data.rails_version) >= Gem::Version.new('7.2')
38
+
39
+ remove_file 'Dockerfile.prod'
40
+ template 'dockerfiles/Dockerfile.prod', 'Dockerfile', force: true
33
41
  end
34
42
 
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
43
+ def create_dockerignore
44
+ template 'dockerfiles/dockerignore', '.dockerignore'
41
45
  end
42
46
 
43
47
  end
@@ -17,11 +17,11 @@ RUN apk add --update --no-cache \
17
17
  vim \
18
18
  jemalloc \
19
19
  vips \
20
- <%- if @adapter =~ /mysql/ -%>
20
+ <%- if @adapter =~ /mysql/ -%>
21
21
  mysql-client
22
- <%- else -%>
22
+ <%- else -%>
23
23
  postgresql-client
24
- <%- end -%>
24
+ <%- end -%>
25
25
 
26
26
  # Set production environment
27
27
  ENV RAILS_ENV="production" \
@@ -37,27 +37,45 @@ RUN apk add --update --no-cache \
37
37
  alpine-sdk \
38
38
  nodejs \
39
39
  tzdata \
40
- yarn \
41
40
  shared-mime-info \
42
41
  gcompat \
43
- <%- if @adapter =~ /mysql/ -%>
42
+ yaml-dev \
43
+ curl \
44
+ bash \
45
+ <%- if @adapter =~ /mysql/ -%>
44
46
  mysql-dev
45
- <%- else -%>
47
+ <%- else -%>
46
48
  postgresql-dev
47
- <%- end -%>
49
+ <%- end -%>
48
50
 
49
51
  # Install application gems
50
52
  RUN gem install bundler -v <%= @data.bundler_version %>
51
53
 
54
+ <%- case @js_engine -%>
55
+ <%- when :webpacker -%>
56
+ RUN apk add yarn
57
+ <%- when :bun -%>
58
+ # Install bun
59
+ ENV BUN_INSTALL=/usr/local/bun
60
+ ENV PATH="$BUN_INSTALL/bin:$PATH"
61
+ RUN curl -fsSL https://bun.sh/install | bash
62
+ <%- end -%>
63
+
52
64
  COPY Gemfile Gemfile.lock ./
53
65
  RUN bundle install && \
54
66
  rm -rf ~/.bundle/ "${BUNDLE_PATH}"/ruby/*/cache "${BUNDLE_PATH}"/ruby/*/bundler/gems/*/.git && \
55
67
  bundle exec bootsnap precompile --gemfile
56
68
 
57
- <%- if @webpack_container_needed -%>
69
+ <%- case @js_engine -%>
70
+ <%- when :webpacker -%>
71
+ # Install node modules
58
72
  COPY package.json yarn.lock ./
59
73
  RUN yarn install
60
- <%- end-%>
74
+ <%- when :bun -%>
75
+ # Install node modules
76
+ COPY package.json bun.lock ./
77
+ RUN bun install --frozen-lockfile
78
+ <%- end -%>
61
79
 
62
80
  # Copy application code
63
81
  COPY . .
@@ -66,10 +84,11 @@ COPY . .
66
84
  RUN bundle exec bootsnap precompile app/ lib/
67
85
 
68
86
  # Precompiling assets for production without requiring secret RAILS_MASTER_KEY
87
+ <%- if @rails_72_and_more -%>
69
88
  RUN SECRET_KEY_BASE_DUMMY=1 ./bin/rails assets:precompile
70
-
71
-
72
-
89
+ <%- else -%>
90
+ RUN SECRET_KEY_BASE=1 ./bin/rails assets:precompile
91
+ <%- end -%>
73
92
 
74
93
  # Final stage for app image
75
94
  FROM base
@@ -0,0 +1,120 @@
1
+ # Created by https://www.gitignore.io/api/osx,rails
2
+
3
+ dump.rdb
4
+
5
+ coverage
6
+ *.xlsx
7
+
8
+ ### OSX ###
9
+ *.DS_Store
10
+ .AppleDouble
11
+ .LSOverride
12
+
13
+ # Icon must end with two \r
14
+ Icon
15
+ # Thumbnails
16
+ ._*
17
+ # Files that might appear in the root of a volume
18
+ .DocumentRevisions-V100
19
+ .fseventsd
20
+ .Spotlight-V100
21
+ .TemporaryItems
22
+ .Trashes
23
+ .VolumeIcon.icns
24
+ .com.apple.timemachine.donotpresent
25
+ # Directories potentially created on remote AFP share
26
+ .AppleDB
27
+ .AppleDesktop
28
+ Network Trash Folder
29
+ Temporary Items
30
+ .apdisk
31
+
32
+ ### Rails ###
33
+ *.rbc
34
+ capybara-*.html
35
+ /db/*.sqlite3
36
+ /db/*.sqlite3-journal
37
+ /public/system
38
+ /public/uploads
39
+ /coverage/
40
+ /spec/tmp
41
+ **.orig
42
+ rerun.txt
43
+ pickle-email-*.html
44
+
45
+ config/initializers/secret_token.rb
46
+
47
+ # Only include if you have production secrets in this file, which is no longer a Rails default
48
+ # config/secrets.yml
49
+
50
+ # dotenv
51
+ .env
52
+ .env.sh
53
+
54
+ ## Environment normalization:
55
+ /.bundle
56
+ /vendor/bundle
57
+
58
+ # these should all be checked in to normalize the environment:
59
+ # Gemfile.lock, .ruby-version, .ruby-gemset
60
+
61
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
62
+ .rvmrc
63
+
64
+ # if using bower-rails ignore default bower_components path bower.json files
65
+ /vendor/assets/bower_components
66
+ *.bowerrc
67
+ bower.json
68
+
69
+ # Ignore pow environment settings
70
+ .powenv
71
+
72
+ # Ignore Byebug command history file.
73
+ .byebug_history
74
+
75
+ **/.classpath
76
+ **/.dockerignore
77
+ **/.env
78
+ **/.gitignore
79
+ **/.project
80
+ **/.settings
81
+ **/.toolstarget
82
+ **/.vs
83
+ **/.vscode
84
+ **/*.*proj.user
85
+ **/*.dbmdl
86
+ **/*.jfm
87
+ **/azds.yaml
88
+ **/charts
89
+ **/docker-compose*
90
+ **/compose*
91
+ **/Dockerfile*
92
+ **/node_modules
93
+ **/npm-debug.log
94
+ **/obj
95
+ **/secrets.dev.yaml
96
+ **/values.dev.yaml
97
+ README.md
98
+
99
+ .browserslistrc
100
+ .gitignore
101
+ .gitlab
102
+ .gitlab-ci.yml
103
+ .modulorails-gitlab-ci
104
+ .nvmrc
105
+ .rubocop.yml
106
+ .ruby-gemset
107
+ .ruby-version
108
+
109
+ /public/packs
110
+ /public/packs-test
111
+ /node_modules
112
+ /yarn-error.log
113
+ yarn-debug.log*
114
+ .yarn-integrity
115
+
116
+ /log/*
117
+ /tmp
118
+
119
+ rspec.xml
120
+ rspec_results.txt
@@ -9,18 +9,23 @@ module Modulorails
9
9
 
10
10
  class EntrypointGenerator < Modulorails::Generators::DockerBase
11
11
 
12
- VERSION = 1
12
+ VERSION = 2
13
13
 
14
14
  desc 'This generator creates Docker entrypoints'
15
15
 
16
16
  protected
17
17
 
18
18
  def create_config
19
+ Modulorails.deprecator.warn(<<~MESSAGE)
20
+ Modulorails::Docker::EntrypointGenerator is deprecated and will be removed in version 2.0.
21
+ Use Moduloproject 3.0 (available later) to initialize new projects with Docker configuration.
22
+ MESSAGE
23
+
19
24
  create_docker_entrypoint
20
- create_webpack_entrypoint if Modulorails.data.webpacker_version.present?
25
+ remove_webpack_entrypoint
21
26
 
22
27
  if File.exist?('entrypoints/sidekiq-entrypoint.sh') || File.exist?('bin/sidekiq-entrypoint')
23
- SidekiqGenerator.new([], {}, {}).invoke('add_entrypoint')
28
+ SidekiqGenerator.new([], {}, {}).invoke('remove_entrypoint')
24
29
  end
25
30
  rescue StandardError => e
26
31
  warn("[Modulorails] Error: cannot generate Docker entrypoints: #{e.message}")
@@ -28,8 +33,9 @@ module Modulorails
28
33
 
29
34
  private
30
35
 
31
- def create_webpack_entrypoint
32
- create_new_file('entrypoints/webpack-entrypoint.sh', 'bin/webpack-entrypoint')
36
+ def remove_webpack_entrypoint
37
+ remove_file('entrypoints/webpack-entrypoint.sh')
38
+ remove_file('bin/webpack-entrypoint')
33
39
  end
34
40
 
35
41
  def create_docker_entrypoint
@@ -1,5 +1,10 @@
1
1
  #!/bin/sh -e
2
2
 
3
+ # For non-rails command (webpack, bun, yarn, etc.), we skip all rails-related processes and checks.
4
+ if ! echo "${@}" | grep -qE '\b(rails|bin/rails)\b'; then
5
+ exec "${@}"
6
+ fi
7
+
3
8
  # Enable jemalloc for reduced memory usage and latency.
4
9
  jemalloc_lib=$(find /usr/lib/ -name "libjemalloc.so.2" 2>/dev/null | head -n 1)
5
10
 
@@ -6,7 +6,7 @@ module Modulorails
6
6
 
7
7
  class GithooksGenerator < Modulorails::Generators::Base
8
8
 
9
- VERSION = 1
9
+ VERSION = 2
10
10
 
11
11
  protected
12
12
 
@@ -21,8 +21,10 @@ module Modulorails
21
21
  private
22
22
 
23
23
  def create_hook_executor
24
- template 'dockeruby.rb', 'bin/dockeruby'
25
- chmod 'bin/dockeruby', 0o755
24
+ template 'dc.sh', 'bin/dc'
25
+ chmod 'bin/dc', 0o755
26
+ template 'dcr.sh', 'bin/dcr'
27
+ chmod 'bin/dcr', 0o755
26
28
  end
27
29
 
28
30
  def create_refresh_generations_script
@@ -0,0 +1,30 @@
1
+ #!/usr/bin/env bash
2
+
3
+ # Function to run the main docker command
4
+ run_command() {
5
+ local docker_args="$1"
6
+
7
+ # Build the docker command
8
+ local command="docker compose --project-name \"\$(basename \$(pwd))_devcontainer\" -f .devcontainer/compose.yml"
9
+
10
+ # Execute the command with additional arguments
11
+ eval "$command $docker_args"
12
+ }
13
+
14
+ main() {
15
+ # Check for apk command to determine if we're in an Alpine Linux container
16
+ if ! command -v apk >/dev/null 2>&1; then
17
+ # Escape arguments and pass them to the docker command
18
+ local escaped_args=()
19
+ for arg in "$@"; do
20
+ escaped_args+=("$(printf '%q' "$arg")")
21
+ done
22
+ run_command "${escaped_args[*]}"
23
+ else
24
+ # Execute the given arguments without wrapping
25
+ exec "$@"
26
+ fi
27
+ }
28
+
29
+ # Pass all the script's arguments to the main function
30
+ main "$@"
@@ -0,0 +1,47 @@
1
+ #!/usr/bin/env bash
2
+
3
+ # Function to run the main docker command
4
+ run_command() {
5
+ local docker_args="$1"
6
+
7
+ # Get Git configuration
8
+ local git_email
9
+ git_email=$(git config --get user.email)
10
+ local git_name
11
+ git_name=$(git config --get user.name)
12
+
13
+ # Check if the shell is a TTY
14
+ local tty_option
15
+ if [ -t 1 ]; then
16
+ tty_option='-ti'
17
+ else
18
+ tty_option=''
19
+ fi
20
+
21
+ # Build the docker command
22
+ local command="docker compose -f .devcontainer/compose.yml build && \
23
+ docker compose --project-name \"\$(basename \$(pwd))_devcontainer\" -f .devcontainer/compose.yml run --rm $tty_option \
24
+ -e \"GIT_AUTHOR_EMAIL=$git_email\" -e \"GIT_AUTHOR_NAME=$git_name\" \
25
+ -e \"GIT_COMMITTER_EMAIL=$git_email\" -e \"GIT_COMMITTER_NAME=$git_name\" app"
26
+
27
+ # Execute the command with additional arguments
28
+ eval "$command $docker_args"
29
+ }
30
+
31
+ main() {
32
+ # Check for apk command to determine if we're in an Alpine Linux container
33
+ if ! command -v apk >/dev/null 2>&1; then
34
+ # Escape arguments and pass them to the docker command
35
+ local escaped_args=()
36
+ for arg in "$@"; do
37
+ escaped_args+=("$(printf '%q' "$arg")")
38
+ done
39
+ run_command "${escaped_args[*]}"
40
+ else
41
+ # Execute the given arguments without wrapping
42
+ exec "$@"
43
+ fi
44
+ }
45
+
46
+ # Pass all the script's arguments to the main function
47
+ main "$@"
@@ -1,5 +1,5 @@
1
1
  #!/bin/sh
2
2
  if [ "$1" = "rebase" ]
3
3
  then
4
- exec ./bin/dockeruby ./bin/refresh_generations
4
+ exec ./bin/dc ./bin/refresh_generations
5
5
  fi
@@ -1,2 +1,2 @@
1
1
  #!/bin/sh
2
- exec ./bin/dockeruby ./bin/refresh_generations
2
+ exec ./bin/dc ./bin/refresh_generations
@@ -1,21 +1,29 @@
1
1
  #!/bin/sh
2
2
 
3
- echo 'Regenerate Gemfile.lock'
4
- bundle install
5
- git add Gemfile.lock
3
+ modified_files=$(git diff --cached --name-only)
6
4
 
7
- if [ $(cat Gemfile.lock | grep i18n-js | wc -l) -gt 0 ]
5
+ if echo "$modified_files" | grep -q "Gemfile.lock"
6
+ then
7
+ echo 'Regenerate Gemfile.lock'
8
+ bundle install
9
+ git add Gemfile.lock
10
+ fi
11
+
12
+ if [ "$(cat Gemfile.lock | grep i18n-js | wc -l)" -gt 0 ] && echo "$modified_files" | grep -q "translations.js"
8
13
  then
9
14
  echo 'Regenerate JS translations'
10
15
  rake i18n:js:export
11
16
  git add app/assets/javascripts/i18n/translations.js
12
17
  fi
13
18
 
14
- echo 'Regenerate DB schema'
15
- export RAILS_ENV=test
16
- bundle exec rake db:drop db:create db:schema:load db:migrate
17
- git add db/schema.rb
18
- export RAILS_ENV=development
19
+ if echo "$modified_files" | grep -q "schema.rb"
20
+ then
21
+ echo 'Regenerate DB schema'
22
+ export RAILS_ENV=test
23
+ bundle exec rake db:drop db:create db:schema:load db:migrate
24
+ git add db/schema.rb
25
+ export RAILS_ENV=development
26
+ fi
19
27
 
20
28
  if [ "$(git diff --cached --name-only | wc -l)" -ne 0 ]; then
21
29
  echo "Commit regenerated files by $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>"