yoker 0.1.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 +7 -0
- data/.rubocop.yml +8 -0
- data/LICENSE.txt +21 -0
- data/README.md +223 -0
- data/Rakefile +12 -0
- data/exe/yoker +177 -0
- data/exe/yoker (Copy) +87 -0
- data/lib/yoker/cli/base.rb +106 -0
- data/lib/yoker/cli/init.rb +193 -0
- data/lib/yoker/cli/update.rb +457 -0
- data/lib/yoker/configuration.rb +290 -0
- data/lib/yoker/detectors/database_detector.rb +35 -0
- data/lib/yoker/detectors/rails_detector.rb +48 -0
- data/lib/yoker/detectors/version_manager_detector.rb +91 -0
- data/lib/yoker/errors.rb +149 -0
- data/lib/yoker/generators/base_generator.rb +116 -0
- data/lib/yoker/generators/container/docker.rb +255 -0
- data/lib/yoker/generators/container/docker_compose.rb +255 -0
- data/lib/yoker/generators/container/none.rb +314 -0
- data/lib/yoker/generators/database/mysql.rb +147 -0
- data/lib/yoker/generators/database/postgresql.rb +64 -0
- data/lib/yoker/generators/database/sqlite.rb +123 -0
- data/lib/yoker/generators/version_manager/mise.rb +140 -0
- data/lib/yoker/generators/version_manager/rbenv.rb +165 -0
- data/lib/yoker/generators/version_manager/rvm.rb +246 -0
- data/lib/yoker/templates/bin/setup.rb.erb +232 -0
- data/lib/yoker/templates/config/database_mysql.yml.erb +47 -0
- data/lib/yoker/templates/config/database_postgresql.yml.erb +34 -0
- data/lib/yoker/templates/config/database_sqlite.yml.erb +40 -0
- data/lib/yoker/templates/docker/Dockerfile.erb +124 -0
- data/lib/yoker/templates/docker/docker-compose.yml.erb +117 -0
- data/lib/yoker/templates/docker/entrypoint.sh.erb +94 -0
- data/lib/yoker/templates/docker/init_mysql.sql.erb +44 -0
- data/lib/yoker/templates/docker/init_postgresql.sql.erb +203 -0
- data/lib/yoker/templates/version_managers/gemrc.erb +61 -0
- data/lib/yoker/templates/version_managers/mise.toml.erb +72 -0
- data/lib/yoker/templates/version_managers/rbenv_setup.sh.erb +93 -0
- data/lib/yoker/templates/version_managers/rvm_setup.sh.erb +99 -0
- data/lib/yoker/templates/version_managers/rvmrc.erb +70 -0
- data/lib/yoker/version.rb +5 -0
- data/lib/yoker.rb +32 -0
- data/sig/yoker.rbs +4 -0
- metadata +215 -0
@@ -0,0 +1,232 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require "fileutils"
|
5
|
+
|
6
|
+
# path to your application root.
|
7
|
+
APP_ROOT = File.expand_path("..", __dir__)
|
8
|
+
|
9
|
+
def system!(*args)
|
10
|
+
system(*args, exception: true)
|
11
|
+
end
|
12
|
+
|
13
|
+
def puts_step(message)
|
14
|
+
puts "\n== #{message} =="
|
15
|
+
end
|
16
|
+
|
17
|
+
def puts_success(message)
|
18
|
+
puts "โ
#{message}"
|
19
|
+
end
|
20
|
+
|
21
|
+
def puts_error(message)
|
22
|
+
puts "โ #{message}"
|
23
|
+
end
|
24
|
+
|
25
|
+
def puts_warning(message)
|
26
|
+
puts "โ ๏ธ #{message}"
|
27
|
+
end
|
28
|
+
|
29
|
+
FileUtils.chdir APP_ROOT do
|
30
|
+
puts_step "Installing dependencies"
|
31
|
+
system! "gem install bundler --conservative"
|
32
|
+
system("bundle check") || system!("bundle install")
|
33
|
+
|
34
|
+
<% if version_manager == "mise" -%>
|
35
|
+
# Check if mise is installed
|
36
|
+
puts_step "Checking mise installation"
|
37
|
+
unless system("which mise > /dev/null 2>&1")
|
38
|
+
puts_error "mise is not installed. Please install mise first:"
|
39
|
+
puts " curl https://mise.run | sh"
|
40
|
+
puts " Or visit: https://mise.jdx.dev/getting-started.html"
|
41
|
+
exit 1
|
42
|
+
end
|
43
|
+
|
44
|
+
# Install all tools from mise.toml
|
45
|
+
puts_step "Installing tools from mise.toml"
|
46
|
+
if File.exist?("mise.toml")
|
47
|
+
puts "Installing tools defined in mise.toml..."
|
48
|
+
system!("mise install")
|
49
|
+
|
50
|
+
# Verify Ruby installation
|
51
|
+
current_ruby = `mise exec -- ruby -v`.strip
|
52
|
+
if current_ruby.include?("<%= ruby_version %>")
|
53
|
+
puts_success "Ruby <%= ruby_version %> is ready"
|
54
|
+
else
|
55
|
+
puts_error "Failed to verify Ruby <%= ruby_version %> installation"
|
56
|
+
puts "Expected: <%= ruby_version %>, Got: #{current_ruby}"
|
57
|
+
exit 1
|
58
|
+
end
|
59
|
+
else
|
60
|
+
puts_warning "No mise.toml file found. Creating one with Ruby <%= ruby_version %>"
|
61
|
+
File.write("mise.toml", <<~TOML)
|
62
|
+
[tools]
|
63
|
+
ruby = "<%= ruby_version %>"
|
64
|
+
TOML
|
65
|
+
system!("mise install")
|
66
|
+
end
|
67
|
+
<% end -%>
|
68
|
+
|
69
|
+
<% if container != "none" -%>
|
70
|
+
# Check if Docker is running
|
71
|
+
puts_step "Checking Docker"
|
72
|
+
unless system("docker info > /dev/null 2>&1")
|
73
|
+
puts_error "Docker is not running. Please start Docker first."
|
74
|
+
exit 1
|
75
|
+
end
|
76
|
+
|
77
|
+
<% if container == "docker-compose" -%>
|
78
|
+
# Use Docker Compose setup
|
79
|
+
puts_step "Setting up services with Docker Compose"
|
80
|
+
|
81
|
+
if File.exist?("docker-compose.yml")
|
82
|
+
# Check if database service is running
|
83
|
+
if system("docker compose ps db --status running > /dev/null 2>&1") ||
|
84
|
+
system("docker-compose ps db 2>/dev/null | grep -q Up")
|
85
|
+
puts_success "Database service is already running"
|
86
|
+
else
|
87
|
+
puts "Starting database service..."
|
88
|
+
if system("which docker-compose > /dev/null 2>&1")
|
89
|
+
system!("docker-compose up -d db")
|
90
|
+
else
|
91
|
+
system!("docker compose up -d db")
|
92
|
+
end
|
93
|
+
puts_success "Database service started"
|
94
|
+
end
|
95
|
+
|
96
|
+
# Wait for database to be ready
|
97
|
+
puts "Waiting for database to be ready..."
|
98
|
+
max_attempts = 30
|
99
|
+
attempt = 0
|
100
|
+
|
101
|
+
<% if database == "postgresql" -%>
|
102
|
+
until system("docker compose exec -T db pg_isready -U postgres > /dev/null 2>&1") ||
|
103
|
+
system("docker-compose exec -T db pg_isready -U postgres > /dev/null 2>&1")
|
104
|
+
<% elsif database == "mysql" -%>
|
105
|
+
until system("docker compose exec -T db mysqladmin ping -h localhost -u root -ppassword > /dev/null 2>&1") ||
|
106
|
+
system("docker-compose exec -T db mysqladmin ping -h localhost -u root -ppassword > /dev/null 2>&1")
|
107
|
+
<% end -%>
|
108
|
+
attempt += 1
|
109
|
+
if attempt > max_attempts
|
110
|
+
puts_error "Database failed to start within expected time"
|
111
|
+
exit 1
|
112
|
+
end
|
113
|
+
print "."
|
114
|
+
sleep 1
|
115
|
+
end
|
116
|
+
puts_success "\nDatabase is ready"
|
117
|
+
else
|
118
|
+
puts_warning "No docker-compose.yml found. Please run 'yoker init' first."
|
119
|
+
end
|
120
|
+
|
121
|
+
<% else -%>
|
122
|
+
# Use standalone Docker container
|
123
|
+
puts_step "Setting up <%= database.capitalize %> container"
|
124
|
+
|
125
|
+
container_name = "<%= app_name %>_<%= database %>"
|
126
|
+
|
127
|
+
# Check if container exists
|
128
|
+
if system("docker ps -a --format '{{.Names}}' | grep -q '^#{container_name}$'")
|
129
|
+
puts "Container '#{container_name}' already exists"
|
130
|
+
|
131
|
+
unless system("docker ps --format '{{.Names}}' | grep -q '^#{container_name}$'")
|
132
|
+
puts "Starting existing container..."
|
133
|
+
system!("docker start #{container_name}")
|
134
|
+
end
|
135
|
+
puts_success "Container is running"
|
136
|
+
else
|
137
|
+
puts "Creating and starting <%= database.capitalize %> container..."
|
138
|
+
<% if database == "postgresql" -%>
|
139
|
+
system!(<<~CMD)
|
140
|
+
docker run -d \
|
141
|
+
--name #{container_name} \
|
142
|
+
-e POSTGRES_DB=<%= app_name %>_development \
|
143
|
+
-e POSTGRES_USER=postgres \
|
144
|
+
-e POSTGRES_PASSWORD=password \
|
145
|
+
-p 5432:5432 \
|
146
|
+
-v #{container_name}_data:/var/lib/postgresql/data \
|
147
|
+
postgres:18-alpine
|
148
|
+
CMD
|
149
|
+
<% elsif database == "mysql" -%>
|
150
|
+
system!(<<~CMD)
|
151
|
+
docker run -d \
|
152
|
+
--name #{container_name} \
|
153
|
+
-e MYSQL_ROOT_PASSWORD=password \
|
154
|
+
-e MYSQL_DATABASE=<%= app_name %>_development \
|
155
|
+
-e MYSQL_USER=rails \
|
156
|
+
-e MYSQL_PASSWORD=password \
|
157
|
+
-p 3306:3306 \
|
158
|
+
-v #{container_name}_data:/var/lib/mysql \
|
159
|
+
mysql:8.0
|
160
|
+
CMD
|
161
|
+
<% end -%>
|
162
|
+
puts_success "<%= database.capitalize %> container created and started"
|
163
|
+
end
|
164
|
+
|
165
|
+
# Wait for database
|
166
|
+
puts "Waiting for <%= database %> to be ready..."
|
167
|
+
max_attempts = 30
|
168
|
+
attempt = 0
|
169
|
+
|
170
|
+
<% if database == "postgresql" -%>
|
171
|
+
until system("docker exec #{container_name} pg_isready -U postgres > /dev/null 2>&1")
|
172
|
+
<% elsif database == "mysql" -%>
|
173
|
+
until system("docker exec #{container_name} mysqladmin ping -h localhost -u root -ppassword > /dev/null 2>&1")
|
174
|
+
<% end -%>
|
175
|
+
attempt += 1
|
176
|
+
if attempt > max_attempts
|
177
|
+
puts_error "<%= database.capitalize %> failed to start within expected time"
|
178
|
+
exit 1
|
179
|
+
end
|
180
|
+
print "."
|
181
|
+
sleep 1
|
182
|
+
end
|
183
|
+
puts_success "\n<%= database.capitalize %> is ready"
|
184
|
+
|
185
|
+
<% if database == "postgresql" -%>
|
186
|
+
# Create test database
|
187
|
+
puts "Creating test database..."
|
188
|
+
system("docker exec #{container_name} createdb -U postgres <%= app_name %>_test 2>/dev/null")
|
189
|
+
<% elsif database == "mysql" -%>
|
190
|
+
# Create test database
|
191
|
+
puts "Creating test database..."
|
192
|
+
system("docker exec #{container_name} mysql -u root -ppassword -e 'CREATE DATABASE IF NOT EXISTS <%= app_name %>_test;' 2>/dev/null")
|
193
|
+
<% end -%>
|
194
|
+
<% end -%>
|
195
|
+
<% end -%>
|
196
|
+
|
197
|
+
<% if database != "sqlite3" -%>
|
198
|
+
puts_step "Preparing database"
|
199
|
+
system! "bin/rails db:prepare"
|
200
|
+
<% end -%>
|
201
|
+
|
202
|
+
puts_step "Removing old logs and tempfiles"
|
203
|
+
system! "bin/rails log:clear tmp:clear"
|
204
|
+
|
205
|
+
puts "\n๐ Setup complete!"
|
206
|
+
puts ""
|
207
|
+
puts "Your development environment is ready:"
|
208
|
+
<% if version_manager == "mise" -%>
|
209
|
+
puts "โข Ruby <%= ruby_version %> (managed by mise)"
|
210
|
+
<% end -%>
|
211
|
+
<% if database != "sqlite3" -%>
|
212
|
+
puts "โข <%= database.capitalize %> database"
|
213
|
+
puts "โข Database: <%= app_name %>_development"
|
214
|
+
puts "โข Test database: <%= app_name %>_test"
|
215
|
+
<% end -%>
|
216
|
+
<% if container == "docker-compose" -%>
|
217
|
+
puts "โข Services managed by Docker Compose"
|
218
|
+
puts ""
|
219
|
+
puts "Useful commands:"
|
220
|
+
puts "โข Start all services: docker compose up -d"
|
221
|
+
puts "โข View logs: docker compose logs -f"
|
222
|
+
puts "โข Stop services: docker compose down"
|
223
|
+
<% elsif container == "docker" -%>
|
224
|
+
puts "โข <%= database.capitalize %> running in Docker"
|
225
|
+
puts ""
|
226
|
+
puts "Container management:"
|
227
|
+
puts "โข Stop database: docker stop <%= app_name %>_<%= database %>"
|
228
|
+
puts "โข Start database: docker start <%= app_name %>_<%= database %>"
|
229
|
+
<% end -%>
|
230
|
+
puts ""
|
231
|
+
puts "Start developing: bin/dev"
|
232
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# MySQL database configuration generated by rails-dev-setup
|
2
|
+
#
|
3
|
+
# For more information on how to configure your database, see:
|
4
|
+
# https://guides.rubyonrails.org/configuring.html#configuring-a-database
|
5
|
+
|
6
|
+
default: &default
|
7
|
+
adapter: mysql2
|
8
|
+
encoding: <%= encoding %>
|
9
|
+
username: <%= username %>
|
10
|
+
<% if password && !password.empty? -%>
|
11
|
+
password: <%= password %>
|
12
|
+
<% end -%>
|
13
|
+
host: <%= host %>
|
14
|
+
port: <%= port %>
|
15
|
+
<% if socket -%>
|
16
|
+
socket: <%= socket %>
|
17
|
+
<% end -%>
|
18
|
+
# For details on connection pooling, see Rails configuration guide
|
19
|
+
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
|
20
|
+
# Increase timeout for development (default is 5 seconds)
|
21
|
+
timeout: 10
|
22
|
+
# Enable SQL strict mode for better data integrity
|
23
|
+
strict: true
|
24
|
+
# Reconnect automatically if connection is lost
|
25
|
+
reconnect: true
|
26
|
+
# Set charset for proper Unicode support
|
27
|
+
charset: utf8mb4
|
28
|
+
collation: utf8mb4_unicode_ci
|
29
|
+
|
30
|
+
development:
|
31
|
+
<<: *default
|
32
|
+
database: <%= app_name %>_development
|
33
|
+
|
34
|
+
# Warning: The database defined as "test" will be erased and
|
35
|
+
# re-generated from your development database when you run "rake".
|
36
|
+
# Do not set this db to the same as development or production.
|
37
|
+
test:
|
38
|
+
<<: *default
|
39
|
+
database: <%= app_name %>_test
|
40
|
+
|
41
|
+
# Production database configuration
|
42
|
+
# You should configure the production database URL via environment variable
|
43
|
+
# Example: DATABASE_URL=mysql2://user:pass@host:port/dbname
|
44
|
+
production:
|
45
|
+
url: <%= ENV["DATABASE_URL"] %>
|
46
|
+
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
|
47
|
+
timeout: 5
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# PostgreSQL database configuration generated by yoker
|
2
|
+
#
|
3
|
+
# For more information on how to configure your database, see:
|
4
|
+
# https://guides.rubyonrails.org/configuring.html#configuring-a-database
|
5
|
+
|
6
|
+
default: &default
|
7
|
+
adapter: postgresql
|
8
|
+
encoding: unicode
|
9
|
+
username: <%= username %>
|
10
|
+
<% if password && !password.empty? -%>
|
11
|
+
password: <%= password %>
|
12
|
+
<% end -%>
|
13
|
+
host: <%= host %>
|
14
|
+
port: <%= port %>
|
15
|
+
# For details on connection pooling, see Rails configuration guide
|
16
|
+
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
|
17
|
+
|
18
|
+
development:
|
19
|
+
<<: *default
|
20
|
+
database: <%= app_name %>_development
|
21
|
+
|
22
|
+
# Warning: The database defined as "test" will be erased and
|
23
|
+
# re-generated from your development database when you run "rake".
|
24
|
+
# Do not set this db to the same as development or production.
|
25
|
+
test:
|
26
|
+
<<: *default
|
27
|
+
database: <%= app_name %>_test
|
28
|
+
|
29
|
+
# Production database configuration
|
30
|
+
# You should configure the production database URL via environment variable
|
31
|
+
# Example: DATABASE_URL=postgresql://user:pass@host:port/dbname
|
32
|
+
production:
|
33
|
+
url: <%= ENV["DATABASE_URL"] %>
|
34
|
+
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# SQLite database configuration generated by rails-dev-setup
|
2
|
+
#
|
3
|
+
# SQLite is ideal for development and testing but consider PostgreSQL or MySQL for production.
|
4
|
+
# For more information: https://guides.rubyonrails.org/configuring.html#configuring-a-database
|
5
|
+
|
6
|
+
default: &default
|
7
|
+
adapter: sqlite3
|
8
|
+
pool: <%= pool_size %>
|
9
|
+
timeout: <%= timeout %>
|
10
|
+
# Enable foreign key constraints
|
11
|
+
foreign_keys: true
|
12
|
+
|
13
|
+
development:
|
14
|
+
<<: *default
|
15
|
+
database: <%= database_path %>
|
16
|
+
# SQLite pragma settings for development performance
|
17
|
+
<% pragmas.each do |pragma, value| -%>
|
18
|
+
pragma:
|
19
|
+
<%= pragma %>: <%= value || '""' %>
|
20
|
+
<% end -%>
|
21
|
+
|
22
|
+
# Warning: The database defined as "test" will be erased and
|
23
|
+
# re-generated from your development database when you run "rake".
|
24
|
+
# Do not set this db to the same as development or production.
|
25
|
+
test:
|
26
|
+
<<: *default
|
27
|
+
database: db/<%= app_name %>_test.sqlite3
|
28
|
+
# Test-specific pragmas for speed
|
29
|
+
pragma:
|
30
|
+
journal_mode: memory
|
31
|
+
synchronous: "OFF"
|
32
|
+
cache_size: -64000
|
33
|
+
temp_store: memory
|
34
|
+
|
35
|
+
# SQLite is not recommended for production use
|
36
|
+
# Consider PostgreSQL or MySQL for production deployments
|
37
|
+
production:
|
38
|
+
url: <%= ENV["DATABASE_URL"] %>
|
39
|
+
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
|
40
|
+
timeout: 5000
|
@@ -0,0 +1,124 @@
|
|
1
|
+
# Rails Development Environment Dockerfile
|
2
|
+
# Generated by rails-dev-setup
|
3
|
+
#
|
4
|
+
# This Dockerfile is optimized for development with:
|
5
|
+
# - Ruby <%= ruby_version %>
|
6
|
+
<% if version_manager == "mise" -%>
|
7
|
+
# - mise for tool version management
|
8
|
+
<% end -%>
|
9
|
+
# - <%= database.capitalize %> database support
|
10
|
+
# - Fast rebuilds with layer caching
|
11
|
+
|
12
|
+
FROM ruby:<%= ruby_version %>-alpine
|
13
|
+
|
14
|
+
# Install system dependencies
|
15
|
+
RUN apk add --no-cache \
|
16
|
+
<%= additional_packages.join(" \\\n ") %>
|
17
|
+
|
18
|
+
<% if version_manager == "mise" -%>
|
19
|
+
# Install mise for tool version management
|
20
|
+
RUN curl https://mise.run | sh
|
21
|
+
ENV PATH="/root/.local/bin:$PATH"
|
22
|
+
|
23
|
+
<% end -%>
|
24
|
+
# Set working directory
|
25
|
+
WORKDIR /rails
|
26
|
+
|
27
|
+
# Create rails user for security (optional, commented out for dev ease)
|
28
|
+
# RUN addgroup -g 1000 -S rails && \
|
29
|
+
# adduser -u 1000 -S rails -G rails
|
30
|
+
# USER rails
|
31
|
+
|
32
|
+
<% if version_manager == "mise" -%>
|
33
|
+
# Copy mise configuration first (for better caching)
|
34
|
+
COPY mise.toml ./
|
35
|
+
COPY .mise.local.toml* ./
|
36
|
+
|
37
|
+
# Install tools via mise (if any beyond Ruby)
|
38
|
+
RUN mise install 2>/dev/null || true
|
39
|
+
|
40
|
+
<% end -%>
|
41
|
+
# Copy Gemfile and Gemfile.lock first (for better Docker layer caching)
|
42
|
+
COPY Gemfile Gemfile.lock ./
|
43
|
+
|
44
|
+
# Configure bundler and install gems
|
45
|
+
ENV BUNDLE_PATH="/usr/local/bundle" \
|
46
|
+
BUNDLE_WITHOUT="production"
|
47
|
+
|
48
|
+
RUN bundle config --global frozen 1 && \
|
49
|
+
bundle install && \
|
50
|
+
bundle clean --force && \
|
51
|
+
rm -rf ~/.bundle/ "${BUNDLE_PATH}"/ruby/*/cache "${BUNDLE_PATH}"/ruby/*/bundler/gems/*/.git
|
52
|
+
|
53
|
+
<% if database == "postgresql" -%>
|
54
|
+
# Install PostgreSQL client tools
|
55
|
+
RUN apk add --no-cache postgresql-client
|
56
|
+
|
57
|
+
<% elsif database == "mysql" -%>
|
58
|
+
# Install MySQL client tools
|
59
|
+
RUN apk add --no-cache mysql-client
|
60
|
+
|
61
|
+
<% end -%>
|
62
|
+
# Copy application code
|
63
|
+
COPY . .
|
64
|
+
|
65
|
+
<% if File.exist?("package.json") -%>
|
66
|
+
# Install Node.js dependencies if package.json exists
|
67
|
+
RUN if [ -f package.json ]; then npm install; fi
|
68
|
+
|
69
|
+
<% end -%>
|
70
|
+
# Precompile bootsnap cache for faster boot times
|
71
|
+
RUN bundle exec bootsnap precompile --gemfile app/ lib/
|
72
|
+
|
73
|
+
# Create directories that Rails expects
|
74
|
+
RUN mkdir -p tmp/pids tmp/cache tmp/sockets log
|
75
|
+
|
76
|
+
<% if additional_services&.include?("sidekiq") -%>
|
77
|
+
# Create directory for Sidekiq
|
78
|
+
RUN mkdir -p tmp/sidekiq
|
79
|
+
|
80
|
+
<% end -%>
|
81
|
+
# Set Rails environment
|
82
|
+
ENV RAILS_ENV="development" \
|
83
|
+
BUNDLE_WITHOUT="production"
|
84
|
+
|
85
|
+
<% if database != "sqlite3" -%>
|
86
|
+
# Database configuration
|
87
|
+
<% if database == "postgresql" -%>
|
88
|
+
ENV DATABASE_URL="postgresql://postgres:password@db:5432/<%= app_name %>_development"
|
89
|
+
<% elsif database == "mysql" -%>
|
90
|
+
ENV DATABASE_URL="mysql2://rails:password@db:3306/<%= app_name %>_development"
|
91
|
+
<% end -%>
|
92
|
+
|
93
|
+
<% end -%>
|
94
|
+
<% if additional_services&.include?("redis") -%>
|
95
|
+
# Redis configuration
|
96
|
+
ENV REDIS_URL="redis://redis:6379/0"
|
97
|
+
|
98
|
+
<% end -%>
|
99
|
+
# Expose port 3000 for the Rails server
|
100
|
+
EXPOSE 3000
|
101
|
+
|
102
|
+
<% if needs_custom_entrypoint? -%>
|
103
|
+
# Copy and set up entrypoint script
|
104
|
+
COPY docker/entrypoint.sh /usr/local/bin/
|
105
|
+
RUN chmod +x /usr/local/bin/entrypoint.sh
|
106
|
+
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
|
107
|
+
|
108
|
+
<% end -%>
|
109
|
+
# Default command
|
110
|
+
CMD ["bundle", "exec", "rails", "server", "-b", "0.0.0.0"]
|
111
|
+
|
112
|
+
# Health check for the Rails application
|
113
|
+
HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
|
114
|
+
CMD curl -f http://localhost:3000/health || curl -f http://localhost:3000/ || exit 1
|
115
|
+
|
116
|
+
# Labels for better container management
|
117
|
+
LABEL maintainer="rails-dev-setup" \
|
118
|
+
description="Rails <%= app_name %> development environment" \
|
119
|
+
ruby.version="<%= ruby_version %>" \
|
120
|
+
database="<%= database %>" \
|
121
|
+
<% if version_manager != "none" -%>
|
122
|
+
version.manager="<%= version_manager %>" \
|
123
|
+
<% end -%>
|
124
|
+
rails.env="development"
|
@@ -0,0 +1,117 @@
|
|
1
|
+
services:
|
2
|
+
db:
|
3
|
+
<% if database == "postgresql" -%>
|
4
|
+
image: postgres:18-alpine
|
5
|
+
environment:
|
6
|
+
POSTGRES_DB: <%= app_name %>_development
|
7
|
+
POSTGRES_USER: postgres
|
8
|
+
POSTGRES_PASSWORD: password
|
9
|
+
ports:
|
10
|
+
- "5432:5432"
|
11
|
+
volumes:
|
12
|
+
- postgres_data:/var/lib/postgresql/data
|
13
|
+
- ./docker/init.sql:/docker-entrypoint-initdb.d/init.sql:ro
|
14
|
+
healthcheck:
|
15
|
+
test: ["CMD-SHELL", "pg_isready -U postgres"]
|
16
|
+
interval: 10s
|
17
|
+
timeout: 5s
|
18
|
+
retries: 5
|
19
|
+
<% elsif database == "mysql" -%>
|
20
|
+
image: mysql:8.0
|
21
|
+
environment:
|
22
|
+
MYSQL_ROOT_PASSWORD: password
|
23
|
+
MYSQL_DATABASE: <%= app_name %>_development
|
24
|
+
MYSQL_USER: rails
|
25
|
+
MYSQL_PASSWORD: password
|
26
|
+
ports:
|
27
|
+
- "3306:3306"
|
28
|
+
volumes:
|
29
|
+
- mysql_data:/var/lib/mysql
|
30
|
+
healthcheck:
|
31
|
+
test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-u", "root", "-ppassword"]
|
32
|
+
interval: 10s
|
33
|
+
timeout: 5s
|
34
|
+
retries: 5
|
35
|
+
<% end -%>
|
36
|
+
|
37
|
+
web:
|
38
|
+
build: .
|
39
|
+
command: bash -c "rm -f tmp/pids/server.pid && bundle exec rails s -b '0.0.0.0'"
|
40
|
+
volumes:
|
41
|
+
- .:/rails
|
42
|
+
- gem_cache:/usr/local/bundle
|
43
|
+
ports:
|
44
|
+
- "3000:3000"
|
45
|
+
depends_on:
|
46
|
+
db:
|
47
|
+
condition: service_healthy
|
48
|
+
<% if additional_services&.include?("redis") -%>
|
49
|
+
redis:
|
50
|
+
condition: service_started
|
51
|
+
<% end -%>
|
52
|
+
environment:
|
53
|
+
<% if database == "postgresql" -%>
|
54
|
+
DATABASE_URL: postgresql://postgres:password@db:5432/<%= app_name %>_development
|
55
|
+
<% elsif database == "mysql" -%>
|
56
|
+
DATABASE_URL: mysql2://rails:password@db:3306/<%= app_name %>_development
|
57
|
+
<% end -%>
|
58
|
+
RAILS_ENV: development
|
59
|
+
<% if additional_services&.include?("redis") -%>
|
60
|
+
REDIS_URL: redis://redis:6379/0
|
61
|
+
<% end -%>
|
62
|
+
<% if additional_services&.include?("mailcatcher") -%>
|
63
|
+
SMTP_HOST: mailcatcher
|
64
|
+
SMTP_PORT: 1025
|
65
|
+
<% end -%>
|
66
|
+
stdin_open: true
|
67
|
+
tty: true
|
68
|
+
|
69
|
+
<% if additional_services&.include?("redis") -%>
|
70
|
+
redis:
|
71
|
+
image: redis:7-alpine
|
72
|
+
ports:
|
73
|
+
- "6379:6379"
|
74
|
+
volumes:
|
75
|
+
- redis_data:/data
|
76
|
+
|
77
|
+
<% end -%>
|
78
|
+
<% if additional_services&.include?("sidekiq") -%>
|
79
|
+
sidekiq:
|
80
|
+
build: .
|
81
|
+
command: bundle exec sidekiq
|
82
|
+
volumes:
|
83
|
+
- .:/rails
|
84
|
+
- gem_cache:/usr/local/bundle
|
85
|
+
depends_on:
|
86
|
+
db:
|
87
|
+
condition: service_healthy
|
88
|
+
redis:
|
89
|
+
condition: service_started
|
90
|
+
environment:
|
91
|
+
<% if database == "postgresql" -%>
|
92
|
+
DATABASE_URL: postgresql://postgres:password@db:5432/<%= app_name %>_development
|
93
|
+
<% elsif database == "mysql" -%>
|
94
|
+
DATABASE_URL: mysql2://rails:password@db:3306/<%= app_name %>_development
|
95
|
+
<% end -%>
|
96
|
+
REDIS_URL: redis://redis:6379/0
|
97
|
+
RAILS_ENV: development
|
98
|
+
|
99
|
+
<% end -%>
|
100
|
+
<% if additional_services&.include?("mailcatcher") -%>
|
101
|
+
mailcatcher:
|
102
|
+
image: schickling/mailcatcher
|
103
|
+
ports:
|
104
|
+
- "1080:1080"
|
105
|
+
- "1025:1025"
|
106
|
+
|
107
|
+
<% end -%>
|
108
|
+
volumes:
|
109
|
+
gem_cache:
|
110
|
+
<% if database == "postgresql" -%>
|
111
|
+
postgres_data:
|
112
|
+
<% elsif database == "mysql" -%>
|
113
|
+
mysql_data:
|
114
|
+
<% end -%>
|
115
|
+
<% if additional_services&.include?("redis") -%>
|
116
|
+
redis_data:
|
117
|
+
<% end -%>
|
@@ -0,0 +1,94 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
# Rails Development Entrypoint Script
|
3
|
+
# Generated by rails-dev-setup
|
4
|
+
|
5
|
+
set -e
|
6
|
+
|
7
|
+
# Colors for output
|
8
|
+
RED='\033[0;31m'
|
9
|
+
GREEN='\033[0;32m'
|
10
|
+
YELLOW='\033[1;33m'
|
11
|
+
NC='\033[0m' # No Color
|
12
|
+
|
13
|
+
echo -e "${GREEN}๐ Starting Rails development environment${NC}"
|
14
|
+
|
15
|
+
<% if database != "sqlite3" -%>
|
16
|
+
# Wait for database to be ready
|
17
|
+
echo -e "${YELLOW}โณ Waiting for <%= database %> database...${NC}"
|
18
|
+
|
19
|
+
<% if database == "postgresql" -%>
|
20
|
+
while ! pg_isready -h db -p 5432 -U postgres; do
|
21
|
+
echo "Waiting for PostgreSQL..."
|
22
|
+
sleep 2
|
23
|
+
done
|
24
|
+
<% elsif database == "mysql" -%>
|
25
|
+
while ! mysqladmin ping -h db -P 3306 -u rails -ppassword --silent; do
|
26
|
+
echo "Waiting for MySQL..."
|
27
|
+
sleep 2
|
28
|
+
done
|
29
|
+
<% end -%>
|
30
|
+
|
31
|
+
echo -e "${GREEN}โ
Database is ready${NC}"
|
32
|
+
|
33
|
+
<% end -%>
|
34
|
+
<% if additional_services&.include?("redis") -%>
|
35
|
+
# Wait for Redis to be ready
|
36
|
+
echo -e "${YELLOW}โณ Waiting for Redis...${NC}"
|
37
|
+
while ! redis-cli -h redis -p 6379 ping > /dev/null 2>&1; do
|
38
|
+
echo "Waiting for Redis..."
|
39
|
+
sleep 2
|
40
|
+
done
|
41
|
+
echo -e "${GREEN}โ
Redis is ready${NC}"
|
42
|
+
|
43
|
+
<% end -%>
|
44
|
+
# Remove any existing server.pid file
|
45
|
+
if [ -f tmp/pids/server.pid ]; then
|
46
|
+
echo -e "${YELLOW}๐งน Removing stale server.pid${NC}"
|
47
|
+
rm tmp/pids/server.pid
|
48
|
+
fi
|
49
|
+
|
50
|
+
<% if database != "sqlite3" -%>
|
51
|
+
# Setup database if needed
|
52
|
+
echo -e "${YELLOW}๐๏ธ Setting up database...${NC}"
|
53
|
+
|
54
|
+
# Check if database exists, create if not
|
55
|
+
bundle exec rails db:prepare 2>/dev/null || {
|
56
|
+
echo -e "${YELLOW}๐ฆ Database not found, creating...${NC}"
|
57
|
+
bundle exec rails db:setup
|
58
|
+
}
|
59
|
+
|
60
|
+
# Run pending migrations
|
61
|
+
if bundle exec rails db:migrate:status | grep -q "down"; then
|
62
|
+
echo -e "${YELLOW}๐ Running pending migrations...${NC}"
|
63
|
+
bundle exec rails db:migrate
|
64
|
+
fi
|
65
|
+
|
66
|
+
<% end -%>
|
67
|
+
<% if additional_services&.include?("sidekiq") -%>
|
68
|
+
# Start Sidekiq in the background if this is the sidekiq container
|
69
|
+
if [ "$1" = "sidekiq" ] || [ "$1" = "bundle" ] && [ "$2" = "exec" ] && [ "$3" = "sidekiq" ]; then
|
70
|
+
echo -e "${GREEN}๐ Starting Sidekiq background jobs${NC}"
|
71
|
+
exec "$@"
|
72
|
+
fi
|
73
|
+
|
74
|
+
<% end -%>
|
75
|
+
# Install any new gems (in case Gemfile changed)
|
76
|
+
echo -e "${YELLOW}๐ Checking for new gems...${NC}"
|
77
|
+
bundle check || bundle install
|
78
|
+
|
79
|
+
<% if File.exist?("package.json") -%>
|
80
|
+
# Install any new npm packages (in case package.json changed)
|
81
|
+
if [ -f package.json ]; then
|
82
|
+
echo -e "${YELLOW}๐ฆ Checking for new npm packages...${NC}"
|
83
|
+
npm install
|
84
|
+
fi
|
85
|
+
|
86
|
+
<% end -%>
|
87
|
+
# Precompile assets in development (optional, can be commented out)
|
88
|
+
# echo -e "${YELLOW}๐จ Precompiling assets...${NC}"
|
89
|
+
# bundle exec rails assets:precompile
|
90
|
+
|
91
|
+
echo -e "${GREEN}๐ Environment ready!${NC}"
|
92
|
+
|
93
|
+
# Execute the main command
|
94
|
+
exec "$@"
|