modulorails 1.5.2.pre.2 → 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 (52) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +2 -1
  3. data/CHANGELOG.md +40 -8
  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 +4 -1
  44. data/lib/modulorails/version.rb +1 -1
  45. data/lib/modulorails.rb +9 -0
  46. metadata +16 -13
  47. data/lib/generators/modulorails/docker/compose/templates/docker-compose.yml.tt +0 -81
  48. data/lib/generators/modulorails/docker/dockerfile/templates/dockerfiles/modulotech/Dockerfile.prod.tt +0 -66
  49. data/lib/generators/modulorails/docker/dockerfile/templates/dockerfiles/modulotech/Dockerfile.tt +0 -30
  50. data/lib/generators/modulorails/docker/entrypoint/templates/entrypoints/webpack-entrypoint.sh.tt +0 -7
  51. data/lib/generators/modulorails/githooks/templates/dockeruby.rb +0 -124
  52. data/lib/generators/modulorails/sidekiq/templates/entrypoints/sidekiq-entrypoint.sh.tt +0 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ee7efcc2d3da4b18443714b9b6c28d0b72363dd9eb796bc3a315a3083eef7fa9
4
- data.tar.gz: eb1694b391cd532700a3121261531078a1031c7b56c0413d02b9d1e8e3ab45a4
3
+ metadata.gz: ca0e2fc9ce5fff20082c0b6f659c1a8a554a61fac4040c99e8986b091d65991b
4
+ data.tar.gz: 728e081a2e54eab2cfc489ef6f2af22596433ac6fbf0d708635c70ab55846b10
5
5
  SHA512:
6
- metadata.gz: 636da5294080814834c215a2296e2b0b0726c1eb603318782b2b8854d65c96d940ef4ef0a0f72267e9b02c5a3eda44bd69c26b9a09ca3fc9a3cbcaa7b6038c52
7
- data.tar.gz: 3365fb68e3be8bd2a490766610871046ae5d2d64e2dfe6c472ebbb95b28522eb5bf44dbd244bc35a2a69eaee996660974e83b05f1286cf9ebee089b0fa74c0cf
6
+ metadata.gz: cbbbd39d4a47ccdce1d5d19f781420738d97d53396c293d11bddbe9c33ae01fcf936cb0e02e5dd06e9ba9ea1fb05fcffbe97733632b5adfb006b266aba74e70f
7
+ data.tar.gz: 5d29bad917de52d4860ccb6c64d946904f25df9becfd902ba034e619f0bce0e9fd26dc629b75b9e6fa7ad3266bf48aa6d3e9bf1c6d2f4488edf0dc54c8f0cc53
data/.rubocop.yml CHANGED
@@ -10,7 +10,8 @@
10
10
  # See https://docs.rubocop.org/rubocop/configuration
11
11
 
12
12
  # Enabling Rails-specific cops.
13
- require: rubocop-rails
13
+ plugins:
14
+ - rubocop-rails
14
15
 
15
16
  inherit_mode:
16
17
  merge:
data/CHANGELOG.md CHANGED
@@ -4,15 +4,47 @@ This file is used to list changes made in each version of the gem.
4
4
 
5
5
  # Unreleased
6
6
 
7
- # 1.5.2
7
+ # 1.6.0
8
+
9
+ The devcontainer release.
10
+
11
+ ## Features
12
+
13
+ - Add devcontainer support (`.devcontainer/` with Dockerfile, compose.yml, devcontainer.json).
14
+ - Add Claude Code generator for devcontainer (native installation).
15
+ - Add `Bun` JS engine support.
16
+ - Add `bin/dc` and `bin/dcr` scripts to wrap `docker compose` commands.
17
+
18
+ ## Improvements
19
+
20
+ - Split DockerGenerator in multiple sub-generators for individual versioning.
21
+ - Merge all keepfiles into `.modulorails.yml`.
22
+ - Force overwrite of keepfile and config files.
23
+ - Speed-up git hooks by checking if regeneration is needed in `refresh_generations.sh`.
24
+ - Add `Modulorails.deprecator` for Rails 7.2+ compatibility.
25
+ - Wrap health_check initializer in `reloader.to_prepare` block.
26
+ - Update Rubocop rules:
27
+ - Allow `class_methods`/`included` blocks in Concerns to break `Metrics/BlockLength`.
28
+ - Allow commented lines to break `Layout/LineLength`.
29
+ - Update generators for devcontainers (Sidekiq, GitLab CI).
30
+ - Update production.rb template for Rails 8.
31
+ - Replace old `Dockerfile.prod` with Rails-standard one.
32
+
33
+ ## Fixes
8
34
 
