ledermann/docker-rails-base

Local Path Gems

Aubermean opened this issue · 2 comments

First up I have to say a thank you for making a great Rails 7 template! What a gentleman for open sourcing all your hard work!

In my project, I install some gems from local path, e.g.:

gem 'awesome_client', path: './vendor/gems/awesome_client'

I was wondering what is the best practice for handling this, so that issues are not raised when trying to docker-compose up.

2.085 Fetching gem metadata from https://rubygems.org/......
32.84 The path `/app/vendor/gems/awesome_client ` does not exist.
------
failed to solve: process "/bin/sh -c bundle config --local without 'development test' &&             bundle install -j4 --retry 3 &&             bundle exec bootsnap precompile --gemfile || true &&             bundle clean --force &&             rm -rf /usr/local/bundle/cache &&             find /usr/local/bundle/gems/ -name \"*.c\" -delete &&             find /usr/local/bundle/gems/ -name \"*.o\" -delete" did not complete successfully: exit code: 13

I saw that only the app directory was copied, so I thought that might be the issue. I tried adding this to the Dockerfile with no success:

RUN mkdir -p /app/vendor/gems

# Copy each gem individually
COPY ./vendor/gems/awesome_client /app/vendor/gems/awesome_client

As knowledgeable as you are, I am sure you can give some guidance on best practices for handing this case with your template/framework. Thank you!

Thanks for the kind words :)

I think the problem is, that the Dockerfile includes this lines:

ONBUILD COPY Gemfile* /app/
ONBUILD RUN bundle install 

https://github.com/ledermann/docker-rails-base/blob/main/Builder/Dockerfile#L42-L45

While installing the gems, the vendor/ folder does not exist, so installing fails.
Maybe this could be fixed by copying the vendor folder into the image before running bundle install. But I have not tried this.

I saw that only the app directory was copied [...]

Note that this is the folder structure:

app/
-- app/
-- bin/
-- config/
-- db/
-- lib/
-- views/
...

So /app is the folder where the whole Rails application lives in the Alpine based image - which itself includes a folder called app.

I fixed this in 9fa5bc8 by copying the vendor/ folder as described above.

The downside is that any change in the vendor/ folder will cause bundle install to run again. I think this is acceptable. In most Rails apps these days, where the vendor/ folder is empty, this doesn't change anything.