Skip to content

Commit

Permalink
feat(background_processor): include redis docker configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
jgmontoya committed Dec 8, 2020
1 parent 4aa2414 commit 69803f2
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
3 changes: 1 addition & 2 deletions lib/potassium/assets/redis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
development: &default
host: <%= ENV["BOXEN_REDIS_HOST"] || ENV["REDIS_HOST"] || "127.0.0.1" %>
port: <%= ENV["BOXEN_REDIS_PORT"] || ENV["REDIS_PORT"] || 6379 %>
url: <%= ENV.fetch("REDIS_URL") %>

test:
<<: *default
Expand Down
31 changes: 31 additions & 0 deletions lib/potassium/recipes/background_processor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ def ask

def create
add_sidekiq if get(:background_processor)
add_docker_compose_redis_config
set_redis_dot_env
end

def install
Expand All @@ -26,6 +28,35 @@ def installed?
gem_exists?(/sidekiq/)
end

private

def add_docker_compose_redis_config
compose = DockerHelpers.new('docker-compose.yml')

service_definition =
<<~YAML
image: redis
ports:
- 6379
volumes:
- redis_data:/data
YAML

compose.add_service('redis', service_definition)
compose.add_volume('redis_data')
end

def set_redis_dot_env
append_to_file(
'.env.development',
<<~TEXT
REDIS_HOST=127.0.0.1
REDIS_PORT=$(make services-port SERVICE=redis PORT=6379)
REDIS_URL=redis://${REDIS_HOST}:${REDIS_PORT}/1
TEXT
)
end

def add_sidekiq
gather_gem("sidekiq")
add_adapters("sidekiq")
Expand Down

0 comments on commit 69803f2

Please sign in to comment.