Skip to content

Commit

Permalink
Move to Ruby 3 and Sidekiq 7.
Browse files Browse the repository at this point in the history
  • Loading branch information
phlegx committed May 5, 2023
1 parent 1b22b15 commit 2baeedb
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 50 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ jobs:
labels: ${{ steps.meta.outputs.labels }}
build-args: |
RUBY_VERSION=slim-buster
SIDEKIQ_VERSION=~>6.0
SIDEKIQ_VERSION=~>7.0
SIDEKIQ_CRON_VERSION=~>1.0
PUMA_VERSION=~>5.0
PUMA_VERSION=~>6.0
18 changes: 9 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Sidekiq Web
#
# Description: Dockerfile for standalone Sidekiq Web with Puma.
# Author: Egon Zemmer, Phlegx Systems OG
# Author: Egon Zemmer, Phlegx Systems Technologies GmbH

# Set base image.
ARG RUBY_VERSION=latest
Expand All @@ -15,15 +15,15 @@ RUN mkdir -p /usr/src/sidekiq
WORKDIR /usr/src/sidekiq

# Add gems.
ARG SIDEKIQ_VERSION=~>6.0
ARG SIDEKIQ_VERSION=~>7.0
ARG SIDEKIQ_CRON_VERSION=~>1.0
ARG PUMA_VERSION=~>5.0
RUN echo "source 'https://rubygems.org';\
gem 'hiredis'; \
gem 'em-synchrony'; \
gem 'sidekiq', '$SIDEKIQ_VERSION';\
gem 'sidekiq-cron', '$SIDEKIQ_CRON_VERSION';\
gem 'redis-namespace'; \
ARG PUMA_VERSION=~>6.0
RUN echo "source 'https://rubygems.org'; \
gem 'rackup'; \
gem 'rack-session'; \
gem 'hiredis-client'; \
gem 'sidekiq', '$SIDEKIQ_VERSION'; \
gem 'sidekiq-cron', '$SIDEKIQ_CRON_VERSION'; \
gem 'puma', '$PUMA_VERSION'" > Gemfile

# Install gems.
Expand Down
20 changes: 9 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Docker Hub Repo: https://hub.docker.com/r/phlegx/sidekiq-web/
* Uses connection pool for Redis connections
* Redis configuration support
* Redis Sentinel configuration support
* Redis driver ruby, hiredis and synchrony support
* Redis driver ruby and hiredis support
* Sidekiq Cron support
* HTTP Basic Auth support

Expand All @@ -22,10 +22,10 @@ Docker Hub Repo: https://hub.docker.com/r/phlegx/sidekiq-web/

```
docker build \
--build-arg RUBY_VERSION=2.7.5-slim-buster \
--build-arg SIDEKIQ_VERSION=6.4.1 \
--build-arg SIDEKIQ_CRON_VERSION=1.2.0 \
--build-arg PUMA_VERSION=5.6.4 \
--build-arg RUBY_VERSION=3.2.2-slim-buster \
--build-arg SIDEKIQ_VERSION=7.1.0 \
--build-arg SIDEKIQ_CRON_VERSION=1.10.0 \
--build-arg PUMA_VERSION=6.2.2 \
-t sidekiq-web .
```

Expand Down Expand Up @@ -59,10 +59,9 @@ docker run \
-p 3001:9292 \
-e REDIS_URI=host:6379 \
-e REDIS_DB=1 \
-e REDIS_NAMESPACE=test \
-e REDIS_POOL_SIZE=5 \
-e REDIS_PASSWORD=password \
-e REDIS_DRIVER=synchrony \
-e REDIS_DRIVER=ruby \
sidekiq-web
```

Expand All @@ -76,9 +75,8 @@ docker run \
-e REDIS_SENTINEL_MASTER_URI=urimaster \
-e REDIS_SENTINEL_PASSWORD=password \
-e REDIS_DB=1 \
-e REDIS_NAMESPACE=test \
-e REDIS_POOL_SIZE=5 \
-e REDIS_DRIVER=synchrony \
-e REDIS_DRIVER=ruby \
sidekiq-web
```

