How to ignore a Gemfile when building a site

Hi folx!

I’m attempting to deploy my Storybook documentation from a repository that contains a mix of JS and Ruby.

I’m using the following command in my package.json file to generate the documentation into its own folder:

"scripts": {
  "build-storybook": "build-storybook -c .storybook"
}

This works great locally, but unfortunately when Netlify attempts to build the probject, it fails when attempting to install all the Ruby dependencies from my Gemfile. I don’t need any of that to happen since I just want to run a Yarn/NPM script.

Is there a way to skip installing a project’s Gemfile?

hmm, maybe this is too simple, but what happens if you just don’t include it in the repo that you push?

@perry removing the Gemfile works, so we know that’s definitely the problem! I can’t remove that from source control permanently, though. Is there a way to tell Netlify’s robots to ignore a file?

The build command runs after bundle install so I wouldn’t be able to delete the Gemfile there.

Hi @maxime, you can’t currently ignore the GemFile. Have you considered removing the Gem’s as part of your build process? You can change your build command to something similar to:

gem uninstall --all && npm run build

Note that in the future we plan on adding the ability to skip installing dependencies, but that functionality isn’t available yet and I don’t have a timeline as to when it will be.

Hey @futuregerald, this unfortunately doesn’t work. See my previous message:

The build command runs after bundle install so I wouldn’t be able to delete the Gemfile there.

Good to know this is something Netlify will support this in the future! For the moment, I’ve moved my site into a different repository, but that’s not ideal.

1 Like

We have the same issue. Our builds fail because it tries to install Ruby gems although it is not necessary to install them for our frontend app. This is a mono-repo where all files are in the same base/root directory. So setting a different base dir for deploys wont work for us.

It would be very much appreciated to be able to overwrite the install step in the netlify.toml file.

Installing hundreds of gems just to not use them seems a bit arkward, also currently they completey fail for missing C bindings (postgresql and such).

Again: We do not need those gems at all for our frontend NuxtJS app. It is nice that Netlify thinks - “oh a Gemfile lets install gems” - but it is also mandatory for developers to be able to overwrite the “install dependencies” step.

Please help asap, we just opened a business account just to encounter that this vital part is not controllable by us.

Thanks for your help.

Another way to help us sovling this issue would be to lets us define our own Docker image to build the site. But this does not seem to be working either?

We have no intention to ever allow specification of your own Docker image - you may want a different CI service if that is your need, @tvdeyen.

Apologies - didn’t see that both questions were from you. There is literally no way at present to change that behavior in a direct, straightforward way, and I am not sure we’ll provide one soon.

As far as workarounds, you could set the base to a subdirectory, and then change back up out of it to do your build? Something like:

[build]
  base = "subdirectory"
  command = "cd .. && npm install && npm run build"
  ignore = "false"

might do the trick, though we won’t cache your dependencies at all, it’s probably better than your site not building!

PS: If you have a business account, pinging us in the helpdesk will get you much faster support during the week - drop us a line at support@netlify.com from your netlify login email (shown at https://app.netlify.com/user/settings)

As far as workarounds, you could set the base to a subdirectory, and then change back up out of it to do your build?

Thanks for the answer.

As I wrote, the install step is failing due to lack of libraries on your build images. We never reach the build step. I understand that providing those libraries is not possible and we actually do not need them, if the install step would not assume, Gemfile -> bundler first. If it at least would assume package.json -> npm it would help.

Couldn’t you let people decide which install strategy to use as you let people decide which OS to build with? It should be easy to allow choosing an install strategy in the build settings:

  • automatic (the default)
  • npm
  • bundler
  • etc.

Or at least you could change the order of strategies for now:

  • package.json? -> npm
  • Gemfile? -> bundler
  • etc.

It is not much you would need to do to support paying customers like us.

That would be very much appreciated.

Thanks

As I tried to describe, if you don’t start the build in the directory with your Gemfile, we won’t try to bundle install, and thus the lack of libraries won’t matter :wink:

Your suggestions are great! But they will not be implemented tomorrow and presumably you’d like your site to start building ASAP.

I’ll get them in front of the team working on our builds so they are aware of your very thoughtful and valid feedback. But since I am not writing or deploying changes to our system, I am trying to help you get things working today :slight_smile:

I found a much easier way to skip bundle install during install phase.

# Gemfile
return true if ENV['NETLIFY']
...

at the top of your Gemfile will early exit bundle install on all Netlify builds. No customization of builds necessary, it just skips over and continues with yarn install.

Still I think that the ability to customize the install step would be beneficial for lots of projects.

That is a great trick that I had no idea would work. Kudos for finding and sharing!

I agree with your assertion and our team is working towards a more flexible build architecture

1 Like