plutonium 0.10.2 → 0.10.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -0
  3. data/app/views/application/_flash_alerts.html.erb +3 -0
  4. data/app/views/application/_flash_toasts.html.erb +2 -0
  5. data/app/views/components/base.rb +1 -1
  6. data/app/views/layouts/resource.html copy.erb +2 -2
  7. data/app/views/layouts/resource.html.erb +3 -3
  8. data/app/views/layouts/rodauth.html.erb +9 -4
  9. data/app/views/rodauth/add_recovery_codes.html.erb +8 -7
  10. data/app/views/rodauth/otp_auth.html.erb +1 -1
  11. data/app/views/rodauth/otp_setup.html.erb +10 -8
  12. data/css.manifest +1 -1
  13. data/lib/generators/pu/core/ruby/ruby_generator.rb +30 -0
  14. data/lib/generators/pu/core/ruby/templates/.keep +0 -0
  15. data/lib/generators/pu/docker/install/install_generator.rb +35 -0
  16. data/lib/generators/pu/docker/install/templates/.keep +0 -0
  17. data/lib/generators/pu/docker/install/templates/Dockerfile.dev.tt +30 -0
  18. data/lib/generators/pu/docker/install/templates/Dockerfile.tt +75 -0
  19. data/lib/generators/pu/docker/install/templates/bin/console +3 -0
  20. data/lib/generators/pu/docker/install/templates/bin/restart +3 -0
  21. data/lib/generators/pu/docker/install/templates/bin/shell +3 -0
  22. data/lib/generators/pu/docker/install/templates/docker-compose.yml +29 -0
  23. data/lib/generators/pu/gem/dotenv/dotenv_generator.rb +32 -0
  24. data/lib/generators/pu/gem/dotenv/templates/.env +6 -0
  25. data/lib/generators/pu/gem/dotenv/templates/.env.local +5 -0
  26. data/lib/generators/pu/gem/dotenv/templates/.env.local.template +5 -0
  27. data/lib/generators/pu/gem/dotenv/templates/.env.template +6 -0
  28. data/lib/generators/pu/gem/dotenv/templates/.keep +0 -0
  29. data/lib/generators/pu/gem/dotenv/templates/config/initializers/001_ensure_required_env.rb +15 -0
  30. data/lib/generators/pu/gem/redis/redis_generator.rb +22 -0
  31. data/lib/generators/pu/gem/redis/templates/.keep +0 -0
  32. data/lib/generators/pu/lib/plutonium_generators/concerns/actions.rb +154 -32
  33. data/lib/generators/pu/lib/plutonium_generators/generator.rb +6 -6
  34. data/lib/generators/pu/lib/plutonium_generators/installer.rb +1 -1
  35. data/lib/generators/pu/rodauth/account_generator.rb +10 -10
  36. data/lib/generators/pu/rodauth/install_generator.rb +9 -2
  37. data/lib/generators/pu/rodauth/migration/sequel/audit_logging.erb +2 -2
  38. data/lib/generators/pu/rodauth/migration_generator.rb +1 -1
  39. data/lib/generators/pu/rodauth/templates/app/{misc → rodauth}/account_rodauth_plugin.rb.tt +2 -2
  40. data/lib/generators/pu/rodauth/templates/app/{misc → rodauth}/rodauth_plugin.rb.tt +0 -3
  41. data/lib/generators/pu/rodauth/templates/db/migrate/install_rodauth.rb.tt +5 -0
  42. data/lib/generators/pu/service/postgres/postgres_generator.rb +61 -0
  43. data/lib/generators/pu/service/postgres/templates/.keep +0 -0
  44. data/lib/generators/pu/service/postgres/templates/bin/initdb.d/create-multiple-postgresql-databases.sh +22 -0
  45. data/lib/generators/pu/service/postgres/templates/database.yml.tt +93 -0
  46. data/lib/generators/pu/service/sidekiq/sidekiq_generator.rb +62 -0
  47. data/lib/generators/pu/service/sidekiq/templates/.keep +0 -0
  48. data/lib/generators/pu/service/sidekiq/templates/app/sidekiq/sidekiq_job.rb +5 -0
  49. data/lib/generators/pu/service/sidekiq/templates/config/initializers/sidekiq.rb +53 -0
  50. data/lib/generators/pu/service/sidekiq/templates/config/sidekiq.yml +6 -0
  51. data/lib/plutonium/config.rb +7 -2
  52. data/lib/plutonium/core/controllers/base.rb +1 -1
  53. data/lib/plutonium/core/controllers/entity_scoping.rb +3 -3
  54. data/lib/plutonium/icons.rb +1 -1
  55. data/lib/plutonium/railtie.rb +4 -0
  56. data/lib/plutonium/resource/controller.rb +1 -0
  57. data/lib/plutonium/rodauth/controller_methods.rb +1 -1
  58. data/lib/plutonium/version.rb +1 -1
  59. data/lib/plutonium.rb +4 -0
  60. data/lib/tasks/create_rodauth_admin.rake +16 -0
  61. data/public/plutonium-assets/plutonium.8bee7a8482988b0360e3.css +3420 -0
  62. metadata +36 -5
  63. /data/lib/generators/pu/rodauth/templates/app/{misc → rodauth}/rodauth_app.rb.tt +0 -0
