rails_claude_skills 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/.github/ISSUE_TEMPLATE/bug_report.yml +134 -0
- data/.github/ISSUE_TEMPLATE/config.yml +11 -0
- data/.github/ISSUE_TEMPLATE/feature_request.yml +129 -0
- data/.github/ISSUE_TEMPLATE/question.yml +90 -0
- data/.github/dependabot.yml +19 -0
- data/.github/workflows/ci.yml +77 -0
- data/.github/workflows/release.yml +66 -0
- data/.rubocop.yml +52 -0
- data/CHANGELOG.md +94 -0
- data/CLAUDE.md +332 -0
- data/CODE_OF_CONDUCT.md +134 -0
- data/CONTRIBUTING.md +580 -0
- data/LICENSE.txt +21 -0
- data/README.md +544 -0
- data/Rakefile +8 -0
- data/lib/generators/claude/agent/agent_generator.rb +71 -0
- data/lib/generators/claude/agent/templates/agent.md.tt +62 -0
- data/lib/generators/claude/command/command_generator.rb +50 -0
- data/lib/generators/claude/command/templates/command.md.tt +28 -0
- data/lib/generators/claude/commands_library/create-pr.md +27 -0
- data/lib/generators/claude/commands_library/dbchange.md +19 -0
- data/lib/generators/claude/commands_library/quality.md +20 -0
- data/lib/generators/claude/commands_library/stimulus.md +19 -0
- data/lib/generators/claude/commands_library/turbo-feature.md +17 -0
- data/lib/generators/claude/install/install_generator.rb +211 -0
- data/lib/generators/claude/install/templates/README.md.tt +59 -0
- data/lib/generators/claude/install/templates/USAGE +28 -0
- data/lib/generators/claude/install/templates/agents/api-dev.md.tt +46 -0
- data/lib/generators/claude/install/templates/agents/fullstack-dev.md.tt +48 -0
- data/lib/generators/claude/install/templates/agents/rails-developer.md.tt +40 -0
- data/lib/generators/claude/install/templates/settings.local.json.tt +13 -0
- data/lib/generators/claude/rule/rule_generator.rb +175 -0
- data/lib/generators/claude/rule/templates/rule.md.tt +7 -0
- data/lib/generators/claude/rules_library/code-style.md +37 -0
- data/lib/generators/claude/rules_library/database.md +47 -0
- data/lib/generators/claude/rules_library/hotwire.md +56 -0
- data/lib/generators/claude/rules_library/security.md +54 -0
- data/lib/generators/claude/rules_library/testing.md +47 -0
- data/lib/generators/claude/skill/skill_generator.rb +196 -0
- data/lib/generators/claude/skill/templates/SKILL.md.tt +27 -0
- data/lib/generators/claude/skills_library/create-task-files/SKILL.md +311 -0
- data/lib/generators/claude/skills_library/create-task-files/templates/bug.md +60 -0
- data/lib/generators/claude/skills_library/create-task-files/templates/epic.md +47 -0
- data/lib/generators/claude/skills_library/create-task-files/templates/issue.md +45 -0
- data/lib/generators/claude/skills_library/create-task-files/templates/user-story.md +57 -0
- data/lib/generators/claude/skills_library/minitest-testing/SKILL.md +398 -0
- data/lib/generators/claude/skills_library/minitest-testing/references/examples.md +889 -0
- data/lib/generators/claude/skills_library/plan-feature/SKILL.md +253 -0
- data/lib/generators/claude/skills_library/rails-api-controllers/SKILL.md +1041 -0
- data/lib/generators/claude/skills_library/rails-api-controllers/references/api-documentation.md +422 -0
- data/lib/generators/claude/skills_library/rails-api-controllers/references/serialization.md +456 -0
- data/lib/generators/claude/skills_library/rails-auth-with-devise/SKILL.md +191 -0
- data/lib/generators/claude/skills_library/rails-auth-with-devise/references/advanced.md +331 -0
- data/lib/generators/claude/skills_library/rails-auth-with-devise/references/api-auth.md +266 -0
- data/lib/generators/claude/skills_library/rails-auth-with-devise/references/omniauth.md +194 -0
- data/lib/generators/claude/skills_library/rails-authorization-cancancan/SKILL.md +603 -0
- data/lib/generators/claude/skills_library/rails-authorization-cancancan/references/api-authorization.md +543 -0
- data/lib/generators/claude/skills_library/rails-authorization-cancancan/references/complex-permissions.md +572 -0
- data/lib/generators/claude/skills_library/rails-authorization-cancancan/references/multi-tenancy.md +373 -0
- data/lib/generators/claude/skills_library/rails-controllers/SKILL.md +514 -0
- data/lib/generators/claude/skills_library/rails-debugging/SKILL.md +260 -0
- data/lib/generators/claude/skills_library/rails-deployment/SKILL.md +437 -0
- data/lib/generators/claude/skills_library/rails-deployment/references/examples.md +901 -0
- data/lib/generators/claude/skills_library/rails-hotwire/SKILL.md +367 -0
- data/lib/generators/claude/skills_library/rails-jobs/MISSION_CONTROL_SETUP.md +639 -0
- data/lib/generators/claude/skills_library/rails-jobs/SKILL.md +704 -0
- data/lib/generators/claude/skills_library/rails-mailers/SKILL.md +549 -0
- data/lib/generators/claude/skills_library/rails-models/SKILL.md +379 -0
- data/lib/generators/claude/skills_library/rails-pagination-kaminari/SKILL.md +622 -0
- data/lib/generators/claude/skills_library/rails-pagination-kaminari/references/api-pagination.md +523 -0
- data/lib/generators/claude/skills_library/rails-pagination-kaminari/references/custom-themes.md +498 -0
- data/lib/generators/claude/skills_library/rails-pagination-kaminari/references/performance.md +478 -0
- data/lib/generators/claude/skills_library/rails-views/SKILL.md +508 -0
- data/lib/generators/claude/skills_library/refine-requirements/SKILL.md +226 -0
- data/lib/generators/claude/skills_library/refine-requirements/references/examples.md +344 -0
- data/lib/generators/claude/skills_library/refine-requirements/references/reference.md +298 -0
- data/lib/generators/claude/skills_library/rspec-testing/SKILL.md +572 -0
- data/lib/generators/claude/skills_library/rspec-testing/references/better_specs_guide.md +273 -0
- data/lib/generators/claude/skills_library/rspec-testing/references/thoughtbot_patterns.md +407 -0
- data/lib/generators/claude/skills_library/tailwindcss/SKILL.md +371 -0
- data/lib/generators/claude/views/views_generator.rb +113 -0
- data/lib/rails_claude_skills/railtie.rb +16 -0
- data/lib/rails_claude_skills/version.rb +5 -0
- data/lib/rails_claude_skills.rb +27 -0
- data/sig/rails_claude_skills.rbs +4 -0
- metadata +199 -0
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: rails-debugging
|
|
3
|
+
description: Use when debugging Rails issues - provides Rails-specific debugging tools (logs, console, byebug, SQL logging) integrated with systematic debugging process
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Rails Debugging Tools & Techniques
|
|
7
|
+
|
|
8
|
+
<superpowers-integration>
|
|
9
|
+
**REQUIRED BACKGROUND:** Use superpowers:systematic-debugging for investigation process
|
|
10
|
+
- That skill defines 4-phase framework (Root Cause → Pattern → Hypothesis → Implementation)
|
|
11
|
+
- This skill provides Rails-specific debugging tools for each phase
|
|
12
|
+
</superpowers-integration>
|
|
13
|
+
|
|
14
|
+
<when-to-use>
|
|
15
|
+
- Rails application behaving unexpectedly
|
|
16
|
+
- Tests failing with unclear errors
|
|
17
|
+
- Performance issues or N+1 queries
|
|
18
|
+
- Production errors need investigation
|
|
19
|
+
</when-to-use>
|
|
20
|
+
|
|
21
|
+
<verification-checklist>
|
|
22
|
+
Before completing debugging work:
|
|
23
|
+
- ✅ Root cause identified (not just symptoms)
|
|
24
|
+
- ✅ Regression test added (prevents recurrence)
|
|
25
|
+
- ✅ Fix verified in development and test environments
|
|
26
|
+
- ✅ All tests passing (bin/ci passes)
|
|
27
|
+
- ✅ Logs reviewed for related issues
|
|
28
|
+
- ✅ Performance impact verified (if applicable)
|
|
29
|
+
</verification-checklist>
|
|
30
|
+
|
|
31
|
+
<phase1-root-cause-investigation>
|
|
32
|
+
|
|
33
|
+
<tool name="rails-logs">
|
|
34
|
+
<description>Check Rails logs for errors and request traces</description>
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
# Development logs
|
|
38
|
+
tail -f log/development.log
|
|
39
|
+
|
|
40
|
+
# Production logs (Kamal)
|
|
41
|
+
kamal app logs --tail
|
|
42
|
+
|
|
43
|
+
# Filter by severity
|
|
44
|
+
grep ERROR log/production.log
|
|
45
|
+
|
|
46
|
+
# Filter by request
|
|
47
|
+
grep "Started GET" log/development.log
|
|
48
|
+
|
|
49
|
+
```
|
|
50
|
+
</tool>
|
|
51
|
+
|
|
52
|
+
<tool name="rails-console">
|
|
53
|
+
<description>Interactive Rails console for testing models/queries</description>
|
|
54
|
+
|
|
55
|
+
```ruby
|
|
56
|
+
# Start console
|
|
57
|
+
rails console
|
|
58
|
+
|
|
59
|
+
# Or production console (Kamal)
|
|
60
|
+
kamal app exec 'bin/rails console'
|
|
61
|
+
|
|
62
|
+
# Test models
|
|
63
|
+
user = User.find(1)
|
|
64
|
+
user.valid? # Check validations
|
|
65
|
+
user.errors.full_messages # See errors
|
|
66
|
+
|
|
67
|
+
# Test queries
|
|
68
|
+
User.where(email: "test@example.com").to_sql # See SQL
|
|
69
|
+
User.includes(:posts).where(posts: { published: true }) # Avoid N+1
|
|
70
|
+
|
|
71
|
+
```
|
|
72
|
+
</tool>
|
|
73
|
+
|
|
74
|
+
<tool name="byebug">
|
|
75
|
+
<description>Breakpoint debugger for stepping through code</description>
|
|
76
|
+
|
|
77
|
+
```ruby
|
|
78
|
+
# Add to any Rails file
|
|
79
|
+
def some_method
|
|
80
|
+
byebug # Execution stops here
|
|
81
|
+
# ... rest of method
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
# Byebug commands:
|
|
85
|
+
# n - next line
|
|
86
|
+
# s - step into method
|
|
87
|
+
# c - continue execution
|
|
88
|
+
# pp variable - pretty print
|
|
89
|
+
# var local - show local variables
|
|
90
|
+
# exit - quit debugger
|
|
91
|
+
|
|
92
|
+
```
|
|
93
|
+
</tool>
|
|
94
|
+
|
|
95
|
+
<tool name="sql-logging">
|
|
96
|
+
<description>Enable verbose SQL logging to see queries</description>
|
|
97
|
+
|
|
98
|
+
```ruby
|
|
99
|
+
# In rails console or code
|
|
100
|
+
ActiveRecord::Base.logger = Logger.new(STDOUT)
|
|
101
|
+
|
|
102
|
+
# Now all SQL queries print to console
|
|
103
|
+
User.all
|
|
104
|
+
# => SELECT "users".* FROM "users"
|
|
105
|
+
|
|
106
|
+
```
|
|
107
|
+
</tool>
|
|
108
|
+
|
|
109
|
+
</phase1-root-cause-investigation>
|
|
110
|
+
|
|
111
|
+
<phase2-pattern-analysis>
|
|
112
|
+
|
|
113
|
+
<tool name="rails-routes">
|
|
114
|
+
<description>Check route definitions and paths</description>
|
|
115
|
+
|
|
116
|
+
```bash
|
|
117
|
+
# List all routes
|
|
118
|
+
rails routes
|
|
119
|
+
|
|
120
|
+
# Filter routes
|
|
121
|
+
rails routes | grep users
|
|
122
|
+
|
|
123
|
+
# Show routes for controller
|
|
124
|
+
rails routes -c users
|
|
125
|
+
|
|
126
|
+
```
|
|
127
|
+
</tool>
|
|
128
|
+
|
|
129
|
+
<tool name="rails-db-status">
|
|
130
|
+
<description>Check migration status and schema</description>
|
|
131
|
+
|
|
132
|
+
```bash
|
|
133
|
+
# Migration status
|
|
134
|
+
rails db:migrate:status
|
|
135
|
+
|
|
136
|
+
# Show schema version
|
|
137
|
+
rails db:version
|
|
138
|
+
|
|
139
|
+
# Check pending migrations
|
|
140
|
+
rails db:abort_if_pending_migrations
|
|
141
|
+
|
|
142
|
+
```
|
|
143
|
+
</tool>
|
|
144
|
+
|
|
145
|
+
</phase2-pattern-analysis>
|
|
146
|
+
|
|
147
|
+
<phase3-hypothesis-testing>
|
|
148
|
+
|
|
149
|
+
<tool name="rails-runner">
|
|
150
|
+
<description>Run Ruby code in Rails environment</description>
|
|
151
|
+
|
|
152
|
+
```bash
|
|
153
|
+
# Run one-liner
|
|
154
|
+
rails runner "puts User.count"
|
|
155
|
+
|
|
156
|
+
# Run script
|
|
157
|
+
rails runner scripts/investigate_users.rb
|
|
158
|
+
|
|
159
|
+
# Production environment
|
|
160
|
+
RAILS_ENV=production rails runner "User.pluck(:email)"
|
|
161
|
+
|
|
162
|
+
```
|
|
163
|
+
</tool>
|
|
164
|
+
|
|
165
|
+
</phase3-hypothesis-testing>
|
|
166
|
+
|
|
167
|
+
<phase4-implementation>
|
|
168
|
+
|
|
169
|
+
<tool name="rails-test-verbose">
|
|
170
|
+
<description>Run tests with detailed output</description>
|
|
171
|
+
|
|
172
|
+
```bash
|
|
173
|
+
# Run single test with backtrace
|
|
174
|
+
rails test test/models/user_test.rb --verbose
|
|
175
|
+
|
|
176
|
+
# Run with warnings enabled
|
|
177
|
+
RUBYOPT=-W rails test
|
|
178
|
+
|
|
179
|
+
# Run with seed for reproducibility
|
|
180
|
+
rails test --seed 12345
|
|
181
|
+
|
|
182
|
+
```
|
|
183
|
+
</tool>
|
|
184
|
+
|
|
185
|
+
</phase4-implementation>
|
|
186
|
+
|
|
187
|
+
<common-issues>
|
|
188
|
+
|
|
189
|
+
<issue name="n-plus-one-queries">
|
|
190
|
+
<detection>
|
|
191
|
+
Check logs for many similar queries:
|
|
192
|
+
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
User Load (0.1ms) SELECT * FROM users WHERE id = 1
|
|
196
|
+
Post Load (0.1ms) SELECT * FROM posts WHERE user_id = 1
|
|
197
|
+
Post Load (0.1ms) SELECT * FROM posts WHERE user_id = 2
|
|
198
|
+
Post Load (0.1ms) SELECT * FROM posts WHERE user_id = 3
|
|
199
|
+
|
|
200
|
+
```
|
|
201
|
+
</detection>
|
|
202
|
+
<solution>
|
|
203
|
+
Use includes/preload:
|
|
204
|
+
|
|
205
|
+
```ruby
|
|
206
|
+
# Bad
|
|
207
|
+
users.each { |user| user.posts.count }
|
|
208
|
+
|
|
209
|
+
# Good
|
|
210
|
+
users.includes(:posts).each { |user| user.posts.count }
|
|
211
|
+
|
|
212
|
+
```
|
|
213
|
+
</solution>
|
|
214
|
+
</issue>
|
|
215
|
+
|
|
216
|
+
<issue name="missing-migration">
|
|
217
|
+
<detection>
|
|
218
|
+
Error: "ActiveRecord::StatementInvalid: no such column"
|
|
219
|
+
</detection>
|
|
220
|
+
<solution>
|
|
221
|
+
|
|
222
|
+
```bash
|
|
223
|
+
# Check migration status
|
|
224
|
+
rails db:migrate:status
|
|
225
|
+
|
|
226
|
+
# Run pending migrations
|
|
227
|
+
rails db:migrate
|
|
228
|
+
|
|
229
|
+
# Or rollback and retry
|
|
230
|
+
rails db:rollback
|
|
231
|
+
rails db:migrate
|
|
232
|
+
|
|
233
|
+
```
|
|
234
|
+
</solution>
|
|
235
|
+
</issue>
|
|
236
|
+
|
|
237
|
+
</common-issues>
|
|
238
|
+
|
|
239
|
+
<related-skills>
|
|
240
|
+
- superpowers:systematic-debugging (4-phase framework)
|
|
241
|
+
- rails-ai:models (Query optimization, N+1 debugging)
|
|
242
|
+
- rails-ai:controllers (Request debugging, parameter inspection)
|
|
243
|
+
- rails-ai:testing (Test debugging, failure investigation)
|
|
244
|
+
</related-skills>
|
|
245
|
+
|
|
246
|
+
<resources>
|
|
247
|
+
|
|
248
|
+
**Official Documentation:**
|
|
249
|
+
- [Rails Guides - Debugging Rails Applications](https://guides.rubyonrails.org/debugging_rails_applications.html)
|
|
250
|
+
- [Rails API - ActiveSupport::Logger](https://api.rubyonrails.org/classes/ActiveSupport/Logger.html)
|
|
251
|
+
- [Ruby Debugging Guide](https://ruby-doc.org/stdlib-3.0.0/libdoc/debug/rdoc/index.html)
|
|
252
|
+
|
|
253
|
+
**Gems & Libraries:**
|
|
254
|
+
- [byebug](https://github.com/deivid-rodriguez/byebug) - Ruby debugger
|
|
255
|
+
- [bullet](https://github.com/flyerhzm/bullet) - N+1 query detection
|
|
256
|
+
|
|
257
|
+
**Tools:**
|
|
258
|
+
- [Rack Mini Profiler](https://github.com/MiniProfiler/rack-mini-profiler) - Performance profiling
|
|
259
|
+
|
|
260
|
+
</resources>
|
|
@@ -0,0 +1,437 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: rails-deployment
|
|
3
|
+
description: Deploy Rails applications to production using Kamal, Docker, and modern deployment strategies. Covers zero-downtime deployments, environment management, database migrations, SSL/TLS, and production configurations.
|
|
4
|
+
allowed-tools: Read, Grep, Glob, Edit, Write, Bash
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Rails Deployment with Kamal
|
|
8
|
+
|
|
9
|
+
Deploy Rails 8 applications to production using Kamal for zero-downtime Docker deployments. Covers Kamal configuration, Docker setup, environment secrets, database migrations, SSL certificates, and production best practices.
|
|
10
|
+
|
|
11
|
+
<when-to-use>
|
|
12
|
+
- Setting up new Rails application for production deployment
|
|
13
|
+
- Deploying with Kamal to VPS (DigitalOcean, Hetzner, AWS EC2)
|
|
14
|
+
- Configuring Docker for Rails applications
|
|
15
|
+
- Managing environment variables and secrets
|
|
16
|
+
- Running database migrations in production
|
|
17
|
+
- Setting up zero-downtime deployments
|
|
18
|
+
- Configuring SSL/TLS certificates
|
|
19
|
+
- Managing multiple environments (staging, production)
|
|
20
|
+
</when-to-use>
|
|
21
|
+
|
|
22
|
+
<benefits>
|
|
23
|
+
- **Zero-Downtime** - Rolling deployments with health checks
|
|
24
|
+
- **Simple Setup** - SSH-based deployment, no complex orchestration
|
|
25
|
+
- **Docker Native** - Consistent environments from dev to production
|
|
26
|
+
- **Built-in SSL** - Automatic Let's Encrypt certificate management
|
|
27
|
+
- **Fast Deployments** - Optimized Docker layer caching
|
|
28
|
+
- **Rollback Support** - Easy rollback to previous versions
|
|
29
|
+
- **Multi-Server** - Deploy to multiple servers with load balancing
|
|
30
|
+
</benefits>
|
|
31
|
+
|
|
32
|
+
<verification-checklist>
|
|
33
|
+
Before deploying to production:
|
|
34
|
+
- ✅ Kamal configuration file (config/deploy.yml) properly configured
|
|
35
|
+
- ✅ Dockerfile optimized with multi-stage build
|
|
36
|
+
- ✅ Environment secrets set up (.env, Rails credentials)
|
|
37
|
+
- ✅ Database configured and migrations ready
|
|
38
|
+
- ✅ SSL certificates configured (Let's Encrypt or custom)
|
|
39
|
+
- ✅ Health check endpoint responding
|
|
40
|
+
- ✅ Asset precompilation working in Docker
|
|
41
|
+
- ✅ Background jobs (Solid Queue) configured
|
|
42
|
+
- ✅ Monitoring and logging set up
|
|
43
|
+
</verification-checklist>
|
|
44
|
+
|
|
45
|
+
<standards>
|
|
46
|
+
- Use Kamal for deployments (included in Rails 8)
|
|
47
|
+
- Multi-stage Dockerfile for optimized images
|
|
48
|
+
- Store secrets in Rails credentials or environment variables
|
|
49
|
+
- Run database migrations before deployment with --skip-push
|
|
50
|
+
- Use health checks for zero-downtime deployments
|
|
51
|
+
- Configure SSL with Let's Encrypt or custom certificates
|
|
52
|
+
- Set up log aggregation (stdout/stderr)
|
|
53
|
+
- Use Docker registry for image caching (Docker Hub, GitHub Container Registry)
|
|
54
|
+
- Configure proper resource limits in Docker
|
|
55
|
+
- Monitor application health and performance
|
|
56
|
+
</standards>
|
|
57
|
+
|
|
58
|
+
---
|
|
59
|
+
|
|
60
|
+
## Kamal Overview
|
|
61
|
+
|
|
62
|
+
Kamal (formerly MRSK) is a deployment tool for Rails 8 that uses Docker and SSH to deploy applications to any server. No Kubernetes, no complex orchestration - just simple, reliable deployments.
|
|
63
|
+
|
|
64
|
+
**Key Features:**
|
|
65
|
+
- Zero-downtime deployments with health checks
|
|
66
|
+
- Automatic SSL with Let's Encrypt
|
|
67
|
+
- Multi-server deployments
|
|
68
|
+
- Rolling restarts
|
|
69
|
+
- Easy rollbacks
|
|
70
|
+
- Built-in load balancing with Traefik
|
|
71
|
+
|
|
72
|
+
---
|
|
73
|
+
|
|
74
|
+
## Quick Start
|
|
75
|
+
|
|
76
|
+
### 1. Install Kamal
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
# Kamal comes with Rails 8
|
|
80
|
+
gem install kamal
|
|
81
|
+
|
|
82
|
+
# Verify installation
|
|
83
|
+
kamal version
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### 2. Initialize Kamal
|
|
87
|
+
|
|
88
|
+
```bash
|
|
89
|
+
# Generate Kamal configuration files
|
|
90
|
+
kamal init
|
|
91
|
+
|
|
92
|
+
# Creates:
|
|
93
|
+
# - config/deploy.yml # Main configuration
|
|
94
|
+
# - .env.erb # Environment template
|
|
95
|
+
# - .kamal/ # Kamal directory
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### 3. Configure Server
|
|
99
|
+
|
|
100
|
+
```yaml
|
|
101
|
+
# config/deploy.yml
|
|
102
|
+
service: my-blog-app
|
|
103
|
+
image: your-username/my-blog-app
|
|
104
|
+
|
|
105
|
+
servers:
|
|
106
|
+
web:
|
|
107
|
+
hosts:
|
|
108
|
+
- 192.168.1.100 # Your server IP
|
|
109
|
+
labels:
|
|
110
|
+
traefik.http.routers.my-blog-app.rule: Host(`example.com`)
|
|
111
|
+
traefik.http.routers.my-blog-app-secure.entrypoints: websecure
|
|
112
|
+
traefik.http.routers.my-blog-app-secure.rule: Host(`example.com`)
|
|
113
|
+
traefik.http.routers.my-blog-app-secure.tls: true
|
|
114
|
+
traefik.http.routers.my-blog-app-secure.tls.certresolver: letsencrypt
|
|
115
|
+
|
|
116
|
+
registry:
|
|
117
|
+
username: your-username
|
|
118
|
+
password:
|
|
119
|
+
- KAMAL_REGISTRY_PASSWORD
|
|
120
|
+
|
|
121
|
+
env:
|
|
122
|
+
secret:
|
|
123
|
+
- RAILS_MASTER_KEY
|
|
124
|
+
clear:
|
|
125
|
+
RAILS_ENV: production
|
|
126
|
+
RAILS_LOG_TO_STDOUT: true
|
|
127
|
+
|
|
128
|
+
builder:
|
|
129
|
+
multiarch: false
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
### 4. Setup Server
|
|
133
|
+
|
|
134
|
+
```bash
|
|
135
|
+
# Install Docker on remote server
|
|
136
|
+
kamal server bootstrap
|
|
137
|
+
|
|
138
|
+
# Verify setup
|
|
139
|
+
kamal setup
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
### 5. Deploy
|
|
143
|
+
|
|
144
|
+
```bash
|
|
145
|
+
# First deployment
|
|
146
|
+
kamal deploy
|
|
147
|
+
|
|
148
|
+
# Subsequent deployments
|
|
149
|
+
kamal deploy
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
---
|
|
153
|
+
|
|
154
|
+
## Code Examples & Patterns
|
|
155
|
+
|
|
156
|
+
For detailed deployment patterns and examples, see **[examples.md](examples.md)**.
|
|
157
|
+
|
|
158
|
+
### Pattern Categories
|
|
159
|
+
|
|
160
|
+
**examples.md contains:**
|
|
161
|
+
- **Kamal Configuration** - Complete deploy.yml examples for various setups
|
|
162
|
+
- **Docker Configuration** - Multi-stage Dockerfile optimization
|
|
163
|
+
- **Environment Management** - Secrets, credentials, environment variables
|
|
164
|
+
- **Database Migrations** - Safe migration strategies in production
|
|
165
|
+
- **SSL/TLS Setup** - Let's Encrypt and custom certificates
|
|
166
|
+
- **Multi-Server Deployment** - Load balancing across servers
|
|
167
|
+
- **Background Jobs** - Deploying Solid Queue workers
|
|
168
|
+
- **Health Checks** - Endpoint configuration for zero-downtime
|
|
169
|
+
- **Rollback Procedures** - Recovering from failed deployments
|
|
170
|
+
- **Monitoring & Logging** - Production observability setup
|
|
171
|
+
- **CI/CD Integration** - GitHub Actions deployment workflows
|
|
172
|
+
|
|
173
|
+
Refer to examples.md for complete code examples.
|
|
174
|
+
|
|
175
|
+
---
|
|
176
|
+
|
|
177
|
+
## Kamal Commands
|
|
178
|
+
|
|
179
|
+
### Deployment Commands
|
|
180
|
+
|
|
181
|
+
```bash
|
|
182
|
+
# Initial setup (first time only)
|
|
183
|
+
kamal setup
|
|
184
|
+
|
|
185
|
+
# Deploy application
|
|
186
|
+
kamal deploy
|
|
187
|
+
|
|
188
|
+
# Deploy without building new image
|
|
189
|
+
kamal deploy --skip-push
|
|
190
|
+
|
|
191
|
+
# Run migrations before deployment
|
|
192
|
+
kamal deploy --skip-push
|
|
193
|
+
kamal app exec "bin/rails db:migrate"
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
### Application Management
|
|
197
|
+
|
|
198
|
+
```bash
|
|
199
|
+
# Restart application
|
|
200
|
+
kamal app restart
|
|
201
|
+
|
|
202
|
+
# Stop application
|
|
203
|
+
kamal app stop
|
|
204
|
+
|
|
205
|
+
# Start application
|
|
206
|
+
kamal app start
|
|
207
|
+
|
|
208
|
+
# View application logs
|
|
209
|
+
kamal app logs -f
|
|
210
|
+
|
|
211
|
+
# Execute command in container
|
|
212
|
+
kamal app exec "bin/rails console"
|
|
213
|
+
kamal app exec "bin/rails db:migrate:status"
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
### Rollback
|
|
217
|
+
|
|
218
|
+
```bash
|
|
219
|
+
# List versions
|
|
220
|
+
kamal app version
|
|
221
|
+
|
|
222
|
+
# Rollback to previous version
|
|
223
|
+
kamal rollback [VERSION]
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
### Server Management
|
|
227
|
+
|
|
228
|
+
```bash
|
|
229
|
+
# SSH into server
|
|
230
|
+
kamal app exec --interactive bash
|
|
231
|
+
|
|
232
|
+
# View Docker containers
|
|
233
|
+
kamal app containers
|
|
234
|
+
|
|
235
|
+
# View server details
|
|
236
|
+
kamal server details
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
---
|
|
240
|
+
|
|
241
|
+
## Dockerfile for Rails
|
|
242
|
+
|
|
243
|
+
### Multi-Stage Dockerfile
|
|
244
|
+
|
|
245
|
+
Rails 8 includes an optimized Dockerfile by default:
|
|
246
|
+
|
|
247
|
+
```dockerfile
|
|
248
|
+
# Dockerfile (Rails 8 default, optimized)
|
|
249
|
+
ARG RUBY_VERSION=3.4.7
|
|
250
|
+
FROM ruby:$RUBY_VERSION-slim AS base
|
|
251
|
+
|
|
252
|
+
WORKDIR /rails
|
|
253
|
+
|
|
254
|
+
RUN apt-get update -qq && \
|
|
255
|
+
apt-get install --no-install-recommends -y \
|
|
256
|
+
curl libjemalloc2 libvips sqlite3 && \
|
|
257
|
+
rm -rf /var/lib/apt/lists /var/cache/apt/archives
|
|
258
|
+
|
|
259
|
+
ENV RAILS_ENV="production" \
|
|
260
|
+
BUNDLE_DEPLOYMENT="1" \
|
|
261
|
+
BUNDLE_PATH="/usr/local/bundle" \
|
|
262
|
+
BUNDLE_WITHOUT="development:test"
|
|
263
|
+
|
|
264
|
+
FROM base AS build
|
|
265
|
+
|
|
266
|
+
RUN apt-get update -qq && \
|
|
267
|
+
apt-get install --no-install-recommends -y \
|
|
268
|
+
build-essential git pkg-config && \
|
|
269
|
+
rm -rf /var/lib/apt/lists /var/cache/apt/archives
|
|
270
|
+
|
|
271
|
+
COPY Gemfile Gemfile.lock ./
|
|
272
|
+
RUN bundle install && \
|
|
273
|
+
rm -rf ~/.bundle/ "${BUNDLE_PATH}"/ruby/*/cache "${BUNDLE_PATH}"/ruby/*/bundler/gems/*/.git
|
|
274
|
+
|
|
275
|
+
COPY . .
|
|
276
|
+
|
|
277
|
+
RUN bundle exec bootsnap precompile --gemfile app/ lib/
|
|
278
|
+
RUN ./bin/rails assets:precompile
|
|
279
|
+
|
|
280
|
+
FROM base
|
|
281
|
+
|
|
282
|
+
COPY --from=build "${BUNDLE_PATH}" "${BUNDLE_PATH}"
|
|
283
|
+
COPY --from=build /rails /rails
|
|
284
|
+
|
|
285
|
+
RUN groupadd --system --gid 1000 rails && \
|
|
286
|
+
useradd rails --uid 1000 --gid 1000 --create-home --shell /bin/bash && \
|
|
287
|
+
chown -R 1000:1000 db log storage tmp
|
|
288
|
+
USER 1000:1000
|
|
289
|
+
|
|
290
|
+
ENTRYPOINT ["/rails/bin/docker-entrypoint"]
|
|
291
|
+
|
|
292
|
+
EXPOSE 3000
|
|
293
|
+
CMD ["./bin/thrust", "./bin/rails", "server"]
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
---
|
|
297
|
+
|
|
298
|
+
## Environment Management
|
|
299
|
+
|
|
300
|
+
### Rails Credentials
|
|
301
|
+
|
|
302
|
+
```bash
|
|
303
|
+
# Edit production credentials
|
|
304
|
+
EDITOR=nano rails credentials:edit --environment production
|
|
305
|
+
|
|
306
|
+
# Generates config/credentials/production.yml.enc
|
|
307
|
+
# and config/credentials/production.key
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
```yaml
|
|
311
|
+
# config/credentials/production.yml.enc (encrypted)
|
|
312
|
+
secret_key_base: <generated>
|
|
313
|
+
database:
|
|
314
|
+
password: <db_password>
|
|
315
|
+
smtp:
|
|
316
|
+
username: <smtp_user>
|
|
317
|
+
password: <smtp_pass>
|
|
318
|
+
```
|
|
319
|
+
|
|
320
|
+
### Environment Variables
|
|
321
|
+
|
|
322
|
+
```ruby
|
|
323
|
+
# .env (not committed to git, for local deployment)
|
|
324
|
+
KAMAL_REGISTRY_PASSWORD=<docker_hub_password>
|
|
325
|
+
RAILS_MASTER_KEY=<from config/credentials/production.key>
|
|
326
|
+
DATABASE_URL=postgresql://user:pass@host:5432/dbname
|
|
327
|
+
```
|
|
328
|
+
|
|
329
|
+
---
|
|
330
|
+
|
|
331
|
+
## Database Migrations
|
|
332
|
+
|
|
333
|
+
### Safe Migration Strategy
|
|
334
|
+
|
|
335
|
+
```bash
|
|
336
|
+
# 1. Deploy without running migrations
|
|
337
|
+
kamal deploy --skip-push
|
|
338
|
+
|
|
339
|
+
# 2. Run migrations separately
|
|
340
|
+
kamal app exec "bin/rails db:migrate"
|
|
341
|
+
|
|
342
|
+
# 3. Restart application
|
|
343
|
+
kamal app restart
|
|
344
|
+
```
|
|
345
|
+
|
|
346
|
+
### Pre-Deployment Checks
|
|
347
|
+
|
|
348
|
+
```bash
|
|
349
|
+
# Check migration status before deploying
|
|
350
|
+
kamal app exec "bin/rails db:migrate:status"
|
|
351
|
+
|
|
352
|
+
# Run migrations in a transaction
|
|
353
|
+
kamal app exec "bin/rails db:migrate"
|
|
354
|
+
|
|
355
|
+
# Verify migration success
|
|
356
|
+
kamal app exec "bin/rails db:version"
|
|
357
|
+
```
|
|
358
|
+
|
|
359
|
+
---
|
|
360
|
+
|
|
361
|
+
<testing>
|
|
362
|
+
|
|
363
|
+
## Testing Deployment
|
|
364
|
+
|
|
365
|
+
### Local Docker Testing
|
|
366
|
+
|
|
367
|
+
```bash
|
|
368
|
+
# Build Docker image locally
|
|
369
|
+
docker build -t my-app .
|
|
370
|
+
|
|
371
|
+
# Run container locally
|
|
372
|
+
docker run -p 3000:3000 \
|
|
373
|
+
-e RAILS_MASTER_KEY=<key> \
|
|
374
|
+
-e DATABASE_URL=<url> \
|
|
375
|
+
my-app
|
|
376
|
+
|
|
377
|
+
# Test in browser
|
|
378
|
+
open http://localhost:3000
|
|
379
|
+
```
|
|
380
|
+
|
|
381
|
+
### Staging Environment
|
|
382
|
+
|
|
383
|
+
```yaml
|
|
384
|
+
# config/deploy.staging.yml
|
|
385
|
+
service: my-blog-app-staging
|
|
386
|
+
image: your-username/my-blog-app
|
|
387
|
+
|
|
388
|
+
servers:
|
|
389
|
+
web:
|
|
390
|
+
hosts:
|
|
391
|
+
- staging.example.com
|
|
392
|
+
|
|
393
|
+
env:
|
|
394
|
+
secret:
|
|
395
|
+
- RAILS_MASTER_KEY
|
|
396
|
+
clear:
|
|
397
|
+
RAILS_ENV: staging
|
|
398
|
+
```
|
|
399
|
+
|
|
400
|
+
```bash
|
|
401
|
+
# Deploy to staging
|
|
402
|
+
kamal deploy -c config/deploy.staging.yml
|
|
403
|
+
```
|
|
404
|
+
|
|
405
|
+
</testing>
|
|
406
|
+
|
|
407
|
+
---
|
|
408
|
+
|
|
409
|
+
<related-skills>
|
|
410
|
+
- rails-models - Database setup and migrations
|
|
411
|
+
- rails-jobs - Background job configuration for production
|
|
412
|
+
- rails-api - API deployment considerations
|
|
413
|
+
- rails-debugging - Production debugging and monitoring
|
|
414
|
+
</related-skills>
|
|
415
|
+
|
|
416
|
+
<resources>
|
|
417
|
+
|
|
418
|
+
**Official Documentation:**
|
|
419
|
+
- [Kamal Documentation](https://kamal-deploy.org/) - Official Kamal guide
|
|
420
|
+
- [Docker Documentation](https://docs.docker.com/) - Docker reference
|
|
421
|
+
- [Rails Deployment Guide](https://guides.rubyonrails.org/configuring.html#running-in-production) - Rails production config
|
|
422
|
+
|
|
423
|
+
**Deployment Platforms:**
|
|
424
|
+
- [DigitalOcean](https://www.digitalocean.com/) - Simple VPS hosting
|
|
425
|
+
- [Hetzner](https://www.hetzner.com/) - Cost-effective VPS
|
|
426
|
+
- [AWS EC2](https://aws.amazon.com/ec2/) - Scalable cloud hosting
|
|
427
|
+
|
|
428
|
+
**Monitoring & Logging:**
|
|
429
|
+
- [AppSignal](https://appsignal.com/) - Rails monitoring
|
|
430
|
+
- [Sentry](https://sentry.io/) - Error tracking
|
|
431
|
+
- [Lograge](https://github.com/roidrage/lograge) - Structured logging
|
|
432
|
+
|
|
433
|
+
**CI/CD:**
|
|
434
|
+
- [GitHub Actions](https://github.com/features/actions) - CI/CD automation
|
|
435
|
+
- [Kamal GitHub Action](https://github.com/basecamp/kamal) - Official action
|
|
436
|
+
|
|
437
|
+
</resources>
|