<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Zack Kollar</title>
    <description>The latest articles on DEV Community by Zack Kollar (@seedyrom).</description>
    <link>https://dev.to/seedyrom</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F126136%2F0579e8b4-d9d2-47af-9396-089c80c0e2a5.jpeg</url>
      <title>DEV Community: Zack Kollar</title>
      <link>https://dev.to/seedyrom</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/seedyrom"/>
    <language>en</language>
    <item>
      <title>How to add a specific version of bundler to your Ruby on Rails Dockerfile</title>
      <dc:creator>Zack Kollar</dc:creator>
      <pubDate>Mon, 01 Feb 2021 09:20:59 +0000</pubDate>
      <link>https://dev.to/seedyrom/how-to-add-a-specific-version-of-bundler-to-your-ruby-dockerfile-5chl</link>
      <guid>https://dev.to/seedyrom/how-to-add-a-specific-version-of-bundler-to-your-ruby-dockerfile-5chl</guid>
      <description>&lt;p&gt;When working on a slightly older Ruby/RoR project, I updated some dependencies (specifically from DependaBot pull requests) and found out that my bundler version was causing some interesting errors. Mostly incompatibility with my &lt;code&gt;Gemfile.lock&lt;/code&gt; and what version it expected for certain deps.&lt;/p&gt;

&lt;p&gt;The error message was instructing me to update my &lt;code&gt;bundler&lt;/code&gt; version locally.&lt;/p&gt;

&lt;p&gt;This however can work for local projects, but when Docker is involved this isn't quite as obvious for us non-monk Ruby devs.&lt;/p&gt;

&lt;h3&gt;
  
  
  Here's your solution:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight docker"&gt;&lt;code&gt;&lt;span class="k"&gt;ENV&lt;/span&gt;&lt;span class="s"&gt; BUNDLER_VERSION='X.X.X'&lt;/span&gt;
&lt;span class="k"&gt;RUN &lt;/span&gt;gem &lt;span class="nb"&gt;install &lt;/span&gt;bundler &lt;span class="nt"&gt;--no-document&lt;/span&gt; &lt;span class="nt"&gt;-v&lt;/span&gt; &lt;span class="s1"&gt;'X.X.X'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Replace &lt;code&gt;X.X.X&lt;/code&gt; with whatever version you require, for me it was &lt;code&gt;2.2.4&lt;/code&gt;. I placed this after my system package installs to &lt;em&gt;possibly&lt;/em&gt; help with image build caching. (&lt;em&gt;This could be entirely wrong as well!&lt;/em&gt;)&lt;/p&gt;

&lt;p&gt;This doesn't just apply to legacy projects or unsupported Docker image bases, this can be super helpful for managing the exact bundler version you require in your toolset.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Here's the final &lt;code&gt;Dockerfile&lt;/code&gt; for my project for reference. &lt;em&gt;I'm using &lt;code&gt;webpacker&lt;/code&gt; for isolated React components and PostCSS magic.&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight docker"&gt;&lt;code&gt;&lt;span class="k"&gt;FROM&lt;/span&gt;&lt;span class="s"&gt; ruby:2.5.1&lt;/span&gt;

&lt;span class="c"&gt;# Replace with whoever you are!&lt;/span&gt;
&lt;span class="k"&gt;LABEL&lt;/span&gt;&lt;span class="s"&gt; maintainer="YOU@YOU.YOU"&lt;/span&gt;

&lt;span class="c"&gt;# Allow apt to work with https-based sources&lt;/span&gt;
&lt;span class="k"&gt;RUN &lt;/span&gt;apt-get update &lt;span class="nt"&gt;-yqq&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; apt-get &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;-yqq&lt;/span&gt; &lt;span class="nt"&gt;--no-install-recommends&lt;/span&gt; &lt;span class="se"&gt;\
&lt;/span&gt;  apt-transport-https

&lt;span class="c"&gt;# Ensure we install an up-to-date version of Node&lt;/span&gt;
&lt;span class="c"&gt;# see https://github.com/yarnpkg/yarn/issues/2888&lt;/span&gt;
&lt;span class="k"&gt;RUN &lt;/span&gt;curl &lt;span class="nt"&gt;-sL&lt;/span&gt; https://deb.nodesource.com/setup_12.x | bash -