@@ -22,7 +22,10 @@ module PlutoniumGenerators
22
22
 
23
23
  in_root do
24
24
  create_file ".ruby-version", version, force: true, verbose: false
25
- gsub_file "Gemfile", /^ruby ["'].*["']/, "ruby '~> #{version}'", verbose: false
25
+ gsub_file("Gemfile", /^ruby .*/, "ruby File.read(\".ruby-version\").strip", verbose: false)
26
+ %w[Dockerfile Dockerfile.prod Dockerfile.dev].each do |file|
27
+ gsub_file(file, /^ARG RUBY_VERSION=.*/, "ARG RUBY_VERSION=#{version}", verbose: false) if File.exist?(file)
28
+ end
26
29
  end
27
30
  end
28
31
 
@@ -95,29 +98,84 @@ module PlutoniumGenerators
95
98
  # gsub_file "Gemfile", /(:?^.*#.*\n)*.*gem ['"]#{gem}['"].*\n/, "", verbose: false
96
99
  # end
97
100
 
98
- #
99
- # Evaluates the given template and merges it with the project's docker-compose.yml
100
- #
101
- # @param [String] source the template filename
102
- #
103
- # @return [void]
104
- #
105
- def docker_compose(source)
106
- log :docker_compose, source
101
+ # #
102
+ # # Evaluates the given template and merges it with the project's docker-compose.yml
103
+ # #
104
+ # # @param [String] source the template filename
105
+ # #
106
+ # # @return [void]
107
+ # #
108
+ # def docker_compose(source)
109
+ # log :docker_compose, source
110
+
111
+ # in_root do
112
+ # compose_file = "docker-compose.yml"
113
+ # compose_definition = YAML.load_file(compose_file) if File.exist?(compose_file)
114
+ # compose_definition ||= {
115
+ # version: "3.7",
116
+ # services: {}
117
+ # }
118
+ # compose_definition.deep_stringify_keys!
119
+
120
+ # new_definition = YAML.load template_eval("docker-compose/#{source}.yml.tt")
121
+ # compose_definition.deep_merge! new_definition.deep_stringify_keys
122
+
123
+ # create_file compose_file, YAML.dump(compose_definition), force: true
124
+ # end
125
+ # end
126
+
127
+ def managed_compose(file = "docker-compose.yml")
128
+ @managed_compose ||= {}
129
+
130
+ @managed_compose[file] ||= in_root do
131
+ next unless File.exist?(file)
132
+
133
+ parsed_yaml = YAML.load_file(file, aliases: true)
134
+ parsed_yaml if parsed_yaml["x-managed-by"] == "plutonium"
135
+ end
136
+ end
137
+
138
+ def add_compose_service(service, config, file = "docker-compose.yml")
139
+ docker_compose = managed_compose(file)
140
+ error "Docker compose is not managed by plutonium" unless docker_compose
141
+ error "#{service} is already added to compose" if docker_compose["services"].key?(service.to_s)
107
142
 
108
143
  in_root do
109
- compose_file = "docker-compose.yml"
110
- compose_definition = YAML.load_file(compose_file) if File.exist?(compose_file)
111
- compose_definition ||= {
112
- version: "3.7",
113
- services: {}
114
- }
115
- compose_definition.deep_stringify_keys!
116
-
117
- new_definition = YAML.load template_eval("docker-compose/#{source}.yml.tt")
118
- compose_definition.deep_merge! new_definition.deep_stringify_keys
119
-
120
- create_file compose_file, YAML.dump(compose_definition), force: true
144
+ insert_into_file file, indent(config, 2), after: /.*# additional services go here.*\n/
145
+ end
146
+ end
147
+
148
+ def add_compose_env(key, value, service = "x-app", file = "docker-compose.yml")
149
+ raise NotImplementedError, "only service: x-app is currently supported" unless service == "x-app"
150
+
151
+ docker_compose = managed_compose(file)
152
+ error "Docker compose is not managed by plutonium" unless docker_compose
153
+
154
+ in_root do
155
+ gsub_file file, "environment: {} # x-app", "environment: # #{service}"
156
+ gsub_file file, /.*#{key}:.*# #{service}.*\n/, ""
157
+ config = "#{key}: #{value} # #{service}\n"
158
+ insert_into_file file, indent(config, 4), after: /.*environment: # #{service}.*\n/
159
+ end
160
+ end
161
+
162
+ def add_compose_dependency(value, service = "x-app", file = "docker-compose.yml")
163
+ raise NotImplementedError, "only service: x-app is currently supported" unless service == "x-app"
164
+
165
+ docker_compose = managed_compose(file)
166
+ error "Docker compose is not managed by plutonium" unless docker_compose
167
+
168
+ in_root do
169
+ gsub_file file, "depends_on: [] # x-app", "depends_on: # #{service}"
170
+ gsub_file file, /.*- #{value}.*# #{service}.*\n/, ""
171
+ config = "- #{value} # #{service}\n"
172
+ insert_into_file file, indent(config, 4), after: /.*depends_on: # #{service}.*\n/
173
+ end
174
+ end
175
+
176
+ def add_docker_dependency(config, file = "Dockerfile.dev")
177
+ in_root do
178
+ insert_into_file file, "#{config}\n", after: /.*# Additional dependencies go here*\n\n/
121
179
  end
122
180
  end
123
181
 
@@ -283,6 +341,23 @@ module PlutoniumGenerators
283
341
  end
284
342
  end
285
343
 
344
+ #
345
+ # Insert the given directives into .dockerignore
346
+ #
347
+ # @param [String] *directives directives to ignore
348
+ #
349
+ # @return [void]
350
+ #
351
+ def dockerignore(*directives)
352
+ in_root do
353
+ # Doing this one by one so that duplication detection during insertion will work
354
+ directives.each do |directive|
355
+ log :dockerignore, directive
356
+ insert_into_file ".dockerignore", "#{directive}\n", verbose: false
357
+ end
358
+ end
359
+ end
360
+
286
361
  #
287
362
  # Similar to #run, this executes a command but returns both success and output
288
363
  #
@@ -313,6 +388,58 @@ module PlutoniumGenerators
313
388
  [success, output]
314
389
  end
315
390
 
391
+ def bin_directory
392
+ # Copy the directory and store the list of copied files
393
+ @copied_files = directory "bin"
394
+ # Change permissions of the copied files to make them executable
395
+ in_root do
396
+ @copied_files.each do |file|
397
+ file = file.split("/bin/")[1]
398
+ file = "bin/#{file}"
399
+ puts file
400
+ chmod file, "+x" if File.file?(file)
401
+ end
402
+ end
403
+ end
404
+
405
+ def bundle!
406
+ log :bundle, "install"
407
+
408
+ Bundler.with_unbundled_env do
409
+ run "bundle install", verbose: false
410
+ end
411
+ end
412
+
413
+ def bundle(*gems, **options)
414
+ gems = Array(gems).join " "
415
+ options = hash_to_cli_options options
416
+ cmd_args = "add #{gems} #{options}"
417
+
418
+ log :bundle, cmd_args
419
+ Bundler.with_unbundled_env do
420
+ run "bundle #{cmd_args}", verbose: false
421
+ end
422
+ end
423
+
424
+ def unbundle(*gems)
425
+ gems = Array(gems).join " "
426
+ cmd_args = "remove #{gems}"
427
+
428
+ log :bundle, cmd_args
429
+ Bundler.with_unbundled_env do
430
+ run "bundle remove #{Array(gems).join " "}", verbose: false
431
+ end
432
+ end
433
+
434
+ def add_required_env_vars(*vars)
435
+ vars = Array(vars).join " "
436
+ log :equired_env_vars, vars
437
+ in_root do
438
+ cmd = "required_env_vars += %w[#{vars}]\n"
439
+ insert_into_file "config/initializers/001_ensure_required_env.rb", cmd, after: /# Add additional env vars here.*\n/
440
+ end
441
+ end
442
+
316
443
  private
317
444
 
318
445
  #
@@ -351,16 +478,11 @@ module PlutoniumGenerators
351
478
  end
352
479
  end
353
480
 
354
- def bundle(*gems)
355
- Bundler.with_unbundled_env do
356
- run "bundle add #{Array(gems).join " "}"
357
- end
358
- end
359
-
360
- def unbundle(*gems)
361
- Bundler.with_unbundled_env do
362
- run "bundle remove #{Array(gems).join " "}"
363
- end
481
+ def hash_to_cli_options(hash)
482
+ hash.map do |key, value|
483
+ formatted_value = value.is_a?(Array) ? value.join(",") : value
484
+ "--#{key.to_s.tr("_", "-")}=#{formatted_value}"
485
+ end.join(" ")
364
486
  end
365
487
  end
366
488
  end
@@ -64,13 +64,13 @@ module PlutoniumGenerators
64
64
  @prompt ||= TTY::Prompt.new
65
65
  end
66
66
 
67
- def appname
68
- defined?(Rails.application) ? Rails.application.class.module_parent.name : "PlutoniumGenerators"
69
- end
67
+ # def appname
68
+ # defined?(Rails.application) ? Rails.application.class.module_parent.name : "PlutoniumGenerators"
69
+ # end
70
70
 
71
- def app_name
72
- appname.underscore
73
- end
71
+ # def app_name
72
+ # appname.underscore
73
+ # end
74
74
 
75
75
  def pug_installed?(feature, version: nil)
76
76
  installed_version = read_config(:installed, feature)
@@ -21,7 +21,7 @@ module PlutoniumGenerators
21
21
  protected
22
22
 
23
23
  def install!(feature)
24
- set_ruby_version! if root_pug?
24
+ # set_ruby_version! if root_pug?
25
25
 
26
26
  from_version = read_config(:installed, feature, default: "0.0.0")
27
27
  versions = methods.map do |m|
@@ -28,7 +28,7 @@ module Pu
28
28
  end
29
29
 
30
30
  def create_rodauth_app
31
- template "app/misc/account_rodauth_plugin.rb", "app/misc/#{account_path}_rodauth_plugin.rb"
31
+ template "app/rodauth/account_rodauth_plugin.rb", "app/rodauth/#{account_path}_rodauth_plugin.rb"
32
32
  end
33
33
 
34
34
  def configure_rodauth_plugin
@@ -36,16 +36,16 @@ module Pu
36
36
  plugin_name = indent(
37
37
  "configure ::#{account_path.classify}RodauthPlugin#{", :#{table_prefix}" unless primary?}\n", 2
38
38
  )
39
- gsub_file "app/misc/rodauth_app.rb", /.*# configure RodauthMain\n/, ""
40
- insert_into_file "app/misc/rodauth_app.rb", plugin_name, after: "# auth configuration\n"
39
+ gsub_file "app/rodauth/rodauth_app.rb", /.*# configure RodauthMain\n/, ""
40
+ insert_into_file "app/rodauth/rodauth_app.rb", plugin_name, after: "# auth configuration\n"
41
41
  end
42
42
  end
43
43
 
44
44
  def configure_rodauth_plugin_load_route
45
45
  in_root do
46
46
  route_config = indent("r.rodauth#{"(:#{table_prefix})" unless primary?}\n", 4)
47
- gsub_file "app/misc/rodauth_app.rb", /.*# r\.rodauth\n/, ""
48
- insert_into_file "app/misc/rodauth_app.rb", route_config, after: "# auth route configuration\n"
47
+ gsub_file "app/rodauth/rodauth_app.rb", /.*# r\.rodauth\n/, ""
48
+ insert_into_file "app/rodauth/rodauth_app.rb", route_config, after: "# auth route configuration\n"
49
49
  end
50
50
  end
51
51
 
@@ -54,15 +54,15 @@ module Pu
54
54
  plugin_config = indent(
55
55
  "rodauth#{"(:#{table_prefix})" unless primary?}.load_memory # autologin remembered #{table}\n", 4
56
56
  )
57
- gsub_file "app/misc/rodauth_app.rb", /.*# rodauth\.load_memory.*\n/, ""
57
+ gsub_file "app/rodauth/rodauth_app.rb", /.*# rodauth\.load_memory.*\n/, ""
58
58
 
59
59
  if remember?
60
- insert_into_file "app/misc/rodauth_app.rb", plugin_config, after: "# plugin route configuration\n"
60
+ insert_into_file "app/rodauth/rodauth_app.rb", plugin_config, after: "# plugin route configuration\n"
61
61
  else
62
- gsub_file "app/misc/rodauth_app.rb", plugin_config, ""
62
+ gsub_file "app/rodauth/rodauth_app.rb", plugin_config, ""
63
63
  in_root do
64
- unless File.read("app/misc/rodauth_app.rb").match?(/.*\.load_memory # autologin/)
65
- insert_into_file "app/misc/rodauth_app.rb", indent("# rodauth.load_memory # autologin remembered users\n", 4),
64
+ unless File.read("app/rodauth/rodauth_app.rb").match?(/.*\.load_memory # autologin/)
65
+ insert_into_file "app/rodauth/rodauth_app.rb", indent("# rodauth.load_memory # autologin remembered users\n", 4),
66
66
  after: "# plugin route configuration\n"
67
67
  end
68
68
  end
@@ -1,9 +1,12 @@
1
1
  require "rails/generators/base"
2
+ require "rails/generators/active_record/migration"
2
3
  require "securerandom"
3
4
 
4
5
  module Pu
5
6
  module Rodauth
6
7
  class InstallGenerator < ::Rails::Generators::Base
8
+ include ::ActiveRecord::Generators::Migration
9
+
7
10
  SEQUEL_ADAPTERS = {
8
11
  "postgresql" => (RUBY_ENGINE == "jruby") ? "postgresql" : "postgres",
9
12
  "mysql2" => (RUBY_ENGINE == "jruby") ? "mysql" : "mysql2",
@@ -31,8 +34,8 @@ module Pu
31
34
  end
32
35
 
33
36
  def create_rodauth_app
34
- template "app/misc/rodauth_app.rb"
35
- template "app/misc/rodauth_plugin.rb"
37
+ template "app/rodauth/rodauth_app.rb"
38
+ template "app/rodauth/rodauth_plugin.rb"
36
39
  end
37
40
 
38
41
  def add_dev_config
@@ -41,6 +44,10 @@ module Pu
41
44
  before: /^end/
42
45
  end
43
46
 
47
+ def create_install_migration
48
+ migration_template "db/migrate/install_rodauth.rb", "db/migrate/install_rodauth.rb" # , File.join(db_migrate_path, "#{migration_name}.rb")
49
+ end
50
+
44
51
  def show_instructions
45
52
  readme "INSTRUCTIONS" if behavior == :invoke
46
53
  end
@@ -12,6 +12,6 @@ create_table :<%= table_prefix %>_authentication_audit_logs do
12
12
  <% else -%>
13
13
  String :metadata
14
14
  <% end -%>
15
- index [:<%= table_prefix %>_id, :at], name: :audit_<%= table_prefix %>_at_idx
16
- index :at, name: :audit_at_idx
15
+ index [:<%= table_prefix %>_id, :at], name: :<%= table_prefix %>_audit_<%= table_prefix %>_at_idx
16
+ index :at, name: :<%= table_prefix %>_audit_at_idx
17
17
  end
@@ -69,7 +69,7 @@ module Pu
69
69
  private
70
70
 
71
71
  def plugin_filename
72
- "app/misc/#{account_path}_rodauth_plugin.rb"
72
+ "app/rodauth/#{account_path}_rodauth_plugin.rb"
73
73
  end
74
74
 
75
75
  def migration_name
@@ -38,8 +38,8 @@ class <%= account_path.classify %>RodauthPlugin < RodauthPlugin
38
38
  rails_account_model { <%= account_path.classify %> }
39
39
  <% if verify_account? -%>
40
40
 
41
- # Set password when verifying account.
42
- verify_account_set_password? false
41
+ # Set password password during create account.
42
+ # verify_account_set_password? false
43
43
  <% end -%>
44
44
 
45
45
  # Change some default param keys.
@@ -50,9 +50,6 @@ class RodauthPlugin < Rodauth::Rails::Auth
50
50
  # Store account status in an integer column without foreign key constraint.
51
51
  account_status_column :status
52
52
 
53
- # Set password when verifying account.
54
- # verify_account_set_password? false
55
-
56
53
  # Change some default param keys/labels.
57
54
  login_label "Email"
58
55
  login_param "email"
@@ -0,0 +1,5 @@
1
+ class InstallRodauth < ActiveRecord::Migration[<%= ActiveRecord::Migration.current_version %>]
2
+ def change
3
+ enable_extension "citext"
4
+ end
5
+ end
@@ -0,0 +1,61 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../../lib/plutonium_generators"
4
+
5
+ module Pu
6
+ module Service
7
+ class PostgresGenerator < Rails::Generators::Base
8
+ include PlutoniumGenerators::Generator
9
+
10
+ source_root File.expand_path("templates", __dir__)
11
+
12
+ desc "Set up postgres for project"
13
+
14
+ def start
15
+ bundle "goldiloader"
16
+ template "database.yml", "config/database.yml", force: true
17
+ bin_directory
18
+ add_compose_env :POSTGRES_HOST, service
19
+ add_compose_dependency service
20
+ add_compose_service service, compose_config
21
+ add_docker_dependency docker_deps
22
+ rescue => e
23
+ exception "#{self.class} failed:", e
24
+ end
25
+
26
+ private
27
+
28
+ def service
29
+ :postgres
30
+ end
31
+
32
+ def compose_config
33
+ <<~COMPOSE
34
+ postgres:
35
+ image: postgres:15 # postgres
36
+ # postgres properties
37
+ environment: # postgres
38
+ POSTGRES_MULTIPLE_DATABASES: #{db_prefix}_development,#{db_prefix}_test # postgres
39
+ POSTGRES_USER: postgres # postgres
40
+ POSTGRES_PASSWORD: postgres # postgres
41
+ volumes: # postgres
42
+ - "./.volumes/postgres/data:/var/lib/postgresql/data" # postgres
43
+ - "./bin/initdb.d:/docker-entrypoint-initdb.d" # postgres
44
+ COMPOSE
45
+ end
46
+
47
+ def docker_deps
48
+ <<~DEPS
49
+ # Install packages needed for postgres
50
+ RUN apt-get update -qq && \\
51
+ apt-get install --no-install-recommends -y curl postgresql-client && \\
52
+ rm -rf /var/lib/apt/lists /var/cache/apt/archives
53
+ DEPS
54
+ end
55
+
56
+ def db_prefix
57
+ Plutonium.application_name.underscore
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,22 @@
1
+ #!/bin/bash
2
+
3
+ set -e
4
+ set -u
5
+
6
+ function create_user_and_database() {
7
+ local database=$1
8
+ echo " Creating user and database '$database'"
9
+ psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" <<-EOSQL
10
+ CREATE USER $database;
11
+ CREATE DATABASE $database;
12
+ GRANT ALL PRIVILEGES ON DATABASE $database TO $database;
13
+ EOSQL
14
+ }
15
+
16
+ if [ -n "$POSTGRES_MULTIPLE_DATABASES" ]; then
17
+ echo "Multiple database creation requested: $POSTGRES_MULTIPLE_DATABASES"
18
+ for db in $(echo $POSTGRES_MULTIPLE_DATABASES | tr ',' ' '); do
19
+ create_user_and_database $db
20
+ done
21
+ echo "Multiple databases created"
22
+ fi
@@ -0,0 +1,93 @@
1
+ # PostgreSQL. Versions 9.3 and up are supported.
2
+ #
3
+ # Install the pg driver:
4
+ # gem install pg
5
+ # On macOS with Homebrew:
6
+ # gem install pg -- --with-pg-config=/usr/local/bin/pg_config
7
+ # On Windows:
8
+ # gem install pg
9
+ # Choose the win32 build.
10
+ # Install PostgreSQL and put its /bin directory on your path.
11
+ #
12
+ # Configure Using Gemfile
13
+ # gem "pg"
14
+ #
15
+ default: &default
16
+ adapter: postgresql
17
+ encoding: unicode
18
+ # For details on connection pooling, see Rails configuration guide
19
+ # https://guides.rubyonrails.org/configuring.html#database-pooling
20
+ pool: <%%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
21
+ # Timeouts
22
+ connect_timeout: 1
23
+ checkout_timeout: 1
24
+ variables:
25
+ statement_timeout: <%%= ENV["STATEMENT_TIMEOUT"] || "15s" %> # or ms, min, etc
26
+
27
+ local: &local
28
+ host: <%%= ENV["POSTGRES_HOST"] %>
29
+ port: 5432
30
+ username: postgres
31
+ password: postgres
32
+
33
+ development:
34
+ <<: [*default, *local]
35
+ database: <%= db_prefix %>_development
36
+
37
+ # The specified database role being used to connect to PostgreSQL.
38
+ # To create additional roles in PostgreSQL see `$ createuser --help`.
39
+ # When left blank, PostgreSQL will use the default role. This is
40
+ # the same name as the operating system user running Rails.
41
+ #username: <%= db_prefix %>
42
+
43
+ # The password associated with the PostgreSQL role (username).
44
+ #password:
45
+
46
+ # Connect on a TCP socket. Omitted by default since the client uses a
47
+ # domain socket that doesn't need configuration. Windows does not have
48
+ # domain sockets, so uncomment these lines.
49
+ #host: localhost
50
+
51
+ # The TCP port the server listens on. Defaults to 5432.
52
+ # If your server runs on a different port number, change accordingly.
53
+ #port: 5432
54
+
55
+ # Schema search path. The server defaults to $user,public
56
+ #schema_search_path: myapp,sharedapp,public
57
+
58
+ # Minimum log levels, in increasing order:
59
+ # debug5, debug4, debug3, debug2, debug1,
60
+ # log, notice, warning, error, fatal, and panic
61
+ # Defaults to warning.
62
+ #min_messages: notice
63
+
64
+ # Warning: The database defined as "test" will be erased and
65
+ # re-generated from your development database when you run "rake".
66
+ # Do not set this db to the same as development or production.
67
+ test:
68
+ <<: [*default, *local]
69
+ database: <%= db_prefix %>_test
70
+
71
+ # As with config/credentials.yml, you never want to store sensitive information,
72
+ # like your database password, in your source code. If your source code is
73
+ # ever seen by anyone, they now have access to your database.
74
+ #
75
+ # Instead, provide the password or a full connection URL as an environment
76
+ # variable when you boot the app. For example:
77
+ #
78
+ # DATABASE_URL="postgres://myuser:mypass@localhost/somedatabase"
79
+ #
80
+ # If the connection URL is provided in the special DATABASE_URL environment
81
+ # variable, Rails will automatically merge its configuration values on top of
82
+ # the values provided in this file. Alternatively, you can specify a connection
83
+ # URL environment variable explicitly:
84
+ #
85
+ # production:
86
+ # url: <%%= ENV["MY_APP_DATABASE_URL"] %>
87
+ #
88
+ # Read https://guides.rubyonrails.org/configuring.html#configuring-a-database
89
+ # for a full overview on how database connection configuration can be specified.
90
+ #
91
+ production:
92
+ <<: *default
93
+ database: <%= db_prefix %>_production
@@ -0,0 +1,62 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../../lib/plutonium_generators"
4
+
5
+ module Pu
6
+ module Service
7
+ class SidekiqGenerator < Rails::Generators::Base
8
+ include PlutoniumGenerators::Generator
9
+
10
+ source_root File.expand_path("templates", __dir__)
11
+
12
+ desc "Set up sidekiq for project"
13
+
14
+ def start
15
+ bundle "sidekiq"
16
+ bundle "sidekiq-failures"
17
+ directory "app"
18
+ directory "config"
19
+
20
+ in_root do
21
+ insert_into_file "app/jobs/application_job.rb", "\n sidekiq_options failures: :exhausted\n", before: /^end/
22
+ end
23
+
24
+ add_compose_env :REDIS_QUEUE_URL, "redis://redis-queue/0"
25
+ add_required_env_vars :REDIS_QUEUE_URL
26
+ add_compose_dependency redis_service
27
+ add_compose_service service, sidekiq_compose_config
28
+ add_compose_service redis_service, redis_compose_config
29
+ rescue => e
30
+ exception "#{self.class} failed:", e
31
+ end
32
+
33
+ private
34
+
35
+ def service
36
+ :sidekiq
37
+ end
38
+
39
+ def redis_service
40
+ :"redis-queue"
41
+ end
42
+
43
+ def sidekiq_compose_config
44
+ <<~COMPOSE
45
+ sidekiq:
46
+ <<: *app # sidekiq
47
+ command: /bin/sh -c "bundle && sidekiq" # sidekiq
48
+ # sidekiq properties
49
+ COMPOSE
50
+ end
51
+
52
+ def redis_compose_config
53
+ <<~COMPOSE
54
+ redis-queue:
55
+ image: redis # redis-queue
56
+ command: bash -c "redis-server --maxmemory-policy noeviction" # redis-queue
57
+ # redis-queue properties
58
+ COMPOSE
59
+ end
60
+ end
61
+ end
62
+ end
File without changes
@@ -0,0 +1,5 @@
1
+ class SidekiqJob
2
+ include Sidekiq::Job
3
+
4
+ sidekiq_options failures: :exhausted
5
+ end