nickjj / orats

Opinionated rails application templates.
MIT License
664 stars 56 forks source link

Right way of installing a new gem #16

Closed yannickschuchmann closed 8 years ago

yannickschuchmann commented 8 years ago

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

nickjj commented 8 years ago

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.

yannickschuchmann commented 8 years ago

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.

nickjj commented 8 years ago

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.