diff --git a/lib/generators/dockerfile_generator.rb b/lib/generators/dockerfile_generator.rb index 5ad0f94..ff848e8 100644 --- a/lib/generators/dockerfile_generator.rb +++ b/lib/generators/dockerfile_generator.rb @@ -1212,23 +1212,29 @@ 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? and deploy_database == "sqlite3" + base.merge(solidq: "bundle exec rake solid_queue:start") + else + base + end end def using_thruster? @@ -1248,7 +1254,11 @@ def fly_processes if using_sidekiq? list["sidekiq"] = "bundle exec sidekiq" elsif using_solidq? - list["solidq"] = "bundle exec rake solid_queue:start" + if deploy_database == "sqlite3" + return if list.size <= 1 + else + list["solidq"] = "bundle exec rake solid_queue:start" + end end list diff --git a/test/results/solid_queue/Dockerfile b/test/results/solid_queue_postgres/Dockerfile similarity index 100% rename from test/results/solid_queue/Dockerfile rename to test/results/solid_queue_postgres/Dockerfile diff --git a/test/results/solid_queue/docker-compose.yml b/test/results/solid_queue_postgres/docker-compose.yml similarity index 100% rename from test/results/solid_queue/docker-compose.yml rename to test/results/solid_queue_postgres/docker-compose.yml diff --git a/test/results/solid_queue/fly.toml b/test/results/solid_queue_postgres/fly.toml similarity index 100% rename from test/results/solid_queue/fly.toml rename to test/results/solid_queue_postgres/fly.toml diff --git a/test/results/solid_queue_sqlite3/Dockerfile b/test/results/solid_queue_sqlite3/Dockerfile new file mode 100644 index 0000000..0b57c02 --- /dev/null +++ b/test/results/solid_queue_sqlite3/Dockerfile @@ -0,0 +1,82 @@ +# syntax = docker/dockerfile:1 + +# Make sure RUBY_VERSION matches the Ruby version in .ruby-version and Gemfile +ARG RUBY_VERSION=xxx +FROM ruby:$RUBY_VERSION-slim AS base + +# Rails app lives here +WORKDIR /rails + +# Set production environment +ENV BUNDLE_DEPLOYMENT="1" \ + BUNDLE_PATH="/usr/local/bundle" \ + BUNDLE_WITHOUT="development:test" \ + RAILS_ENV="production" + +# Update gems and bundler +RUN gem update --system --no-document && \ + gem install -N bundler + + +# Throw-away build stage to reduce size of final image +FROM base AS build + +# Install packages needed to build gems +RUN apt-get update -qq && \ + apt-get install --no-install-recommends -y build-essential pkg-config + +# Install application gems +COPY Gemfile Gemfile.lock ./ +RUN bundle install && \ + bundle exec bootsnap precompile --gemfile && \ + rm -rf ~/.bundle/ "${BUNDLE_PATH}"/ruby/*/cache "${BUNDLE_PATH}"/ruby/*/bundler/gems/*/.git + +# Copy application code +COPY . . + +# Precompile bootsnap code for faster boot times +RUN bundle exec bootsnap precompile app/ lib/ + +# Precompiling assets for production without requiring secret RAILS_MASTER_KEY +RUN SECRET_KEY_BASE_DUMMY=1 ./bin/rails assets:precompile + + +# Final stage for app image +FROM base + +# Install packages needed for deployment +RUN apt-get update -qq && \ + apt-get install --no-install-recommends -y curl libsqlite3-0 ruby-foreman && \ + 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 && \ + mkdir /data && \ + chown -R rails:rails db log storage tmp /data +USER rails:rails + +# Deployment options +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 +VOLUME /data +CMD ["foreman", "start", "--procfile=Procfile.prod"] diff --git a/test/results/solid_queue_sqlite3/docker-compose.yml b/test/results/solid_queue_sqlite3/docker-compose.yml new file mode 100644 index 0000000..fc66e86 --- /dev/null +++ b/test/results/solid_queue_sqlite3/docker-compose.yml @@ -0,0 +1,22 @@ +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 new file mode 100644 index 0000000..c1a2c8c --- /dev/null +++ b/test/results/solid_queue_sqlite3/fly.toml @@ -0,0 +1,8 @@ +[mounts] + source="data" + destination="/data" + +[[statics]] + guest_path = "/rails/public" + url_prefix = "/" + diff --git a/test/test_solidq.rb b/test/test_solidq_postgres.rb similarity index 90% rename from test/test_solidq.rb rename to test/test_solidq_postgres.rb index 840ab9f..46af4d6 100644 --- a/test/test_solidq.rb +++ b/test/test_solidq_postgres.rb @@ -4,7 +4,7 @@ require_relative "base" -class TestSolidQueue < TestBase +class TestSolidQueuePostgres < TestBase @rails_options = "--database=postgresql" @generate_options = "--compose" diff --git a/test/test_solidq_sqlite3.rb b/test/test_solidq_sqlite3.rb new file mode 100644 index 0000000..2ef6da6 --- /dev/null +++ b/test/test_solidq_sqlite3.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +require "fileutils" + +require_relative "base" + +class TestSolidQueueSqlite3 < TestBase + @rails_options = "--database=sqlite3" + @generate_options = "--compose" + + def app_setup + system "bundle add solid_queue" + FileUtils.touch "fly.toml" + IO.write "app/jobs/DummyJob.rb", "class DummyJob < ApplicationJob; end" + end + + def test_solidq + check_dockerfile + check_toml + check_compose + end +end