Closed IrvanFza closed 5 months ago
I also run my application inside docker. I'm using this in the configuration to set a Redis URL inside the docker environment:
RailsPerformance.setup do |config|
redis = Redis.new URL: "redis://redis" # <-- Your internal docker address for Redis goes here
config.redis = Redis::Namespace.new("#{Rails.env}-rails-performance", redis: redis)
# ...
end
@ekampp can't suggest anything, I don't have docker installed on my machine. It would be great if you can prepare a fix and send a PR with it
The above configuration works for me in docker. If configured, it should already work, and no fix is required.
@igorkasyanchuk The issue described here is not about the url for redis but about the creation of the image. If you create an image for an rails app you sometimes call some kind of rake command. The problem here is that this invokes the rails_performance gem which wants to start and searches for a redis. The problem is not that no redis is found (which is expected during image creation) but that the gem starts on the rake command rather than on the rails server command. In the end the gem should only start when the application is started and not when any rake command is executed.
The workaround is to enable the gem via env variable and only set it when starting the image/container.
yes, because gem tracks rake command execution.
a possible long-term solution can be to make it configurable.
short-term for you if you override "https://github.com/igorkasyanchuk/rails_performance/blob/master/lib/rails_performance/gems/rake_ext.rb"
and make methods empty, so nothing will happen
I ended up implementing a similar workaround as Irvan, just wanted to clarify that this is still an issue when creating an image. Adding a config would be great.
added a new config include_rake_tasks
(by default false)
so I think if you just upgrade gem this issue won't happen
@igorkasyanchuk The config fixes the issue, thank you!
When using Docker, this gem always runs invoke rake command in
lib/rails_performance/gems/rake_ext.rb:30
before the version is created. This makes it cannot read the Redis configuration specified in the envar config, so it always return the default host and port.I suspect the code in https://github.com/igorkasyanchuk/rails_performance/blob/master/lib/rails_performance/engine.rb#L60-L62 that caused this.
My workaround is to read an envar config to enable this gem before any other config like so:
And inject the
ENV['RAILS_PERFORMANCE_ENABLED']
after the Docker finish creating the version and start the rails server like so.If this issue is not a priority right now or cannot be fixed at the moment, it would be great if my solution can be included in the docs to help anyone that faces the same issue.