Expand Down Expand Up @@ -117,7 +115,7 @@ Example compose file:
version: '3'
services:
sidekiq-web:
image: phlegx/sidekiq-web:r2.7-s6
image: phlegx/sidekiq-web:r3.2-s7
environment:
REDIS_URI: host:6379
REDIS_PASSWORD: password
Expand All @@ -144,4 +142,4 @@ services:

The MIT License

Copyright (c) 2022 Phlegx Systems Technologies GmbH
Copyright (c) 2023 Phlegx Systems Technologies GmbH
20 changes: 8 additions & 12 deletions config.ru
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
# Redis Config
#
# Description: Rackup to get Sidekiq Web running with session cookie and HTTP basic auth.
# Author: Egon Zemmer, Phlegx Systems OG
# Author: Egon Zemmer, Phlegx Systems Technologies GmbH
require 'securerandom'
require 'rack'
require 'rack/session'
require 'hiredis-client'
require 'sidekiq'
require 'sidekiq/web'
if ENV['SIDEKIQ_CRON'] && ENV['SIDEKIQ_CRON'] == 'true'
Expand All @@ -17,21 +19,15 @@ require './redis_config'
# Add Rack session cookie secret.
File.open('.session.key', 'w') { |f| f.write(SecureRandom.hex(32)) }
use Rack::Session::Cookie, secret: File.read('.session.key'), same_site: true, max_age: 86_400
Sidekiq::Web.set :session_secret, File.read('.session.key')

# Create Redis instance.
redis = proc {
RedisConfig.config(
db: ENV['REDIS_DB'].to_i,
namespace: ENV['REDIS_NAMESPACE']
)
}
# Ser Redis default driver.
RedisClient.default_driver = ENV.fetch('REDIS_DRIVER', :hiredis).to_sym

# Configure Sidekiq client with Redis instance.
Sidekiq.configure_client do |config|
config.redis = ConnectionPool.new(
size: ENV['REDIS_POOL_SIZE'].nil? ? 1 : ENV['REDIS_POOL_SIZE'].to_i,
&redis
config.redis = RedisConfig.config(
db: ENV.fetch('REDIS_DB', 0).to_i,
size: ENV.fetch('REDIS_POOL_SIZE', 5).to_i
)
end

Expand Down
24 changes: 8 additions & 16 deletions redis_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
# Redis Config
#
# Description: Redis configuration with sentinel configuration options.
# Author: Egon Zemmer, Phlegx Systems OG
require 'redis-namespace'
# Author: Egon Zemmer, Phlegx Systems Technologies GmbH

module RedisConfig
class << self
Expand All @@ -19,15 +18,11 @@ def config(options = {})
private

def single_config(options = {})
namespace = options.delete(:namespace)
uri = "#{ENV['REDIS_URI']}/#{options.delete(:db).to_i}"
redis = Redis.new(
driver: ENV.fetch('REDIS_DRIVER', :hiredis).to_sym,
url: "redis://#{uri}",
{
url: "redis://#{ENV['REDIS_URI']}/#{options.delete(:db).to_i}",
password: ENV['REDIS_PASSWORD'],
**options
)
namespace ? Redis::Namespace.new(namespace, redis: redis) : redis
}
end

def sentinel_config(options = {})
Expand All @@ -38,16 +33,13 @@ def sentinel_config(options = {})
{ host: host.strip, port: port, password: ENV['REDIS_SENTINEL_PASSWORD'] }
end

namespace = options.delete(:namespace)
redis = Redis.new(
driver: ENV.fetch('REDIS_DRIVER', :hiredis).to_sym,
url: "redis://#{ENV['REDIS_SENTINEL_MASTER_URI']}",
{
sentinels: sentinels,
password: ENV['REDIS_SENTINEL_PASSWORD'],
role: :master,
url: "redis://#{ENV['REDIS_SENTINEL_MASTER_URI']}",
password: ENV['REDIS_SENTINEL_PASSWORD'],
**options
)
namespace ? Redis::Namespace.new(namespace, redis: redis) : redis
}
end
end
end

0 comments on commit 2baeedb

Please sign in to comment.