diff --git a/.rubocop.yml b/.rubocop.yml index fa00f06..170eb2e 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -72,6 +72,8 @@ Layout/EndOfLine: Layout/EmptyLineAfterMagicComment: Enabled: true + Exclude: + - '**/test/**/*' Layout/EmptyLinesAroundAccessModifier: Enabled: true @@ -158,6 +160,7 @@ Style/FrozenStringLiteralComment: - 'activestorage/db/update_migrate/**/*.rb' - 'actionmailbox/db/migrate/**/*.rb' - 'actiontext/db/migrate/**/*.rb' + - 'test/**/*.rb' Style/MapToHash: Enabled: true diff --git a/lib/generators/dockerfile_generator.rb b/lib/generators/dockerfile_generator.rb index e25b4cc..3549d35 100644 --- a/lib/generators/dockerfile_generator.rb +++ b/lib/generators/dockerfile_generator.rb @@ -336,6 +336,10 @@ def generate_app force: File.exist?("fly.toml") end + if using_solidq? && deploy_database == "sqlite3" && File.exist?("config/puma.rb") + append_to_file "config/puma.rb", "\n# Run the Solid Queue's supervisor\nplugin :solid_queue\n" + end + if using_litefs? template "litefs.yml.erb", "config/litefs.yml" @@ -1212,29 +1216,23 @@ def dbprep_command def procfile if using_passenger? - base = { + { nginx: "nginx" } elsif options.nginx? - base = { + { nginx: '/usr/sbin/nginx -g "daemon off;"', rails: "./bin/rails server -p 3001" } elsif using_thruster? - base = { + { rails: "bundle exec thrust ./bin/rails server" } else - base = { + { rails: "./bin/rails server" } end - - if using_solidq? && (deploy_database == "sqlite3") - base.merge(solidq: "bundle exec rake solid_queue:start") - else - base - end end def using_thruster? diff --git a/test/base.rb b/test/base.rb index ef7718c..5251c2a 100644 --- a/test/base.rb +++ b/test/base.rb @@ -120,6 +120,16 @@ def check_database_config assert_equal expected, results end + def check_puma + results = IO.read("config/puma.rb") + + IO.write("#{@results}/puma.rb", results) if @capture + + expected = IO.read("#{@results}/puma.rb") + + assert_equal expected, results + end + def teardown return if ENV["TEST_KEEP"] Dir.chdir ".." diff --git a/test/results/solid_queue_sqlite3/Dockerfile b/test/results/solid_queue_sqlite3/Dockerfile index 0b57c02..2b434da 100644 --- a/test/results/solid_queue_sqlite3/Dockerfile +++ b/test/results/solid_queue_sqlite3/Dockerfile @@ -46,23 +46,19 @@ FROM base # Install packages needed for deployment RUN apt-get update -qq && \ - apt-get install --no-install-recommends -y curl libsqlite3-0 ruby-foreman && \ + apt-get install --no-install-recommends -y curl libsqlite3-0 && \ rm -rf /var/lib/apt/lists /var/cache/apt/archives -RUN gem install foreman - # Copy built artifacts: gems, application COPY --from=build "${BUNDLE_PATH}" "${BUNDLE_PATH}" COPY --from=build /rails /rails # Run and own only the runtime files as a non-root user for security -ARG UID=xxx \ - GID=1000 -RUN groupadd -f -g $GID rails && \ - useradd -u $UID -g $GID rails --create-home --shell /bin/bash && \ +RUN groupadd --system --gid 1000 rails && \ + useradd rails --uid 1000 --gid 1000 --create-home --shell /bin/bash && \ mkdir /data && \ - chown -R rails:rails db log storage tmp /data -USER rails:rails + chown -R 1000:1000 db log storage tmp /data +USER 1000:1000 # Deployment options ENV DATABASE_URL="sqlite3:///data/production.sqlite3" @@ -70,13 +66,7 @@ ENV DATABASE_URL="sqlite3:///data/production.sqlite3" # Entrypoint prepares the database. ENTRYPOINT ["/rails/bin/docker-entrypoint"] -# Build a Procfile for production use -COPY <<-"EOF" /rails/Procfile.prod -rails: ./bin/rails server -solidq: bundle exec rake solid_queue:start -EOF - # Start the server by default, this can be overwritten at runtime -EXPOSE 3000 +EXPOSE 80 VOLUME /data -CMD ["foreman", "start", "--procfile=Procfile.prod"] +CMD ["bundle", "exec", "thrust", "./bin/rails", "server"] diff --git a/test/results/solid_queue_sqlite3/docker-compose.yml b/test/results/solid_queue_sqlite3/docker-compose.yml deleted file mode 100644 index fc66e86..0000000 --- a/test/results/solid_queue_sqlite3/docker-compose.yml +++ /dev/null @@ -1,22 +0,0 @@ -version: "3.8" - -services: - web: - build: - context: . - args: - UID: ${UID:-1000} - GID: ${GID:-${UID:-1000}} - volumes: - - ./log:/rails/log - - ./storage:/rails/storage - ports: - - "3000:3000" - environment: - secrets: - - source: master_key - target: /rails/config/master.key - -secrets: - master_key: - file: ./config/master.key \ No newline at end of file diff --git a/test/results/solid_queue_sqlite3/fly.toml b/test/results/solid_queue_sqlite3/fly.toml index c1a2c8c..a7acbd4 100644 --- a/test/results/solid_queue_sqlite3/fly.toml +++ b/test/results/solid_queue_sqlite3/fly.toml @@ -2,7 +2,3 @@ source="data" destination="/data" -[[statics]] - guest_path = "/rails/public" - url_prefix = "/" - diff --git a/test/results/solid_queue_sqlite3/puma.rb b/test/results/solid_queue_sqlite3/puma.rb new file mode 100644 index 0000000..7efc824 --- /dev/null +++ b/test/results/solid_queue_sqlite3/puma.rb @@ -0,0 +1,44 @@ +# This configuration file will be evaluated by Puma. The top-level methods that +# are invoked here are part of Puma's configuration DSL. For more information +# about methods provided by the DSL, see https://puma.io/puma/Puma/DSL.html. +# +# Puma starts a configurable number of processes (workers) and each process +# serves each request in a thread from an internal thread pool. +# +# You can control the number of workers using ENV["WEB_CONCURRENCY"]. You +# should only set this value when you want to run 2 or more workers. The +# default is already 1. +# +# The ideal number of threads per worker depends both on how much time the +# application spends waiting for IO operations and on how much you wish to +# prioritize throughput over latency. +# +# As a rule of thumb, increasing the number of threads will increase how much +# traffic a given process can handle (throughput), but due to CRuby's +# Global VM Lock (GVL) it has diminishing returns and will degrade the +# response time (latency) of the application. +# +# The default is set to 3 threads as it's deemed a decent compromise between +# throughput and latency for the average Rails application. +# +# Any libraries that use a connection pool or another resource pool should +# be configured to provide at least as many connections as the number of +# threads. This includes Active Record's `pool` parameter in `database.yml`. +threads_count = ENV.fetch("RAILS_MAX_THREADS", 3) +threads threads_count, threads_count + +# Specifies the `port` that Puma will listen on to receive requests; default is 3000. +port ENV.fetch("PORT", 3000) + +# Allow puma to be restarted by `bin/rails restart` command. +plugin :tmp_restart + +# Run the Solid Queue supervisor inside of Puma for single-server deployments +plugin :solid_queue if ENV["SOLID_QUEUE_IN_PUMA"] + +# Specify the PID file. Defaults to tmp/pids/server.pid in development. +# In other environments, only set the PID file if requested. +pidfile ENV["PIDFILE"] if ENV["PIDFILE"] + +# Run the Solid Queue's supervisor +plugin :solid_queue diff --git a/test/test_solidq_sqlite3.rb b/test/test_solidq_sqlite3.rb index 2ef6da6..f5d8da5 100644 --- a/test/test_solidq_sqlite3.rb +++ b/test/test_solidq_sqlite3.rb @@ -6,7 +6,6 @@ class TestSolidQueueSqlite3 < TestBase @rails_options = "--database=sqlite3" - @generate_options = "--compose" def app_setup system "bundle add solid_queue" @@ -17,6 +16,6 @@ def app_setup def test_solidq check_dockerfile check_toml - check_compose + check_puma end end