content_flagging 1.0.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/.gitignore +52 -0
- data/LICENSE +21 -0
- data/README.md +143 -0
- data/Rakefile +5 -0
- data/content_flagging.gemspec +48 -0
- data/dummy_app/.dockerignore +37 -0
- data/dummy_app/.ruby-version +1 -0
- data/dummy_app/Dockerfile +62 -0
- data/dummy_app/Gemfile +65 -0
- data/dummy_app/Gemfile.lock +286 -0
- data/dummy_app/README.md +24 -0
- data/dummy_app/Rakefile +6 -0
- data/dummy_app/app/assets/config/manifest.js +2 -0
- data/dummy_app/app/assets/images/.keep +0 -0
- data/dummy_app/app/assets/stylesheets/application.css +15 -0
- data/dummy_app/app/channels/application_cable/channel.rb +4 -0
- data/dummy_app/app/channels/application_cable/connection.rb +4 -0
- data/dummy_app/app/controllers/application_controller.rb +2 -0
- data/dummy_app/app/controllers/concerns/.keep +0 -0
- data/dummy_app/app/helpers/application_helper.rb +2 -0
- data/dummy_app/app/jobs/application_job.rb +7 -0
- data/dummy_app/app/mailers/application_mailer.rb +4 -0
- data/dummy_app/app/models/application_record.rb +3 -0
- data/dummy_app/app/models/concerns/.keep +0 -0
- data/dummy_app/app/models/post.rb +3 -0
- data/dummy_app/app/models/user.rb +2 -0
- data/dummy_app/app/views/layouts/application.html.erb +15 -0
- data/dummy_app/app/views/layouts/mailer.html.erb +13 -0
- data/dummy_app/app/views/layouts/mailer.text.erb +1 -0
- data/dummy_app/bin/docker-entrypoint +8 -0
- data/dummy_app/bin/rails +4 -0
- data/dummy_app/bin/rake +4 -0
- data/dummy_app/bin/setup +33 -0
- data/dummy_app/config/application.rb +42 -0
- data/dummy_app/config/boot.rb +4 -0
- data/dummy_app/config/cable.yml +10 -0
- data/dummy_app/config/credentials.yml.enc +1 -0
- data/dummy_app/config/database.yml +25 -0
- data/dummy_app/config/environment.rb +5 -0
- data/dummy_app/config/environments/development.rb +76 -0
- data/dummy_app/config/environments/production.rb +97 -0
- data/dummy_app/config/environments/test.rb +64 -0
- data/dummy_app/config/initializers/assets.rb +12 -0
- data/dummy_app/config/initializers/content_security_policy.rb +25 -0
- data/dummy_app/config/initializers/filter_parameter_logging.rb +8 -0
- data/dummy_app/config/initializers/inflections.rb +16 -0
- data/dummy_app/config/initializers/permissions_policy.rb +13 -0
- data/dummy_app/config/locales/en.yml +31 -0
- data/dummy_app/config/master.key +1 -0
- data/dummy_app/config/puma.rb +44 -0
- data/dummy_app/config/routes.rb +10 -0
- data/dummy_app/config/storage.yml +34 -0
- data/dummy_app/config.ru +6 -0
- data/dummy_app/db/migrate/20250920174734_create_content_flags.rb +13 -0
- data/dummy_app/db/migrate/20250920174750_create_posts.rb +10 -0
- data/dummy_app/db/migrate/20250920174757_create_users.rb +9 -0
- data/dummy_app/db/schema.rb +40 -0
- data/dummy_app/db/seeds.rb +9 -0
- data/dummy_app/lib/assets/.keep +0 -0
- data/dummy_app/lib/tasks/.keep +0 -0
- data/dummy_app/public/404.html +67 -0
- data/dummy_app/public/422.html +67 -0
- data/dummy_app/public/500.html +66 -0
- data/dummy_app/public/apple-touch-icon-precomposed.png +0 -0
- data/dummy_app/public/apple-touch-icon.png +0 -0
- data/dummy_app/public/favicon.ico +0 -0
- data/dummy_app/public/robots.txt +1 -0
- data/dummy_app/storage/.keep +0 -0
- data/dummy_app/test_console.rb +46 -0
- data/dummy_app/vendor/.keep +0 -0
- data/example_usage.rb +46 -0
- data/lib/content_flagging/configuration.rb +9 -0
- data/lib/content_flagging/flag.rb +36 -0
- data/lib/content_flagging/flaggable.rb +46 -0
- data/lib/content_flagging/version.rb +3 -0
- data/lib/content_flagging.rb +22 -0
- data/lib/generators/content_flagging/install_generator.rb +24 -0
- data/lib/generators/content_flagging/templates/content_flagging.rb +4 -0
- data/lib/generators/content_flagging/templates/create_content_flags.rb.erb +13 -0
- data/test_manual.rb +36 -0
- metadata +342 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 1fe5a29d1160fecce845a934e83a92a4bc00f3da61f76f5db6b3f15aea73f006
|
|
4
|
+
data.tar.gz: 6c41f75667eddab18eb96206f8057c4287d0df2e315afb973e51ed2f5a2f0d2b
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 0e85b31a49a5d4a52144763dd9e321bc71e7bb504d858ad084727d938d74e2a08e576fa388ae1c1391f41425272998cf3f3bfc14ca54edc2408f7d0cf5ba8f39
|
|
7
|
+
data.tar.gz: a3a969baa59ebabe9babe391cfb9635bd84357dea69bc4fcec8b13984ae30d0be0bcec7ac7b1d7a3b7c432283fa721f2724d5efeb21e7f75661dbf7a7ff0de4d
|
data/.gitignore
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
*.gem
|
|
2
|
+
*.rbc
|
|
3
|
+
/.config
|
|
4
|
+
/coverage/
|
|
5
|
+
/InstalledFiles
|
|
6
|
+
/pkg/
|
|
7
|
+
/spec/reports/
|
|
8
|
+
/spec/examples.txt
|
|
9
|
+
/test/tmp/
|
|
10
|
+
/test/version_tmp/
|
|
11
|
+
/tmp/
|
|
12
|
+
|
|
13
|
+
# rspec failure tracking
|
|
14
|
+
.rspec_status
|
|
15
|
+
|
|
16
|
+
# YARD artifacts
|
|
17
|
+
.yardoc
|
|
18
|
+
_yardoc
|
|
19
|
+
doc/
|
|
20
|
+
.yardopts
|
|
21
|
+
|
|
22
|
+
# bundler
|
|
23
|
+
/vendor/bundle
|
|
24
|
+
/.bundle/
|
|
25
|
+
/Gemfile.lock
|
|
26
|
+
|
|
27
|
+
# ruby/rails
|
|
28
|
+
*.log
|
|
29
|
+
*.sqlite3
|
|
30
|
+
*.sqlite3-*
|
|
31
|
+
.byebug_history
|
|
32
|
+
|
|
33
|
+
# OS generated files
|
|
34
|
+
.DS_Store
|
|
35
|
+
.DS_Store?
|
|
36
|
+
._*
|
|
37
|
+
.Spotlight-V100
|
|
38
|
+
.Trashes
|
|
39
|
+
ehthumbs.db
|
|
40
|
+
Thumbs.db
|
|
41
|
+
|
|
42
|
+
# IDE
|
|
43
|
+
.vscode/
|
|
44
|
+
.idea/
|
|
45
|
+
*.swp
|
|
46
|
+
*.swo
|
|
47
|
+
|
|
48
|
+
# dummy app
|
|
49
|
+
dummy_app/log/
|
|
50
|
+
dummy_app/tmp/
|
|
51
|
+
dummy_app/db/*.sqlite3
|
|
52
|
+
dummy_app/.byebug_history
|
data/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Arshdeep Singh
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
# 🚩 ContentFlagging
|
|
2
|
+
|
|
3
|
+
> **The `acts_as_paranoid` for content moderation**
|
|
4
|
+
|
|
5
|
+
A powerful Rails gem that automatically hides inappropriate content when it gets flagged too many times. Just like `acts_as_paranoid` hides deleted records, `acts_as_flaggable` hides flagged content from your default scopes.
|
|
6
|
+
|
|
7
|
+
## ⚡ Quick Start
|
|
8
|
+
|
|
9
|
+
```ruby
|
|
10
|
+
# Gemfile
|
|
11
|
+
gem 'content_flagging'
|
|
12
|
+
|
|
13
|
+
# Terminal
|
|
14
|
+
rails generate content_flagging:install
|
|
15
|
+
rails db:migrate
|
|
16
|
+
|
|
17
|
+
# Model
|
|
18
|
+
class Post < ApplicationRecord
|
|
19
|
+
acts_as_flaggable # 🎯 That's it!
|
|
20
|
+
end
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## 🎯 The Magic
|
|
24
|
+
|
|
25
|
+
```ruby
|
|
26
|
+
post = Post.create(title: "Controversial Content")
|
|
27
|
+
|
|
28
|
+
# Users start flagging...
|
|
29
|
+
post.flag!(flagged_by: user1)
|
|
30
|
+
post.flag!(flagged_by: user2)
|
|
31
|
+
post.flag! # Anonymous flag
|
|
32
|
+
|
|
33
|
+
# 💥 BOOM! Post disappears from default scope
|
|
34
|
+
Post.all.include?(post) # => false (auto-hidden!)
|
|
35
|
+
post.flagged? # => true
|
|
36
|
+
post.flagged_at # => 2024-01-01 12:00:00 UTC
|
|
37
|
+
|
|
38
|
+
# But admins can still see everything
|
|
39
|
+
Post.with_flagged.count # => All posts (including flagged)
|
|
40
|
+
Post.with_flagged.flagged # => Only flagged posts
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## 🛠️ Setup
|
|
44
|
+
|
|
45
|
+
### 1. Add the Magic Method
|
|
46
|
+
```ruby
|
|
47
|
+
class Post < ApplicationRecord
|
|
48
|
+
acts_as_flaggable # Default threshold: 3
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
class Comment < ApplicationRecord
|
|
52
|
+
acts_as_flaggable threshold: 5 # Custom threshold
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
class Review < ApplicationRecord
|
|
56
|
+
acts_as_flaggable threshold: 1 # Zero tolerance
|
|
57
|
+
end
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### 2. Add Database Columns
|
|
61
|
+
```ruby
|
|
62
|
+
# Migration
|
|
63
|
+
add_column :posts, :flagged_count, :integer, default: 0
|
|
64
|
+
add_column :posts, :flagged_at, :datetime
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## 🚀 Real-World Examples
|
|
68
|
+
|
|
69
|
+
### Community Moderation
|
|
70
|
+
```ruby
|
|
71
|
+
# Users can flag inappropriate content
|
|
72
|
+
def flag_post
|
|
73
|
+
@post.flag!(flagged_by: current_user)
|
|
74
|
+
redirect_to posts_path, notice: "Thanks for keeping our community safe! 🛡️"
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
# Content automatically disappears when threshold is hit
|
|
78
|
+
Post.all # Only shows clean content ✨
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### Admin Dashboard
|
|
82
|
+
```ruby
|
|
83
|
+
# See what's been flagged
|
|
84
|
+
@flagged_posts = Post.with_flagged.flagged.order(:flagged_at)
|
|
85
|
+
@recent_flags = Post.with_flagged.where('flagged_at > ?', 1.day.ago)
|
|
86
|
+
|
|
87
|
+
# Bulk operations
|
|
88
|
+
Post.with_flagged.flagged.pluck(:flagged_at) # When were they flagged?
|
|
89
|
+
Post.with_flagged.where('flagged_count > 10') # Heavily flagged content
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### Smart Queries
|
|
93
|
+
```ruby
|
|
94
|
+
# Different ways to slice and dice
|
|
95
|
+
Post.count # Clean content only
|
|
96
|
+
Post.with_flagged.count # Everything
|
|
97
|
+
Post.not_flagged.count # Explicitly clean
|
|
98
|
+
Post.with_flagged.flagged # The naughty list 😈
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
## ⚙️ Configuration
|
|
102
|
+
|
|
103
|
+
```ruby
|
|
104
|
+
# config/initializers/content_flagging.rb
|
|
105
|
+
ContentFlagging.configure do |config|
|
|
106
|
+
config.flag_threshold = 5 # Global default (can be overridden per model)
|
|
107
|
+
end
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## 🎪 API Reference
|
|
111
|
+
|
|
112
|
+
| Method | Description | Example |
|
|
113
|
+
|--------|-------------|----------|
|
|
114
|
+
| `flag!(flagged_by: user)` | Flag content | `post.flag!(flagged_by: current_user)` |
|
|
115
|
+
| `unflag!(flagged_by: user)` | Remove flag | `post.unflag!(flagged_by: current_user)` |
|
|
116
|
+
| `flagged?` | Check if flagged | `post.flagged? # => true/false` |
|
|
117
|
+
| `flag_count` | Number of flags | `post.flag_count # => 3` |
|
|
118
|
+
| `flagged_at` | When first flagged | `post.flagged_at # => Time` |
|
|
119
|
+
|
|
120
|
+
| Scope | Description | Example |
|
|
121
|
+
|-------|-------------|----------|
|
|
122
|
+
| `Model.all` | Clean content (default) | `Post.all` |
|
|
123
|
+
| `Model.with_flagged` | Everything | `Post.with_flagged` |
|
|
124
|
+
| `Model.flagged` | Only flagged | `Post.with_flagged.flagged` |
|
|
125
|
+
| `Model.not_flagged` | Explicitly clean | `Post.not_flagged` |
|
|
126
|
+
|
|
127
|
+
## 🔥 Why This Rocks
|
|
128
|
+
|
|
129
|
+
- **🎯 Zero Config**: Works out of the box with sensible defaults
|
|
130
|
+
- **🔒 Thread-Safe**: Database-level counters prevent race conditions
|
|
131
|
+
- **🚀 Performance**: Efficient queries with proper indexing
|
|
132
|
+
- **🎨 Flexible**: Flag anything - posts, comments, users, you name it
|
|
133
|
+
- **👥 Community-Driven**: Let your users moderate themselves
|
|
134
|
+
- **🛡️ Admin-Friendly**: Easy oversight and management tools
|
|
135
|
+
- **🗄️ Database Agnostic**: Works with PostgreSQL, MySQL, SQLite
|
|
136
|
+
|
|
137
|
+
## 🤝 Contributing
|
|
138
|
+
|
|
139
|
+
Found a bug? Want a feature? PRs welcome!
|
|
140
|
+
|
|
141
|
+
## 📄 License
|
|
142
|
+
|
|
143
|
+
MIT License - go wild! 🎉
|
data/Rakefile
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
require_relative 'lib/content_flagging/version'
|
|
2
|
+
|
|
3
|
+
Gem::Specification.new do |spec|
|
|
4
|
+
spec.name = 'content_flagging'
|
|
5
|
+
spec.version = ContentFlagging::VERSION
|
|
6
|
+
spec.authors = ['Arshdeep Singh']
|
|
7
|
+
spec.email = ['arsh199820@gmail.com']
|
|
8
|
+
spec.summary = 'The acts_as_paranoid for content moderation - automatic flagging system for Rails'
|
|
9
|
+
spec.description = 'A powerful Rails gem that automatically hides inappropriate content when flagged. Like acts_as_paranoid for deleted records, acts_as_flaggable hides flagged content from default scopes with configurable thresholds.'
|
|
10
|
+
spec.homepage = 'https://github.com/arshdeepsingh/content_flagging'
|
|
11
|
+
spec.license = 'MIT'
|
|
12
|
+
spec.required_ruby_version = '>= 2.7.0'
|
|
13
|
+
|
|
14
|
+
spec.metadata = {
|
|
15
|
+
'homepage_uri' => 'https://github.com/arshdeepsingh/content_flagging',
|
|
16
|
+
'source_code_uri' => 'https://github.com/arshdeepsingh/content_flagging',
|
|
17
|
+
'changelog_uri' => 'https://github.com/arshdeepsingh/content_flagging/blob/main/CHANGELOG.md',
|
|
18
|
+
'bug_tracker_uri' => 'https://github.com/arshdeepsingh/content_flagging/issues',
|
|
19
|
+
'documentation_uri' => 'https://github.com/arshdeepsingh/content_flagging/blob/main/README.md',
|
|
20
|
+
'rubygems_mfa_required' => 'true'
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
|
24
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
|
25
|
+
end
|
|
26
|
+
spec.bindir = 'exe'
|
|
27
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
28
|
+
spec.require_paths = ['lib']
|
|
29
|
+
|
|
30
|
+
# Runtime dependencies
|
|
31
|
+
spec.add_dependency 'activerecord', '>= 6.0'
|
|
32
|
+
spec.add_dependency 'activesupport', '>= 6.0'
|
|
33
|
+
spec.add_dependency 'railties', '>= 6.0'
|
|
34
|
+
|
|
35
|
+
# Development dependencies
|
|
36
|
+
spec.add_development_dependency 'bundler', '~> 2.0'
|
|
37
|
+
spec.add_development_dependency 'rake', '~> 13.0'
|
|
38
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
|
39
|
+
spec.add_development_dependency 'rspec-rails', '~> 5.0'
|
|
40
|
+
spec.add_development_dependency 'sqlite3', '~> 1.4'
|
|
41
|
+
spec.add_development_dependency 'pg', '~> 1.0'
|
|
42
|
+
spec.add_development_dependency 'mysql2', '~> 0.5'
|
|
43
|
+
spec.add_development_dependency 'rails', '>= 6.0'
|
|
44
|
+
spec.add_development_dependency 'factory_bot_rails', '~> 6.0'
|
|
45
|
+
spec.add_development_dependency 'rubocop', '~> 1.0'
|
|
46
|
+
spec.add_development_dependency 'rubocop-rails', '~> 2.0'
|
|
47
|
+
spec.add_development_dependency 'simplecov', '~> 0.21'
|
|
48
|
+
end
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# See https://docs.docker.com/engine/reference/builder/#dockerignore-file for more about ignoring files.
|
|
2
|
+
|
|
3
|
+
# Ignore git directory.
|
|
4
|
+
/.git/
|
|
5
|
+
|
|
6
|
+
# Ignore bundler config.
|
|
7
|
+
/.bundle
|
|
8
|
+
|
|
9
|
+
# Ignore all environment files (except templates).
|
|
10
|
+
/.env*
|
|
11
|
+
!/.env*.erb
|
|
12
|
+
|
|
13
|
+
# Ignore all default key files.
|
|
14
|
+
/config/master.key
|
|
15
|
+
/config/credentials/*.key
|
|
16
|
+
|
|
17
|
+
# Ignore all logfiles and tempfiles.
|
|
18
|
+
/log/*
|
|
19
|
+
/tmp/*
|
|
20
|
+
!/log/.keep
|
|
21
|
+
!/tmp/.keep
|
|
22
|
+
|
|
23
|
+
# Ignore pidfiles, but keep the directory.
|
|
24
|
+
/tmp/pids/*
|
|
25
|
+
!/tmp/pids/.keep
|
|
26
|
+
|
|
27
|
+
# Ignore storage (uploaded files in development and any SQLite databases).
|
|
28
|
+
/storage/*
|
|
29
|
+
!/storage/.keep
|
|
30
|
+
/tmp/storage/*
|
|
31
|
+
!/tmp/storage/.keep
|
|
32
|
+
|
|
33
|
+
# Ignore assets.
|
|
34
|
+
/node_modules/
|
|
35
|
+
/app/assets/builds/*
|
|
36
|
+
!/app/assets/builds/.keep
|
|
37
|
+
/public/assets
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
3.0.6
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# syntax = docker/dockerfile:1
|
|
2
|
+
|
|
3
|
+
# Make sure RUBY_VERSION matches the Ruby version in .ruby-version and Gemfile
|
|
4
|
+
ARG RUBY_VERSION=3.0.6
|
|
5
|
+
FROM registry.docker.com/library/ruby:$RUBY_VERSION-slim as base
|
|
6
|
+
|
|
7
|
+
# Rails app lives here
|
|
8
|
+
WORKDIR /rails
|
|
9
|
+
|
|
10
|
+
# Set production environment
|
|
11
|
+
ENV RAILS_ENV="production" \
|
|
12
|
+
BUNDLE_DEPLOYMENT="1" \
|
|
13
|
+
BUNDLE_PATH="/usr/local/bundle" \
|
|
14
|
+
BUNDLE_WITHOUT="development"
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
# Throw-away build stage to reduce size of final image
|
|
18
|
+
FROM base as build
|
|
19
|
+
|
|
20
|
+
# Install packages needed to build gems
|
|
21
|
+
RUN apt-get update -qq && \
|
|
22
|
+
apt-get install --no-install-recommends -y build-essential git libvips pkg-config
|
|
23
|
+
|
|
24
|
+
# Install application gems
|
|
25
|
+
COPY Gemfile Gemfile.lock ./
|
|
26
|
+
RUN bundle install && \
|
|
27
|
+
rm -rf ~/.bundle/ "${BUNDLE_PATH}"/ruby/*/cache "${BUNDLE_PATH}"/ruby/*/bundler/gems/*/.git && \
|
|
28
|
+
bundle exec bootsnap precompile --gemfile
|
|
29
|
+
|
|
30
|
+
# Copy application code
|
|
31
|
+
COPY . .
|
|
32
|
+
|
|
33
|
+
# Precompile bootsnap code for faster boot times
|
|
34
|
+
RUN bundle exec bootsnap precompile app/ lib/
|
|
35
|
+
|
|
36
|
+
# Precompiling assets for production without requiring secret RAILS_MASTER_KEY
|
|
37
|
+
RUN SECRET_KEY_BASE_DUMMY=1 ./bin/rails assets:precompile
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
# Final stage for app image
|
|
41
|
+
FROM base
|
|
42
|
+
|
|
43
|
+
# Install packages needed for deployment
|
|
44
|
+
RUN apt-get update -qq && \
|
|
45
|
+
apt-get install --no-install-recommends -y curl libsqlite3-0 libvips && \
|
|
46
|
+
rm -rf /var/lib/apt/lists /var/cache/apt/archives
|
|
47
|
+
|
|
48
|
+
# Copy built artifacts: gems, application
|
|
49
|
+
COPY --from=build /usr/local/bundle /usr/local/bundle
|
|
50
|
+
COPY --from=build /rails /rails
|
|
51
|
+
|
|
52
|
+
# Run and own only the runtime files as a non-root user for security
|
|
53
|
+
RUN useradd rails --create-home --shell /bin/bash && \
|
|
54
|
+
chown -R rails:rails db log storage tmp
|
|
55
|
+
USER rails:rails
|
|
56
|
+
|
|
57
|
+
# Entrypoint prepares the database.
|
|
58
|
+
ENTRYPOINT ["/rails/bin/docker-entrypoint"]
|
|
59
|
+
|
|
60
|
+
# Start the server by default, this can be overwritten at runtime
|
|
61
|
+
EXPOSE 3000
|
|
62
|
+
CMD ["./bin/rails", "server"]
|
data/dummy_app/Gemfile
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
source "https://rubygems.org"
|
|
2
|
+
|
|
3
|
+
ruby "3.0.6"
|
|
4
|
+
|
|
5
|
+
# Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main"
|
|
6
|
+
gem "rails", "~> 7.1.4"
|
|
7
|
+
|
|
8
|
+
# The original asset pipeline for Rails [https://github.com/rails/sprockets-rails]
|
|
9
|
+
gem "sprockets-rails"
|
|
10
|
+
|
|
11
|
+
# Use sqlite3 as the database for Active Record
|
|
12
|
+
gem "sqlite3", ">= 1.4"
|
|
13
|
+
|
|
14
|
+
# Content flagging gem
|
|
15
|
+
gem "content_flagging", path: ".."
|
|
16
|
+
|
|
17
|
+
# Use the Puma web server [https://github.com/puma/puma]
|
|
18
|
+
gem "puma", ">= 5.0"
|
|
19
|
+
|
|
20
|
+
# Use JavaScript with ESM import maps [https://github.com/rails/importmap-rails]
|
|
21
|
+
gem "importmap-rails"
|
|
22
|
+
|
|
23
|
+
# Hotwire's SPA-like page accelerator [https://turbo.hotwired.dev]
|
|
24
|
+
gem "turbo-rails"
|
|
25
|
+
|
|
26
|
+
# Hotwire's modest JavaScript framework [https://stimulus.hotwired.dev]
|
|
27
|
+
gem "stimulus-rails"
|
|
28
|
+
|
|
29
|
+
# Build JSON APIs with ease [https://github.com/rails/jbuilder]
|
|
30
|
+
gem "jbuilder"
|
|
31
|
+
|
|
32
|
+
# Use Redis adapter to run Action Cable in production
|
|
33
|
+
# gem "redis", ">= 4.0.1"
|
|
34
|
+
|
|
35
|
+
# Use Kredis to get higher-level data types in Redis [https://github.com/rails/kredis]
|
|
36
|
+
# gem "kredis"
|
|
37
|
+
|
|
38
|
+
# Use Active Model has_secure_password [https://guides.rubyonrails.org/active_model_basics.html#securepassword]
|
|
39
|
+
# gem "bcrypt", "~> 3.1.7"
|
|
40
|
+
|
|
41
|
+
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
|
|
42
|
+
gem "tzinfo-data", platforms: %i[ windows jruby ]
|
|
43
|
+
|
|
44
|
+
# Reduces boot times through caching; required in config/boot.rb
|
|
45
|
+
gem "bootsnap", require: false
|
|
46
|
+
|
|
47
|
+
# Use Active Storage variants [https://guides.rubyonrails.org/active_storage_overview.html#transforming-images]
|
|
48
|
+
# gem "image_processing", "~> 1.2"
|
|
49
|
+
|
|
50
|
+
group :development, :test do
|
|
51
|
+
# See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem
|
|
52
|
+
gem "debug", platforms: %i[ mri windows ]
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
group :development do
|
|
56
|
+
# Use console on exceptions pages [https://github.com/rails/web-console]
|
|
57
|
+
gem "web-console"
|
|
58
|
+
|
|
59
|
+
# Add speed badges [https://github.com/MiniProfiler/rack-mini-profiler]
|
|
60
|
+
# gem "rack-mini-profiler"
|
|
61
|
+
|
|
62
|
+
# Speed up commands on slow machines / big apps [https://github.com/rails/spring]
|
|
63
|
+
# gem "spring"
|
|
64
|
+
end
|
|
65
|
+
|