Skip to content

Commit

Permalink
Merge pull request #132 from foliea/compose-adapt
Browse files Browse the repository at this point in the history
ignore redis config in tests
  • Loading branch information
foliea committed Mar 31, 2015
2 parents cda3b89 + e996603 commit a2d1643
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 13 deletions.
6 changes: 4 additions & 2 deletions config/initializers/redis.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
redis = Redis.new(url: ENV['REDIS_URL'], password: ENV['REDIS_PASSWORD'])
if ENV['RAILS_ENV'] != 'test'
redis = Redis.new(url: ENV['REDIS_URL'], password: ENV['REDIS_PASSWORD'])

$redis = Redis::Namespace.new('grounds', redis: redis)
$redis = Redis::Namespace.new('grounds', redis: redis)
end
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ web:
- TEST_OPTS
- DOCKER_URL
- REDIS_URL
- REDIS_PASSWORD
- RUNNER_URL
- SECRET_KEY_BASE
- NEWRELIC_LICENSE_KEY
Expand Down
27 changes: 16 additions & 11 deletions lib/tasks/run.rake
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ task :run do
sh 'bundle exec rake assets:precompile'
end

set_runner_url
set_redis_url
set_runner
set_redis

sh 'rails server -b 0.0.0.0 -p 3000'
end
Expand All @@ -14,7 +14,7 @@ desc 'Run the test suite with environment properly configured'
task :test do
ENV['RAILS_ENV'] = 'test'

set_runner_url
set_runner

sh "rspec --format documentation --color #{ENV['TEST_OPTS']}"
end
Expand All @@ -23,18 +23,23 @@ def production?
ENV['RAILS_ENV'] == 'production'
end

# Fetch runner url from env (if running natively),
# or look for a runner on the same docker host.
def set_runner_url
# Docker Compose unfortunately sets environment variables inherited
# from the host to an empty string if these are missing in the host
# environment. Therefore we need to set this variables to nil if empty.
# Thanks to rails '.presence' returns nil if the variable is nil or empty.

# Fetch runner url from env (if running natively), or look for a runner on
# the same docker host.
def set_runner
ENV['RUNNER_URL'] = ENV['RUNNER_URL'].presence || docker_url_with(8080)
end

# Fetch redis url from env (if running natively),
# or look for a redis instance linked to this
# container (docker compose now use links name instead
# of environment variables).
def set_redis_url
# Fetch redis url from env (if running natively), or look for a redis instance
# linked to this container (docker compose recommends to use links name instead
# of using docker links environment variables).
def set_redis
ENV['REDIS_URL'] = ENV['REDIS_URL'].presence || 'redis://redis:6379'
ENV['REDIS_PASSWORD'] = ENV['REDIS_PASSWORD'].presence
end

# Parse docker url with a custom port
Expand Down

0 comments on commit a2d1643

Please sign in to comment.