<?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: Khamsouk Souvanlasy</title>
    <description>The latest articles on DEV Community by Khamsouk Souvanlasy (@kam).</description>
    <link>https://dev.to/kam</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.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F90562%2F5d7ea1e3-3638-4e10-83b7-1babceac24f4.png</url>
      <title>DEV Community: Khamsouk Souvanlasy</title>
      <link>https://dev.to/kam</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/kam"/>
    <language>en</language>
    <item>
      <title>Deploying a Project to Heroku that uses a Private Ruby Gem Repo on Gitlab</title>
      <dc:creator>Khamsouk Souvanlasy</dc:creator>
      <pubDate>Mon, 25 Nov 2019 13:41:23 +0000</pubDate>
      <link>https://dev.to/kam/deploying-a-project-to-heroku-that-uses-a-private-gem-on-gitlab-4d56</link>
      <guid>https://dev.to/kam/deploying-a-project-to-heroku-that-uses-a-private-gem-on-gitlab-4d56</guid>
      <description>&lt;p&gt;On a recent Ruby on Rails project deployed on Heroku, I needed to require a privately hosted gem on Gitlab. Without the proper authentication with Gitlab, this will result in the following errors trying to push to Heroku.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;remote:        fatal: could not read Username for 'https://gitlab.com': No such device or address
remote:        
remote:        Git error: command `git clone 'https://gitlab.com/YOUR_ACCOUNT/YOUR_GEM.git'

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

&lt;/div&gt;



&lt;p&gt;To get this working, we need to provide authentication details to Bundler. We'll do this using Gitlab's Personal Access Tokens.&lt;/p&gt;

&lt;h2&gt;
  
  
  Create a Personal Access Token on Gitlab
&lt;/h2&gt;

&lt;p&gt;First you need to navigate to &lt;a href="https://gitlab.com/profile/personal_access_tokens"&gt;https://gitlab.com/profile/personal_access_tokens&lt;/a&gt; and create a token with &lt;code&gt;read_repository&lt;/code&gt; access.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--_ap30C7b--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/92v3h62u5q6bhzliht6a.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--_ap30C7b--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/92v3h62u5q6bhzliht6a.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;You will see this token once, so be sure to save it somewhere secure.&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Configure Bundler to use your Token
&lt;/h2&gt;

&lt;p&gt;You could add the following in your Gemfile:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="n"&gt;gem&lt;/span&gt; &lt;span class="s1"&gt;'YOUR_GEM'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;git: &lt;/span&gt;&lt;span class="s2"&gt;"https://oauth2:YOUR_TOKEN@gitlab.com/YOUR_ACCOUNT/YOUR_GEM.git"&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;However, that would be exposing your access token in your main project's Git repository. Instead, you can set a bundler config variable and leave the entry in your Gemfile as:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="n"&gt;gem&lt;/span&gt; &lt;span class="s1"&gt;'YOUR_GEM'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;git: &lt;/span&gt;&lt;span class="s2"&gt;"https://gitlab.com/YOUR_ACCOUNT/YOUR_GEM.git"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Local Config
&lt;/h3&gt;

&lt;p&gt;To do it locally in your project:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;bundle config &lt;span class="nt"&gt;--local&lt;/span&gt; gitlab.com oauth2:YOUR_TOKEN
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will set a variable in &lt;code&gt;.bundle/config&lt;/code&gt; that bundler will use to authenticate with Gitlab.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;BUNDLE_GITLAB__COM: &lt;span class="s2"&gt;"oauth2:YOUR_TOKEN"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Make sure that the &lt;code&gt;.bundle&lt;/code&gt; directory is added to your &lt;code&gt;.gitignore&lt;/code&gt; file so this isn't stored in your repo.&lt;/p&gt;

&lt;h3&gt;
  
  
  Heroku Config
&lt;/h3&gt;

&lt;p&gt;Heroku supports the above bundler configuration feature as environment variables. Simply add your Gitlab token using the following command (&lt;em&gt;note: this will restart your app!&lt;/em&gt;):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;heroku config:add &lt;span class="nv"&gt;BUNDLE_GITLAB__COM&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;oauth2:YOUR_TOKEN
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Deploy to Heroku
&lt;/h2&gt;

&lt;p&gt;Now that it's all setup, deploy away!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git push heroku master
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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