nickjj / orats

Opinionated rails application templates.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Right way of installing a new gem

yannickschuchmann opened this issue · comments

Hey,
everytime I added a new gem to my Gemfile and ran docker-compose exec website bundle install I get the following error for the cable and sidekiq containers:

Your bundle is locked to bcrypt (3.1.11), but that version could not be found in any of the sources listed in your Gemfile.

The Gemfile and Gemfile.lock are shared between website, cable and sidekiq containers while all gems are installed separately on each container.
So I have to bundle install three times, one for each container to get rid of the error messages.

Is there a better way than this? Maybe one solution would be to also share all installed gems between the containers or?

kind regards,
Yannick

Hi,

Yeah, there's a much better way.

Stop your containers and then run docker-compose up --build. Docker will re-build the image and the gem layer will be shared for all 3 images.

Basically, you just need to re-build the image so that the bundle install command in the Dockerfile gets executed. So most of the time you would run docker-compose up, but when you want to install new gems you just add the --build flag.

Thanks for the report, I feel like this should have been explained in the blog post at http://nickjanetakis.com/blog/dockerize-a-rails-5-postgres-redis-sidekiq-action-cable-app-with-docker-compose.

Hey,
re-building the image would be a simple solution, but not if you have to keep an eye on your monthly internet usage. Doesn't re-building throw the current gem layer away?

At my current residence in South Africa I have only a 20gb/month capped internet contract. Sure, this is more likely a personal issue.. 😄

Anyways, thanks for your reply.

Since the gem layer changes (you added a new gem), then yeah bundle install will do a full run.

I'd measure how much bandwidth you use when performing that bundle install from scratch to see how much it really takes. 20gb/month is brutal tho.

Fortunately adding gems isn't something that happens often, so even if you stuck to your triple method it's only a mild inconceivable. If I were you I'd make a simple bash script that runs the command on all 3 containers in 1 shot.

Another less appealing option would be to bundle install locally without Docker (but now you're back to the point where you need Ruby and a Ruby manager on your workstation) and then mount in the gems so you only have to run it once locally.