&lt;span class="c"&gt;# Ensure latest packages for Yarn&lt;/span&gt;
&lt;span class="k"&gt;RUN &lt;/span&gt;curl &lt;span class="nt"&gt;-sS&lt;/span&gt; https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
&lt;span class="k"&gt;RUN &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"deb https://dl.yarnpkg.com/debian/ stable main"&lt;/span&gt; | &lt;span class="se"&gt;\
&lt;/span&gt;  &lt;span class="nb"&gt;tee&lt;/span&gt; /etc/apt/sources.list.d/yarn.list

&lt;span class="c"&gt;# Convention to use update and install on same line to actually install new packages&lt;/span&gt;
&lt;span class="c"&gt;# We also use the line separation to make this easier to change&lt;/span&gt;
&lt;span class="k"&gt;RUN &lt;/span&gt;apt-get update &lt;span class="nt"&gt;-yqq&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; apt-get &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;-yqq&lt;/span&gt; &lt;span class="nt"&gt;--no-install-recommends&lt;/span&gt; &lt;span class="se"&gt;\
&lt;/span&gt;  nodejs &lt;span class="se"&gt;\
&lt;/span&gt;  yarn

&lt;span class="c"&gt;# Setup our bundler version specifically&lt;/span&gt;
&lt;span class="k"&gt;ENV&lt;/span&gt;&lt;span class="s"&gt; BUNDLER_VERSION='X.X.X'&lt;/span&gt;
&lt;span class="k"&gt;RUN &lt;/span&gt;gem &lt;span class="nb"&gt;install &lt;/span&gt;bundler &lt;span class="nt"&gt;--no-document&lt;/span&gt; &lt;span class="nt"&gt;-v&lt;/span&gt; &lt;span class="s1"&gt;'X.X.X'&lt;/span&gt;

&lt;span class="c"&gt;# Load our Gemfile and JS locks&lt;/span&gt;
&lt;span class="k"&gt;COPY&lt;/span&gt;&lt;span class="s"&gt; Gemfile* $YOUR_APPLICATION_PATH&lt;/span&gt;
&lt;span class="k"&gt;COPY&lt;/span&gt;&lt;span class="s"&gt; package.json $YOUR_APPLICATION_PATH&lt;/span&gt;

&lt;span class="k"&gt;WORKDIR&lt;/span&gt;&lt;span class="s"&gt; $YOUR_APPLICATION_PATH&lt;/span&gt;

&lt;span class="c"&gt;# Install our dependencies&lt;/span&gt;
&lt;span class="k"&gt;ENV&lt;/span&gt;&lt;span class="s"&gt; BUNDLE_PATH /gems&lt;/span&gt;
&lt;span class="k"&gt;RUN &lt;/span&gt;bundle &lt;span class="nb"&gt;install&lt;/span&gt;

&lt;span class="c"&gt;# Handle yarn caching and install deps&lt;/span&gt;
&lt;span class="k"&gt;COPY&lt;/span&gt;&lt;span class="s"&gt; package.json yarn.lock ./&lt;/span&gt;
&lt;span class="k"&gt;RUN &lt;/span&gt;yarn &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;--check-files&lt;/span&gt;

&lt;span class="c"&gt;# Build the static assets and webpack data&lt;/span&gt;
&lt;span class="k"&gt;COPY&lt;/span&gt;&lt;span class="s"&gt; . $YOUR_APPLICATION_PATH&lt;/span&gt;
&lt;span class="k"&gt;RUN &lt;/span&gt;bundle &lt;span class="nb"&gt;exec &lt;/span&gt;rake assets:precompile 

&lt;span class="c"&gt;# Serve the application&lt;/span&gt;
&lt;span class="k"&gt;ENV&lt;/span&gt;&lt;span class="s"&gt; RAILS_SERVE_STATIC_FILES=true&lt;/span&gt;
&lt;span class="k"&gt;ENV&lt;/span&gt;&lt;span class="s"&gt; RAILS_LOG_TO_STDOUT=true&lt;/span&gt;
&lt;span class="k"&gt;CMD&lt;/span&gt;&lt;span class="s"&gt; ["bin/rails", "s", "-b", "0.0.0.0", "-e", "production"]&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I hope somebody struggling with any of these problems finds this! Please feel free to contact me directly if this doesn't work. Also if you're not using webpacker/shakapacker(2022).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Good luck and happy hacking!&lt;/strong&gt;&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
