modulorails 1.5.2.pre.2 → 1.7.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/.claude/skills/release-modulorails/SKILL.md +150 -0
- data/.rubocop.yml +2 -1
- data/CHANGELOG.md +55 -8
- data/Gemfile.lock +75 -26
- 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/rubocop_generator.rb +8 -3
- 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 +41 -12
- data/lib/modulorails/generators/base.rb +1 -1
- data/lib/modulorails/railtie.rb +4 -1
- data/lib/modulorails/version.rb +1 -1
- data/lib/modulorails.rb +15 -5
- metadata +17 -10
- 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
|
@@ -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 =
|
|
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
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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
|
-
|
|
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 =
|
|
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
|
-
|
|
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"]
|
|
@@ -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:
|
data/lib/generators/modulorails/docker/devcontainer/templates/devcontainer/devcontainer.json.tt
ADDED
|
@@ -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 =
|
|
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
|
-
@
|
|
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
|
|
32
|
-
|
|
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
|
|
36
|
-
|
|
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
|
-
|
|
20
|
+
<%- if @adapter =~ /mysql/ -%>
|
|
21
21
|
mysql-client
|
|
22
|
-
|
|
22
|
+
<%- else -%>
|
|
23
23
|
postgresql-client
|
|
24
|
-
|
|
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
|
-
|
|
42
|
+
yaml-dev \
|
|
43
|
+
curl \
|
|
44
|
+
bash \
|
|
45
|
+
<%- if @adapter =~ /mysql/ -%>
|
|
44
46
|
mysql-dev
|
|
45
|
-
|
|
47
|
+
<%- else -%>
|
|
46
48
|
postgresql-dev
|
|
47
|
-
|
|
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
|
-
<%-
|
|
69
|
+
<%- case @js_engine -%>
|
|
70
|
+
<%- when :webpacker -%>
|
|
71
|
+
# Install node modules
|
|
58
72
|
COPY package.json yarn.lock ./
|
|
59
73
|
RUN yarn install
|
|
60
|
-
<%-
|
|
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
|