Skip to content

Commit

Permalink
add support for solid_queue
Browse files Browse the repository at this point in the history
  • Loading branch information
rubys committed Jan 6, 2024
1 parent b348b69 commit 9b61204
Show file tree
Hide file tree
Showing 6 changed files with 153 additions and 4 deletions.
12 changes: 10 additions & 2 deletions lib/generators/dockerfile_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,10 @@ def using_sidekiq?
@gemfile.include?("sidekiq")
end

def using_solidq?
@gemfile.include?("solid_queue")
end

def parallel?
(using_node? || using_bun?) && options.parallel
end
Expand Down Expand Up @@ -1131,15 +1135,19 @@ def procfile

def fly_processes
return unless File.exist? "fly.toml"
return unless using_sidekiq?
return unless using_sidekiq? or using_solidq?

if procfile.size > 1
list = { "app" => "foreman start --procfile=Procfile.prod" }
else
list = { "app" => procfile.values.first }
end

list["sidekiq"] = "bundle exec sidekiq"
if using_sidekiq?
list["sidekiq"] = "bundle exec sidekiq"
elsif using_solidq?
list["solidq"] = "bundle exec rake solid_queue:start"
end

list
end
Expand Down
8 changes: 6 additions & 2 deletions lib/generators/templates/docker-compose.yml.erb
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,15 @@ services:
redis-db:
image: redis
<% end -%>
<% if using_sidekiq? and deploy_database != 'sqlite3' -%>
<% if (using_sidekiq? or using_solidq?) and deploy_database != 'sqlite3' -%>
sidekiq:
<%= using_sidekiq? ? "sidekiq" : "solidq" %>:
build: .
<% if using_sidekiq? -%>
command: bundle exec sidekiq
<% else -%>
command: bundle exec rake solid_queue:start
<% end -%>
environment:
- RAILS_MASTER_KEY=$RAILS_MASTER_KEY
- REDIS_URL=redis://redis-db:6379
Expand Down
68 changes: 68 additions & 0 deletions test/results/solid_queue/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# 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 libpq-dev

# Install application gems
COPY --link 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 --link . .

# 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 postgresql-client && \
rm -rf /var/lib/apt/lists /var/cache/apt/archives

# Copy built artifacts: gems, application
COPY --from=build /usr/local/bundle /usr/local/bundle
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 && \
chown -R rails:rails db log storage tmp
USER rails:rails

# Entrypoint prepares the database.
ENTRYPOINT ["/rails/bin/docker-entrypoint"]

# Start the server by default, this can be overwritten at runtime
EXPOSE 3000
44 changes: 44 additions & 0 deletions test/results/solid_queue/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
version: "3.8"
services:
web:
build:
context: .
args:
UID: ${UID:-1000}
GID: ${GID:-${UID:-1000}}
ports:
- "3000:3000"
environment:
- RAILS_MASTER_KEY=$RAILS_MASTER_KEY
- DATABASE_URL=postgres://root:password@postgres-db/
depends_on:
postgres-db:
condition: service_healthy

postgres-db:
image: postgres
environment:
POSTGRES_USER: root
POSTGRES_PASSWORD: password
volumes:
- ./tmp/db:/var/lib/postgresql/data
ports:
- "5432:5432"
healthcheck:
test: pg_isready
interval: 2s
timeout: 5s
retries: 30

solidq:
build: .
command: bundle exec rake solid_queue:start
environment:
- RAILS_MASTER_KEY=$RAILS_MASTER_KEY
- REDIS_URL=redis://redis-db:6379
- DATABASE_URL=postgres://root:password@postgres-db/
depends_on:
redis-db:
condition: service_started
postgres-db:
condition: service_healthy
4 changes: 4 additions & 0 deletions test/results/solid_queue/fly.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

[processes]
app = "./bin/rails server"
solidq = "bundle exec rake solid_queue:start"
21 changes: 21 additions & 0 deletions test/test_solidq.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# frozen_string_literal: true

require "fileutils"

require_relative "base"

class TestSolidQueue < TestBase
@rails_options = "--database=postgresql"
@generate_options = "--compose"

def app_setup
system "bundle add solid_queue"
FileUtils.touch "fly.toml"
end

def test_solidq
check_dockerfile
check_toml
check_compose
end
end

0 comments on commit 9b61204

Please sign in to comment.