9
35
  - Fix typo in `database.yml` template for test database.
10
- - Fix removal of rails' server's pidfile in docker entrypoint.
11
- - Split DockerGenerator in multiple sub-generators to version each one individually.
12
- - Merge all keepfiles in one.
13
- - Wrap health_check initializer in a reloader.to_prepare block.
14
- - Always use latest ruby in dockeruby.
15
- - Add Modulorails.deprecator for compatibility with Rails 7.2.
36
+ - Fix removal of rails server's pidfile in docker entrypoint.
37
+
38
+ ## Deprecations (will be removed in 2.0)
39
+
40
+ - Configuration options: `config.staging_url`, `config.review_base_url`, `config.production_url`, `config.no_auto_update`.
41
+ - `Modulorails::SelfUpdateGenerator`.
42
+ - Infrastructure generators (use Moduloproject 3.0, available later):
43
+ - `DockerGenerator` and all sub-generators
44
+ - `GitlabciGenerator`
45
+ - `ClaudeCodeGenerator`
46
+ - `ModuloprojectGenerator`
47
+ - `SidekiqGenerator`
16
48
 
17
49
  # 1.5.1
18
50
 
@@ -136,7 +168,7 @@ Fixes, updates and health_check release.
136
168
  Docker release.
137
169
 
138
170
  - Add generator for Docker.
139
- - Use templates for Gitlabci generator.
171
+ - Use templates for Gitlabci generator.
140
172
 
141
173
  # 0.2.3
