-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(redis): move redis to its own recipe and install redis-actionpack
- Loading branch information
Showing
5 changed files
with
93 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
class Recipes::Redis < Rails::AppBuilder | ||
def create | ||
add_redis | ||
add_docker_compose_redis_config | ||
set_redis_dot_env | ||
end | ||
|
||
def install | ||
create | ||
end | ||
|
||
def installed? | ||
gem_exists?(/redis-actionpack/) | ||
end | ||
|
||
def add_redis | ||
run_action(:install_redis) do | ||
gather_gem("redis-actionpack") | ||
copy_file("../assets/redis.yml", "config/redis.yml", force: true) | ||
end | ||
end | ||
|
||
private | ||
|
||
def add_docker_compose_redis_config | ||
compose = DockerHelpers.new('docker-compose.yml') | ||
|
||
service_definition = | ||
<<~YAML | ||
image: redis:6.2.12 | ||
ports: | ||
- 6379 | ||
volumes: | ||
- redis_data:/data | ||
YAML | ||
|
||
compose.add_service('redis', service_definition) | ||
compose.add_volume('redis_data') | ||
end | ||
|
||
def set_redis_dot_env | ||
puts "HOLA" | ||
append_to_file( | ||
'.env.development', | ||
<<~TEXT | ||
REDIS_HOST=127.0.0.1 | ||
REDIS_PORT=COMMAND_EXPAND(make services-port SERVICE=redis PORT=6379) | ||
REDIS_URL=redis://${REDIS_HOST}:${REDIS_PORT}/1 | ||
TEXT | ||
) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
require "spec_helper" | ||
require 'yaml' | ||
|
||
RSpec.describe "RedisProcessor" do | ||
before :all do | ||
drop_dummy_database | ||
remove_project_directory | ||
create_dummy_project("heroku" => true) | ||
end | ||
|
||
context "when installed" do | ||
it "adds redis-actionpack gem to Gemfile" do | ||
gemfile_content = IO.read("#{project_path}/Gemfile") | ||
expect(gemfile_content).to include("redis-actionpack") | ||
end | ||
|
||
it "adds ENV vars" do | ||
content = IO.read("#{project_path}/.env.development") | ||
expect(content).to include('REDIS_HOST=127.0.0.1') | ||
expect(content).to include( | ||
'REDIS_PORT=COMMAND_EXPAND(make services-port SERVICE=redis PORT=6379)' | ||
) | ||
expect(content).to include('REDIS_URL=redis://${REDIS_HOST}:${REDIS_PORT}/1') | ||
end | ||
|
||
it "adds redis.yml file" do | ||
content = IO.read("#{project_path}/config/redis.yml") | ||
expect(content).to include("REDIS_URL") | ||
end | ||
|
||
it 'adds redis to docker-compose' do | ||
compose_file = IO.read("#{project_path}/docker-compose.yml") | ||
compose_content = YAML.safe_load(compose_file, symbolize_names: true) | ||
|
||
expect(compose_content[:services]).to include(:redis) | ||
end | ||
end | ||
end |