Use zeus with Rails 3 and docker - ruby-on-rails

We have a Rails 3.2.9 app, and recently switched to Docker in development. By now, I've always used zeus local on my machine to preload my codebase and execute tests with Rspec faster.
But how would you achieve this with docker? When I try to install zeus inside my container with gem install zeus and start it with zeus start I get
Unable to accept socket connection.
It looks like Zeus is already running. If not, remove .zeus.sock and try again.
And there is a .zeus.soc (notice the missing k at the end) left in my filesystem.
Has anybody got this working with Docker?

Apparently zeus is not able to create the .zeus.sock file on the vboxsf filesystem used by VirtualBox for sharing a volume with the host. So a solution is to tell Zeus explicitely to create the file somewhere else by setting the ZEUSSOCK environment variable. This is discussed here: https://github.com/burke/zeus/issues/488

Related

RubyMine RSpec run configuration with Dockerized Zeus

Context
I'm Dockerizing the development environment for a legacy Rails monolith, using a Dockerfile written for local env + docker-compose using that image to start different services.
Goal
I would like to run specs from RubyMine with just cmd+shift+R using Zeus - as it takes forever without.
Attempt
I have a service called test which starts zeus. Now if I do docker-compose exec test zeus rspec ./spec/dummy_spec.rb it runs very nicely and quickly.
I can not figure out how to tell RubyMine to do just that. It'd be best if debugger would also just work as if I were running things locally.
(I can run the spec with a remote interpreter, so that part is clear, but without Zeus it takes forever like I said.)
Question
Obviously, I'd like to know how to achieve my goal or hear about the best alternatives. :)

`rails console` hangs when using vendored gems (running in docker)

I'm running into a strange issue trying to dockerize a (fairly large) rails app. I'm using the official ruby docker image for now, and mounting my code into the app. Using:
docker pull ruby:2.2.4
docker run -it -v $PWD:/code ruby:2.2.4 bash
Then in the container I ran:
cd /code
bundle install
rails c
This works fine (I can't connect to the database obviously since I didn't link it, but rails console otherwise runs normally and loads my app).
However, when I instead run bundle install --deployment, then running rails c just hangs forever.
Any idea what could cause this?
I was hoping to use a local copy of gems, because we're also using a bunch of npm modules (which install locally into node_modules) so I figured keeping gems in the local directory as well is the most straightforward and has the same persistence between docker runs in the development environment.
Nevermind I figured it out - it's not completely hanging just going really really slow thanks to Virtualbox's default type of shared drive. The code is on my OSX filesystem, mounted as a shared drive into Virtualbox (using vagrant), and then mounted as a volume into docker. When the gems are installed into vendor/bundle they all have to be loaded from this slow volume and there are ~150 gems total with all the dependencies.
root#fa575694f86a:/code# time echo puts :ok | rails c
Loading development environment (Rails 4.2.1)
Switch to inspect mode.
irb: warn: can't alias context from irb_context.
puts :ok
ok
nil
real 2m0.937s
user 0m2.574s
sys 0m59.985s
So it takes 2 whole minutes just to launch rails. I changed vagrant to use an NFS shared volume, and that brings the launch time down to ~12 seconds (literally 10x faster, I'd heard of NFS being 2x faster but this is pretty crazy). Using just bundle install to install the gems globally there's no penalty, it's the usual 3-4 second rails load time which is the same thing I get running in OSX.

How to run initialization script on starting a Rails server?

I have a simple shell script (happy.sh) that I am currently running by hand (. ./happy.sh) every time I restart a rails server. It sets some environment variables that I need because of various APIs I'm using. However, I was wondering if there's some way of having rails run the script itself whenever I run "guard" or "rails s"
Thanks
If you use foreman, you can define all processes you needed started on application start into a Procfile. (including bbundle exec rails server -p $PORT)
By calling foreman start, all the process starts up.
More information can be gotten here on this cast
Proper way of setting ENV variables is putting them in bash_proflle or bashrc depending of linux distro.
vi ~/.bash_proflle
And then add something like
export MY_RAILS_VAR=123
Then you don't need to run any ENV initialization scripts on rails start.

Ruby on Rails: How to start the WEBrick server automatically on Windows in background?

In order to run the my Rails application on Windows XP I open a command line, cd to application's directory, and then run rails server.
I would like to automate this, such that every time I turn on my computer, all I'll have to do is to type localhost:3000 in a browser.
How could I do this ?
The simpler way is to create a batch file with the instruction what you give in the command prompt like
d:
cd projects\myapp
ruby script\server
and then drop a copy of the file to Windows Start -> All Programs -> start up folder.
You have few possibilities to do that.
using the registry you can use HKLM\Software\Microsoft\Windows\CurrentVersion\Run or the better approach would be to create a service, you can see this KB with some instruction how to make a service of whatever executable you want.
have you thought about , AUTOEXEC.BAT or creating some batch files. you create right cmd commands that are run at start up. http://www.aumha.org/a/batches.php
The best approach is turn your application into a service. There is a solution for Mongrel (a web server similar to webrick) called mongrel_service, but is not compatible with Rails 3 (due several changes of Rails internals)
However, you can repurpose mongrel_service codebase to work with thin, another webserver that works with Rails 3.
Please look here where is the only reference to mongrel_service script. changing it to thin start could work.
Perhaps is not the answer you're looking for (as there is some work to be done) but is something :)
start rubyw script/rails server webrick
start -> start in another console
rubyw -> run ruby detached from console

Daemon Start at the application bootup

I have a daemon that should run behind my rails app doing db modifications.I implemented that daemon using ruby daemons gem. I want to start that daemon at the start of my app. Whenever my app starts, I need to start that daemon.
How can I do this..?
If you must start it during Rails initialization:
Create a ruby file that will start the daemon. Say invoke_daemon.rb
Put this file in config/initializers/invoke_daemon.rb
However if it isn't mandatory, I would suggest creating a binary executable or a rake task and manually starting it through command line. This way it runs as a separate process. You can simply add it to your deployment scripts for production boxes and on development box run it manually. A few examples would be searchd, the search daemon for sphinx and thinking_sphinx:delayed_delta rake task from thinking_sphinx.
For your knowledge you have to take look of
Rails Life cycle
I have just implemented this thing. I have implemented on Windows7.
I have created one batch file let's say my_batch.bat, which contains ruby command i.e. ruby my_daemon.rb file.
In addition, to execute this file when my app starts , I have just added one statement in environment.rb file which executes that batch file. i.e. system ("my_batch.bat").
But I am not sure that this is a good way to implement this task.

Resources