142
174
 
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Modulorails [![Build Status](https://travis-ci.com/Ezveus/modulorails.svg?branch=master)](https://travis-ci.com/Ezveus/modulorails)
1
+ # Modulorails
2
2
 
3
3
  **Modulorails** is the common base for the Ruby on Rails project at [Modulotech](https://www.modulotech.fr/).
4
4
 
@@ -28,11 +28,73 @@ Modulorails.configure do |config|
28
28
  config.project_manager 'The email of the project manager of the application'
29
29
  config.endpoint 'The url to the intranet'
30
30
  config.api_key 'The API key'
31
- config.review_base_url 'The base url for the review environments' # optional
32
- config.staging_url 'The url for the staging environment' # optional
33
- config.production_url 'The url for the production environment' # optional
34
31
  end
35
- ```
32
+ ```
33
+
34
+ ## Features
35
+
36
+ ### Devcontainer Support
37
+
38
+ Modulorails automatically generates a `.devcontainer/` configuration for VS Code and compatible IDEs:
39
+ - `Dockerfile` for the development container
40
+ - `compose.yml` with database, Redis, and mailcatcher services
41
+ - `devcontainer.json` for VS Code integration
42
+
43
+ ### Docker Scripts
44
+
45
+ Two helper scripts are provided in `bin/`:
46
+ - `bin/dc` - Wrapper for `docker compose` commands targeting the devcontainer
47
+ - `bin/dcr` - Wrapper for `docker compose run` with proper TTY and Git configuration
48
+
49
+ Usage:
50
+ ```bash
51
+ bin/dc up -d # Start services in background
52
+ bin/dc logs -f app # Follow app logs
53
+ bin/dcr rails console # Run Rails console in container
54
+ bin/dcr rspec # Run tests in container
55
+ ```
56
+
57
+ ### Claude Code Integration
58
+
59
+ Modulorails can configure your devcontainer for efficient use with Claude Code:
60
+ - Persistent bash history across container restarts
61
+ - Claude Code configuration volume
62
+ - Firewall initialization script
63
+
64
+ ### Bun JS Engine Support
65
+
66
+ Modulorails detects and supports the Bun JavaScript runtime. When `bun.config.js` is present, the devcontainer will include appropriate JS and CSS build services.
67
+
68
+ ### Other Generators
69
+
70
+ - **RubocopGenerator** - Configures `.rubocop.yml` with Modulotech standards
71
+ - **BundlerauditGenerator** - Sets up bundler-audit for security checks
72
+ - **GithooksGenerator** - Installs git hooks for automated checks
73
+ - **HealthCheckGenerator** - Configures the health_check gem
74
+ - **SidekiqGenerator** - Adds Sidekiq background job processing
75
+
76
+ ## Deprecations (will be removed in 2.0)
77
+
78
+ The following features are deprecated and will be removed in version 2.0:
79
+
80
+ ### Configuration options
81
+ - `config.staging_url`
82
+ - `config.review_base_url`
83
+ - `config.production_url`
84
+ - `config.no_auto_update`
85
+
86
+ ### Services
87
+ - `Modulorails::BaseService#log` - Use `Rails.logger.debug` directly
88
+ - `Modulorails::LogsForMethodService` - Use `Rails.logger.debug` directly
89
+
90
+ ### Generators
91
+ The following generators are deprecated and will be moved to Moduloproject 3.0:
92
+ - `Modulorails::DockerGenerator` (and all sub-generators)
93
+ - `Modulorails::GitlabciGenerator`
94
+ - `Modulorails::ClaudeCodeGenerator`
95
+ - `Modulorails::ModuloprojectGenerator`
96
+ - `Modulorails::SidekiqGenerator`
97
+ - `Modulorails::SelfUpdateGenerator` (will be removed entirely)
36
98
 
37
99
  ## Development
38
100
 
@@ -47,10 +109,8 @@ There are tests in `spec`. To run tests:
47
109
  - Ruby 3.1: `docker compose run ruby31`
48
110
 
49
111
  [Appraisal](https://github.com/thoughtbot/appraisal) is used to test the gem against many supported Rails versions:
50
- - Rails 5.2, 6.0 and 6.1 on Ruby 2.5 and 2.6.
51
- - Rails 5.2, 6.0, 6.1 and 7.0 on Ruby 2.7, 3.0 and 3.1.
52
-
53
- Travis CI is configured to automatically run tests in all supported Ruby versions and dependency sets after each push.
112
+ - Rails 5.2, 6.0 and 6.1 on Ruby 2.5 and 2.6.
113
+ - Rails 5.2, 6.0, 6.1 and 7.0 on Ruby 2.7, 3.0 and 3.1.
54
114
 
55
115
  ## Contributing
56
116
 
@@ -0,0 +1,64 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'modulorails/generators/base'
4
+
5
+ class Modulorails::ClaudeCodeGenerator < Modulorails::Generators::Base
6
+
7
+ VERSION = 1
8
+
9
+ desc 'This generator configures the devcontainer to use Claude Code efficiently'
10
+
11
+ protected
12
+
13
+ def create_config
14
+ Modulorails.deprecator.warn(<<~MESSAGE)
15
+ Modulorails::ClaudeCodeGenerator is deprecated and will be removed in version 2.0.
16
+ Use Moduloproject 3.0 (available later) to initialize new projects with Claude Code configuration.
17
+ MESSAGE
18
+
19
+ @data = Modulorails.data
20
+ @image_name = @data.name.parameterize
21
+ @environment_name = @data.environment_name
22
+ @adapter = @data.adapter
23
+ @review_base_url = @data.review_base_url
24
+ @staging_url = @data.staging_url
25
+ @production_url = @data.production_url
26
+
27
+ template 'bin/init-firewall.sh'
28
+ inject_into_file(Rails.root.join('bin/setup'), "\n puts \"== Setting up firewall rules ==\"\n system(\"bin/init-firewall.sh\")\n", after: "APP_ROOT do")
29
+ inject_into_file(Rails.root.join('.devcontainer/devcontainer.json'), after: '"shutdownAction": "stopCompose",') do
30
+ <<-JSON
31
+
32
+ "mounts": [
33
+ "source=claude-code-bashhistory,target=/commandhistory,type=volume",
34
+ "source=claude-code-config,target=/root/.claude,type=volume"
35
+ ],
36
+
37
+ "remoteEnv": {
38
+ "NODE_OPTIONS": "--max-old-space-size=4096",
39
+ "CLAUDE_CONFIG_DIR": "/root/.claude"
40
+ },
41
+
42
+ JSON
43
+ end
44
+ inject_into_file(Rails.root.join('.devcontainer/Dockerfile'), before: 'RUN gem install bundler') do
45
+ <<-DOCKERFILE
46
+ ENV DEVCONTAINER=true
47
+
48
+ # Persist bash history.
49
+ RUN SNIPPET="export PROMPT_COMMAND='history -a' && export HISTFILE=/commandhistory/.bash_history" \
50
+ && mkdir /commandhistory \
51
+ && touch /commandhistory/.bash_history
52
+
53
+ RUN mkdir -p /root/.claude
54
+
55
+ # Install Claude Code (native installation)
56
+ RUN curl -fsSL https://claude.ai/install.sh | bash
57
+
58
+ DOCKERFILE
59
+ end
60
+ rescue StandardError => e
61
+ warn("[Modulorails] Error: cannot configure Claude Code: #{e.message}")
62
+ end
63
+
64
+ end
@@ -0,0 +1,120 @@
1
+ include:
2
+ - project: 'modulosource/modulotech/devops/gitlab-ci-templates'
3
+ file:
4
+ - '/templates/helm.gitlab-ci.yml'
5
+ - '/templates/integration.gitlab-ci.yml'
6
+ - '/templates/docker-buildx.gitlab-ci.yml'
7
+
8
+ variables:
9
+ IMAGE_NAME: <%= @image_name %>
10
+
11
+ stages:
12
+ - test
13
+ - build
14
+ - deploy
15
+
16
+ build_integration_image:
17
+ extends: .build_integration_image
18
+
19
+ test:
20
+ extends: .test
21
+ services:
22
+ <%- if @adapter =~ /mysql/ -%>
23
+ - mysql:8-alpine
24
+ <%- else -%>
25
+ - postgres:16-alpine
26
+ <%- end -%>
27
+ - redis:7-alpine
28
+ variables:
29
+ RAILS_ENV: test
30
+ <%- if @adapter =~ /mysql/ -%>
31
+ MYSQL_DATABASE: <%= @image_name %>-test
32
+ MYSQL_ALLOW_EMPTY_PASSWORD: 'true'
33
+ DATABASE_TEST_URL: 'mysql2://root@mysql/<%= @image_name %>-test'
34
+ <%- else -%>
35
+ POSTGRES_DB: <%= @image_name %>-test
36
+ POSTGRES_USER: postgres
37
+ POSTGRES_PASSWORD: postgres
38
+ DATABASE_TEST_URL: 'postgresql://postgres:postgres@postgres/<%= @image_name %>-test'
39
+ <%- end -%>
40
+ script:
41
+ - bin/test
42
+
43
+ docker_build:
44
+ extends: .docker_buildx_push
45
+ variables:
46
+ DOCKERFILE: Dockerfile
47
+ only:
48
+ - merge_requests
49
+ - staging
50
+ - master
51
+
52
+ <%- if @review_base_url.present? -%>
53
+ deploy_review:
54
+ extends: .deploy_helm
55
+ variables:
56
+ NAMESPACE: <%= @image_name %>-$CI_ENVIRONMENT_SLUG
57
+ NAME: <%= @image_name %>
58
+ CHART_NAME: rails
59
+ CONFIG_FILE: config/deploy/review.yaml
60
+ EXTRA_VARS: --set image.tag=$CI_COMMIT_SHORT_SHA --set ingress.hosts[0].host=${CI_ENVIRONMENT_SLUG}.<%= @review_base_url %> --set ingress.tls[0].hosts[0]=${CI_ENVIRONMENT_SLUG}.<%= @review_base_url %> --set env.url=${CI_ENVIRONMENT_SLUG}.<%= @review_base_url %> --set database.url=$DATABASE_URL --set master_key.key=$MASTER_KEY
61
+ environment:
62
+ name: review/$CI_COMMIT_REF_SLUG
63
+ url: https://${CI_ENVIRONMENT_SLUG}.<%= @review_base_url %>
64
+ on_stop: stop_review
65
+ auto_stop_in: 3 days
66
+ only:
67
+ - merge_requests
68
+
69
+ stop_review:
70
+ extends: .stop_review
71
+ variables:
72
+ NAMESPACE: <%= @image_name %>-$CI_ENVIRONMENT_SLUG
73
+ NAME: <%= @image_name %>
74
+ only:
75
+ - merge_requests
76
+ <%- end -%>
77
+
78
+ <%- if @staging_url.present? -%>
79
+ deploy_staging:
80
+ extends: .deploy_helm
81
+ variables:
82
+ NAMESPACE: <%= @image_name %>
83
+ NAME: <%= @image_name %>
84
+ CHART_NAME: rails
85
+ CONFIG_FILE: config/deploy/staging.yaml
86
+ EXTRA_VARS: --set image.tag=$CI_COMMIT_SHORT_SHA --set database.url=$DATABASE_URL --set master_key.key=$MASTER_KEY
87
+ environment:
88
+ name: staging
89
+ url: https://<%= @staging_url %>
90
+ on_stop: stop_staging
91
+ auto_stop_in: 7 days
92
+ only:
93
+ - staging
94
+
95
+ stop_staging:
96
+ extends: .stop_staging
97
+ variables:
98
+ NAMESPACE: <%= @image_name %>
99
+ NAME: <%= @image_name %>
100
+ only:
101
+ - staging
102
+ needs:
103
+ - docker_build
104
+ <%- end -%>
105
+
106
+ <%- if @production_url.present? -%>
107
+ deploy_production:
108
+ extends: .deploy_helm
109
+ variables:
110
+ NAMESPACE: <%= @image_name %>
111
+ NAME: <%= @image_name %>
112
+ CHART_NAME: rails
113
+ CONFIG_FILE: config/deploy/production.yaml
114
+ EXTRA_VARS: --set image.tag=$CI_COMMIT_SHORT_SHA
115
+ environment:
116
+ name: production
117
+ url: https://<%= @production_url %>
118
+ only:
119
+ - master
120
+ <%- end -%>
@@ -0,0 +1,6 @@
1
+ This file ensures the modulorails gem will not try to override your current .gitlab-ci.yml
2
+ file on Rails start.
3
+
4
+ If you want to reset your CI configuration, you can either:
5
+ - remove this file,
6
+ - or run `rails g modulorails:gitlabci`.
@@ -0,0 +1,118 @@
1
+ #!/bin/bash
2
+ set -euo pipefail # Exit on error, undefined vars, and pipeline failures
3
+ IFS=$'\n\t' # Stricter word splitting
4
+
5
+ # Flush existing rules and delete existing ipsets
6
+ iptables -F
7
+ iptables -X
8
+ iptables -t nat -F
9
+ iptables -t nat -X
10
+ iptables -t mangle -F
11
+ iptables -t mangle -X
12
+ ipset destroy allowed-domains 2>/dev/null || true
13
+
14
+ # First allow DNS and localhost before any restrictions
15
+ # Allow outbound DNS
16
+ iptables -A OUTPUT -p udp --dport 53 -j ACCEPT
17
+ # Allow inbound DNS responses
18
+ iptables -A INPUT -p udp --sport 53 -j ACCEPT
19
+ # Allow outbound SSH
20
+ iptables -A OUTPUT -p tcp --dport 22 -j ACCEPT
21
+ # Allow inbound SSH responses
22
+ iptables -A INPUT -p tcp --sport 22 -m state --state ESTABLISHED -j ACCEPT
23
+ # Allow localhost
24
+ iptables -A INPUT -i lo -j ACCEPT
25
+ iptables -A OUTPUT -o lo -j ACCEPT
26
+
27
+ # Create ipset with CIDR support
28
+ ipset create allowed-domains hash:net
29
+
30
+ # Fetch GitHub meta information and aggregate + add their IP ranges
31
+ echo "Fetching GitHub IP ranges..."
32
+ gh_ranges=$(curl -s https://api.github.com/meta)
33
+ if [ -z "$gh_ranges" ]; then
34
+ echo "ERROR: Failed to fetch GitHub IP ranges"
35
+ exit 1
36
+ fi
37
+
38
+ if ! echo "$gh_ranges" | jq -e '.web and .api and .git' >/dev/null; then
39
+ echo "ERROR: GitHub API response missing required fields"
40
+ exit 1
41
+ fi
42
+
43
+ echo "Processing GitHub IPs..."
44
+ while read -r cidr; do
45
+ if [[ ! "$cidr" =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}/[0-9]{1,2}$ ]]; then
46
+ echo "ERROR: Invalid CIDR range from GitHub meta: $cidr"
47
+ exit 1
48
+ fi
49
+ echo "Adding GitHub range $cidr"
50
+ ipset add allowed-domains "$cidr"
51
+ done < <(echo "$gh_ranges" | jq -r '(.web + .api + .git)[]' | aggregate -q)
52
+
53
+ # Resolve and add other allowed domains
54
+ for domain in \
55
+ "registry.npmjs.org" \
56
+ "api.anthropic.com" \
57
+ "sentry.io" \
58
+ "statsig.anthropic.com" \
59
+ "statsig.com"; do
60
+ echo "Resolving $domain..."
61
+ ips=$(dig +short A "$domain")
62
+ if [ -z "$ips" ]; then
63
+ echo "ERROR: Failed to resolve $domain"
64
+ exit 1
65
+ fi
66
+
67
+ while read -r ip; do
68
+ if [[ ! "$ip" =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
69
+ echo "ERROR: Invalid IP from DNS for $domain: $ip"
70
+ exit 1
71
+ fi
72
+ echo "Adding $ip for $domain"
73
+ ipset add allowed-domains "$ip"
74
+ done < <(echo "$ips")
75
+ done
76
+
77
+ # Get host IP from default route
78
+ HOST_IP=$(ip route | grep default | cut -d" " -f3)
79
+ if [ -z "$HOST_IP" ]; then
80
+ echo "ERROR: Failed to detect host IP"
81
+ exit 1
82
+ fi
83
+
84
+ HOST_NETWORK=$(echo "$HOST_IP" | sed "s/\.[0-9]*$/.0\/24/")
85
+ echo "Host network detected as: $HOST_NETWORK"
86
+
87
+ # Set up remaining iptables rules
88
+ iptables -A INPUT -s "$HOST_NETWORK" -j ACCEPT
89
+ iptables -A OUTPUT -d "$HOST_NETWORK" -j ACCEPT
90
+
91
+ # Set default policies to DROP first
92
+ iptables -P INPUT DROP
93
+ iptables -P FORWARD DROP
94
+ iptables -P OUTPUT DROP
95
+
96
+ # First allow established connections for already approved traffic
97
+ iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
98
+ iptables -A OUTPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
99
+
100
+ # Then allow only specific outbound traffic to allowed domains
101
+ iptables -A OUTPUT -m set --match-set allowed-domains dst -j ACCEPT
102
+
103
+ echo "Firewall configuration complete"
104
+ echo "Verifying firewall rules..."
105
+ if curl --connect-timeout 5 https://example.com >/dev/null 2>&1; then
106
+ echo "ERROR: Firewall verification failed - was able to reach https://example.com"
107
+ exit 1
108
+ else
109
+ echo "Firewall verification passed - unable to reach https://example.com as expected"
110
+ fi
111
+
112
+ # Verify GitHub API access
113
+ if ! curl --connect-timeout 5 https://api.github.com/zen >/dev/null 2>&1; then
114
+ echo "ERROR: Firewall verification failed - unable to reach https://api.github.com"
115
+ exit 1
116
+ else
117
+ echo "Firewall verification passed - able to reach https://api.github.com as expected"
118
+ fi
@@ -8,19 +8,20 @@ module Modulorails
8
8
 
9
9
  class ComposeGenerator < ::Modulorails::Generators::DockerBase
10
10
 
11
- VERSION = 1
11
+ VERSION = 2
12
12
 
13
13
  desc 'This generator creates Docker Compose configuration'
14
14
 
15
15
  protected
16
16
 
17
17
  def create_config
18
- @data = Modulorails.data
19
- @adapter = @data.adapter
20
- @webpack_container_needed = @data.webpacker_version.present?
21
- @image_name = @data.name.parameterize
18
+ Modulorails.deprecator.warn(<<~MESSAGE)
19
+ Modulorails::Docker::ComposeGenerator 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
22
 
23
- create_new_file('docker-compose.yml', 'compose.yml', executable: false)
23
+ remove_file('docker-compose.yml')
24
+ remove_file('compose.yml')
24
25
  rescue StandardError => e
25
26
  warn("[Modulorails] Error: cannot generate Docker Compose configuration: #{e.message}")
26
27
  end
@@ -8,20 +8,26 @@ module Modulorails
8
8
 
9
9
  class ConfigGenerator < Modulorails::Generators::DockerBase
10
10
 
11
- VERSION = 1
11
+ VERSION = 2
12
12
 
13
13
  desc 'This generator creates application configuration'
14
14
 
15
15
  protected
16
16
 
17
17
  def create_config
18
+ Modulorails.deprecator.warn(<<~MESSAGE)
19
+ Modulorails::Docker::ConfigGenerator 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
25
+ @image_name = @data.name.parameterize
20
26
 
21
- template 'config/database.yml'
22
- template 'config/cable.yml'
23
- template 'config/initializers/0_redis.rb'
24
- template 'config/puma.rb'
27
+ template 'config/database.yml', force: true
28
+ template 'config/cable.yml', force: true
29
+ template 'config/initializers/0_redis.rb', force: true
30
+ template 'config/puma.rb', force: true
25
31
  rescue StandardError => e
26
32
  warn("[Modulorails] Error: cannot generate application configuration: #{e.message}")
27
33
  end
@@ -1,14 +1,19 @@
1
1
  development: &default
2
2
  <%- if @adapter =~ /mysql/ -%>
3
3
  adapter: mysql2
4
+ url: <%%= ENV.fetch('DATABASE_URL', 'mysql2://root@database/<%= @image_name %>') %>
4
5
  <%- else -%>
5
6
  adapter: postgresql
7
+ url: <%%= ENV.fetch('DATABASE_URL', 'postgresql://postgres:postgres@database/<%= @image_name %>') %>
6
8
  <%- end -%>
7
- url: <%%= ENV['DATABASE_URL'] %>
8
9
 
9
10
  test:
10
11
  <<: *default
11
- database: <%%= ENV['DATABASE_TEST_URL'] %>
12
+ <%- if @adapter =~ /mysql/ -%>
13
+ url: <%%= ENV.fetch('DATABASE_TEST_URL', 'mysql2://root@database/<%= @image_name %>-test') %>
14
+ <%- else -%>
15
+ url: <%%= ENV.fetch('DATABASE_TEST_URL', 'postgresql://postgres:postgres@database/<%= @image_name %>-test') %>
16
+ <%- end -%>
12
17
 
13
18
  staging:
14
19
  <<: *default
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'modulorails/generators/docker_base'
4
+ require 'generators/modulorails/sidekiq/sidekiq_generator'
5
+
6
+ module Modulorails
7
+
8
+ module Docker
9
+
10
+ class DevcontainerGenerator < Modulorails::Generators::DockerBase
11
+
12
+ VERSION = 1
13
+
14
+ desc 'This generator creates devcontainer configuration'
15
+
16
+ protected
17
+
18
+ def create_config
19
+ Modulorails.deprecator.warn(<<~MESSAGE)
20
+ Modulorails::Docker::DevcontainerGenerator 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
+
24
+ remove_old_dockerfiles
25
+ create_template_files
26
+ rescue StandardError => e
27
+ warn("[Modulorails] Error: cannot generate devcontainer configuration: #{e.message}")
28
+ end
29
+
30
+ private
31
+
32
+ def remove_old_dockerfiles
33
+ remove_file 'compose.yml'
34
+ remove_file 'docker-compose.yml'
35
+ end
36
+
37
+ def create_template_files
38
+ @data = Modulorails.data
39
+ @adapter = @data.adapter
40
+ @image_name = @data.name.parameterize
41
+ @js_engine = @data.js_engine
42
+
43
+ template 'devcontainer/devcontainer.json', '.devcontainer/devcontainer.json'
44
+ template 'devcontainer/compose.yml', '.devcontainer/compose.yml'
45
+ template 'devcontainer/Dockerfile', '.devcontainer/Dockerfile'
46
+ end
47
+
48
+ end
49
+
50
+ end
51
+
52
+ end
@@ -0,0 +1,53 @@
1
+ FROM ruby:<%= @data.ruby_version %>-alpine
2
+
3
+ ENV RAILS_ENV=development
4
+ ENV EDITOR=vim
5
+ WORKDIR /rails
6
+
7
+ RUN apk add --update --no-cache \
8
+ alpine-sdk \
9
+ nodejs \
10
+ tzdata \
11
+ gcompat \
12
+ vim \
13
+ bash \
14
+ openssh \
15
+ yaml-dev \
16
+ curl \
17
+ <%- if @adapter =~ /mysql/ -%>
18
+ mysql-dev
19
+ <%- else -%>
20
+ postgresql-dev
21
+ <%- end -%>
22
+ RUN gem install bundler -v <%= @data.bundler_version %>
23
+
24
+ <%- case @js_engine -%>
25
+ <%- when :webpacker -%>
26
+ RUN apk add yarn
27
+
28
+ # Install node modules
29
+ COPY package.json yarn.lock ./
30
+ RUN yarn install
31
+ <%- when :bun -%>
32
+ # Install bun
33
+ ENV BUN_INSTALL=/usr/local/bun
34
+ ENV PATH="$BUN_INSTALL/bin:$PATH"
35
+ RUN curl -fsSL https://bun.sh/install | bash
36
+
37
+ # Install node modules
38
+ COPY package.json bun.lock ./
39
+ RUN bun install
40
+ <%- end -%>
41
+
42
+ COPY Gemfile Gemfile.lock ./
43
+ RUN bundle install --jobs=2
44
+
45
+ COPY . .
46
+
47
+ RUN sed -i 's:/bin/ash:/bin/bash:g' /etc/passwd
48
+
49
+ EXPOSE 3000
50
+
51
+ ENTRYPOINT ["./bin/docker-entrypoint"]
52
+
53
+ CMD ["sleep", "infinity"]