diff --git a/lib/potassium/assets/redis.yml b/lib/potassium/assets/redis.yml index 91d774a2..533b6795 100644 --- a/lib/potassium/assets/redis.yml +++ b/lib/potassium/assets/redis.yml @@ -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 diff --git a/lib/potassium/recipes/background_processor.rb b/lib/potassium/recipes/background_processor.rb index f0152036..d39b1ab2 100644 --- a/lib/potassium/recipes/background_processor.rb +++ b/lib/potassium/recipes/background_processor.rb @@ -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 @@ -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")