<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>mina capistrano deployment rails rake ruby on random thoughts</title><link>https://awesomeprogrammer.com/categories/mina-capistrano-deployment-rails-rake-ruby/</link><description>Recent content in mina capistrano deployment rails rake ruby on random thoughts</description><generator>Hugo -- gohugo.io</generator><language>en-us</language><lastBuildDate>Sat, 27 Oct 2012 00:00:00 +0000</lastBuildDate><atom:link href="https://awesomeprogrammer.com/categories/mina-capistrano-deployment-rails-rake-ruby/index.xml" rel="self" type="application/rss+xml"/><item><title>Super fast deployment with mina - capistrano alternative</title><link>https://awesomeprogrammer.com/blog/2012/10/27/super-fast-deployment-with-mina-capistrano-alternative/</link><pubDate>Sat, 27 Oct 2012 00:00:00 +0000</pubDate><guid>https://awesomeprogrammer.com/blog/2012/10/27/super-fast-deployment-with-mina-capistrano-alternative/</guid><description><![CDATA[<p><a href="https://github.com/nadarei/mina">Mina</a> is an interesting alternative for <a href="https://github.com/capistrano/capistrano/">capistrano</a>. It&rsquo;s really tiny, easy to configure and fast as hell. Overall usage is <a href="http://nadarei.co/mina/">very well documented</a>, so to avoid repetition I&rsquo;ll just describe very specific case of deploying rails apps on a shared server through use of a gateway (or whatever you may call it).</p>
<p>So it happens I keep my personal project on ones of those shared servers - it&rsquo;s just cheaper and I don&rsquo;t have to bother with upgrades, system security etc. - assuming my provider knows what he&rsquo;s doing of course ;). I can normally log through ssh on my <em>shell account</em> and then from that machine I can ssh to yet another machine that hosts my sites.</p>
<h3 id="preparing">Preparing</h3>
<p>I assume you already setup password-less login from your machine to your primary server. Now it depends how you login to your secondary (www) server. In my case I had an system alias that logged me into that server using one command, and that alias was just an ssh command pointing to some ip with use of different public key. So first I had to allow simple <em>ssh www-server</em> to work. And you can easily automatically provide key for some host in your ssh configuration:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span><span style="color:#75715e"># ~/.ssh/config</span>
</span></span><span style="display:flex;"><span>Host web-server
</span></span><span style="display:flex;"><span>  IdentityFile /path/to/specific/key
</span></span></code></pre></div><p>After very little configuration you should be able to do: <em>ssh primary-server</em> and from that server <em>ssh web-server</em> without a password.</p>
<h3 id="configuring-mina">Configuring mina</h3>
<p>As I said before - mina has great documentation, so I will just copy my deployment configuration and give you some tips what could go wrong.</p>
<p>Be honest I had some hard time at the beginning, what may seems weird considering what I just said before :P. Ssh&rsquo;ing from one server to another just didn&rsquo;t work as expected and after further investigation it appeared that I got disconnected from web-server after executing first command (the rest of script were executing on shell server or not executing at all - it just hanged)
. What you have to do to fix it is wrap whole executed script in <a href="http://www.techrepublic.com/article/use-heredoc-in-shell-scripts/5733460">heredoc</a>. And that&rsquo;s basically it, except there is a small catch while you are deploying, because there is external script that is loaded just for deployment. It is in <code>mina/data/deploy.sh.erb</code>, so don&rsquo;t bother patching ssh_helper as I did ;-). Script itself loaded in <code>deploy_helpers.rb</code>, so you may want just to modify and include this updated file in your deploy.rb, or you may want fork the project and made your own modifications. Whatever solution you choose it the end you should wrap it all within something like:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span><span style="color:#e6db74">&lt;&lt;&#39;ENDSSH&#39;
</span></span></span><span style="display:flex;"><span><span style="color:#e6db74"># you custom taks(s), commands or the whole deploy script
</span></span></span><span style="display:flex;"><span><span style="color:#e6db74">ENDSSH</span>
</span></span></code></pre></div><p>And here is my (still very fresh - so expect update in the future) deploy file configuration:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-ruby" data-lang="ruby"><span style="display:flex;"><span><span style="color:#75715e"># config/deploy.rb</span>
</span></span><span style="display:flex;"><span>require <span style="color:#e6db74">&#39;mina/git&#39;</span>
</span></span><span style="display:flex;"><span>require <span style="color:#e6db74">&#39;mina/rails&#39;</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>set <span style="color:#e6db74">:domain</span>, <span style="color:#e6db74">&#39;mydomain.net&#39;</span>
</span></span><span style="display:flex;"><span>set <span style="color:#e6db74">:user</span>, <span style="color:#e6db74">&#39;user&#39;</span>
</span></span><span style="display:flex;"><span>set <span style="color:#e6db74">:deploy_to</span>, <span style="color:#e6db74">&#39;/my/path&#39;</span>
</span></span><span style="display:flex;"><span>set <span style="color:#e6db74">:repository</span>, <span style="color:#e6db74">&#39;git@myrepo.git&#39;</span>
</span></span><span style="display:flex;"><span>set <span style="color:#e6db74">:branch</span>, <span style="color:#e6db74">&#39;master&#39;</span>
</span></span><span style="display:flex;"><span>set <span style="color:#e6db74">:current_path</span>, <span style="color:#e6db74">&#39;custom-current-directory&#39;</span>
</span></span><span style="display:flex;"><span>set <span style="color:#e6db74">:shared_paths</span>, <span style="color:#f92672">[</span><span style="color:#e6db74">&#39;.bundle&#39;</span>, <span style="color:#e6db74">&#39;config/email.yml&#39;</span>, <span style="color:#e6db74">&#39;config/database.yml&#39;</span>, <span style="color:#e6db74">&#39;public/system&#39;</span>, <span style="color:#e6db74">&#39;log&#39;</span>, <span style="color:#e6db74">&#39;tmp&#39;</span><span style="color:#f92672">]</span>
</span></span><span style="display:flex;"><span>set <span style="color:#e6db74">:ssh_options</span>, <span style="color:#e6db74">&#39;-A -t ssh -A user@www-server.net&#39;</span>
</span></span><span style="display:flex;"><span>set <span style="color:#e6db74">:term_mode</span>, <span style="color:#66d9ef">nil</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>task <span style="color:#e6db74">:deploy</span> <span style="color:#66d9ef">do</span>
</span></span><span style="display:flex;"><span>  deploy <span style="color:#66d9ef">do</span>
</span></span><span style="display:flex;"><span>    invoke <span style="color:#e6db74">:&#39;git:clone&#39;</span>
</span></span><span style="display:flex;"><span>    invoke <span style="color:#e6db74">:&#39;deploy:link_shared_paths&#39;</span>
</span></span><span style="display:flex;"><span>    queue <span style="color:#e6db74">&#34;bundle install&#34;</span>
</span></span><span style="display:flex;"><span>    invoke <span style="color:#e6db74">:&#39;rails:db_migrate&#39;</span>
</span></span><span style="display:flex;"><span>    invoke <span style="color:#e6db74">:&#39;rails:assets_precompile&#39;</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>    to <span style="color:#e6db74">:launch</span> <span style="color:#66d9ef">do</span>
</span></span><span style="display:flex;"><span>      queue <span style="color:#e6db74">&#39;touch tmp/restart.txt&#39;</span>
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">end</span>
</span></span><span style="display:flex;"><span>  <span style="color:#66d9ef">end</span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">end</span>
</span></span></code></pre></div><p>Note that I don&rsquo;t use provided bundle:install command – instead I&rsquo;m linking my custom bundler configuration. I&rsquo;m aware this is very specific configuration with some weird workarounds, moreover if you&rsquo;re planning of using whole tasks I just recommend forking the project on github and adjusting it to your needs.</p>]]></description><content:encoded><![CDATA[<p><a href="https://github.com/nadarei/mina">Mina</a> is an interesting alternative for <a href="https://github.com/capistrano/capistrano/">capistrano</a>. It&rsquo;s really tiny, easy to configure and fast as hell. Overall usage is <a href="http://nadarei.co/mina/">very well documented</a>, so to avoid repetition I&rsquo;ll just describe very specific case of deploying rails apps on a shared server through use of a gateway (or whatever you may call it).</p>
<p>So it happens I keep my personal project on ones of those shared servers - it&rsquo;s just cheaper and I don&rsquo;t have to bother with upgrades, system security etc. - assuming my provider knows what he&rsquo;s doing of course ;). I can normally log through ssh on my <em>shell account</em> and then from that machine I can ssh to yet another machine that hosts my sites.</p>
<h3 id="preparing">Preparing</h3>
<p>I assume you already setup password-less login from your machine to your primary server. Now it depends how you login to your secondary (www) server. In my case I had an system alias that logged me into that server using one command, and that alias was just an ssh command pointing to some ip with use of different public key. So first I had to allow simple <em>ssh www-server</em> to work. And you can easily automatically provide key for some host in your ssh configuration:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span><span style="color:#75715e"># ~/.ssh/config</span>
</span></span><span style="display:flex;"><span>Host web-server
</span></span><span style="display:flex;"><span>  IdentityFile /path/to/specific/key
</span></span></code></pre></div><p>After very little configuration you should be able to do: <em>ssh primary-server</em> and from that server <em>ssh web-server</em> without a password.</p>
<h3 id="configuring-mina">Configuring mina</h3>
<p>As I said before - mina has great documentation, so I will just copy my deployment configuration and give you some tips what could go wrong.</p>
<p>Be honest I had some hard time at the beginning, what may seems weird considering what I just said before :P. Ssh&rsquo;ing from one server to another just didn&rsquo;t work as expected and after further investigation it appeared that I got disconnected from web-server after executing first command (the rest of script were executing on shell server or not executing at all - it just hanged)
. What you have to do to fix it is wrap whole executed script in <a href="http://www.techrepublic.com/article/use-heredoc-in-shell-scripts/5733460">heredoc</a>. And that&rsquo;s basically it, except there is a small catch while you are deploying, because there is external script that is loaded just for deployment. It is in <code>mina/data/deploy.sh.erb</code>, so don&rsquo;t bother patching ssh_helper as I did ;-). Script itself loaded in <code>deploy_helpers.rb</code>, so you may want just to modify and include this updated file in your deploy.rb, or you may want fork the project and made your own modifications. Whatever solution you choose it the end you should wrap it all within something like:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span><span style="color:#e6db74">&lt;&lt;&#39;ENDSSH&#39;
</span></span></span><span style="display:flex;"><span><span style="color:#e6db74"># you custom taks(s), commands or the whole deploy script
</span></span></span><span style="display:flex;"><span><span style="color:#e6db74">ENDSSH</span>
</span></span></code></pre></div><p>And here is my (still very fresh - so expect update in the future) deploy file configuration:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-ruby" data-lang="ruby"><span style="display:flex;"><span><span style="color:#75715e"># config/deploy.rb</span>
</span></span><span style="display:flex;"><span>require <span style="color:#e6db74">&#39;mina/git&#39;</span>
</span></span><span style="display:flex;"><span>require <span style="color:#e6db74">&#39;mina/rails&#39;</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>set <span style="color:#e6db74">:domain</span>, <span style="color:#e6db74">&#39;mydomain.net&#39;</span>
</span></span><span style="display:flex;"><span>set <span style="color:#e6db74">:user</span>, <span style="color:#e6db74">&#39;user&#39;</span>
</span></span><span style="display:flex;"><span>set <span style="color:#e6db74">:deploy_to</span>, <span style="color:#e6db74">&#39;/my/path&#39;</span>
</span></span><span style="display:flex;"><span>set <span style="color:#e6db74">:repository</span>, <span style="color:#e6db74">&#39;git@myrepo.git&#39;</span>
</span></span><span style="display:flex;"><span>set <span style="color:#e6db74">:branch</span>, <span style="color:#e6db74">&#39;master&#39;</span>
</span></span><span style="display:flex;"><span>set <span style="color:#e6db74">:current_path</span>, <span style="color:#e6db74">&#39;custom-current-directory&#39;</span>
</span></span><span style="display:flex;"><span>set <span style="color:#e6db74">:shared_paths</span>, <span style="color:#f92672">[</span><span style="color:#e6db74">&#39;.bundle&#39;</span>, <span style="color:#e6db74">&#39;config/email.yml&#39;</span>, <span style="color:#e6db74">&#39;config/database.yml&#39;</span>, <span style="color:#e6db74">&#39;public/system&#39;</span>, <span style="color:#e6db74">&#39;log&#39;</span>, <span style="color:#e6db74">&#39;tmp&#39;</span><span style="color:#f92672">]</span>
</span></span><span style="display:flex;"><span>set <span style="color:#e6db74">:ssh_options</span>, <span style="color:#e6db74">&#39;-A -t ssh -A user@www-server.net&#39;</span>
</span></span><span style="display:flex;"><span>set <span style="color:#e6db74">:term_mode</span>, <span style="color:#66d9ef">nil</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>task <span style="color:#e6db74">:deploy</span> <span style="color:#66d9ef">do</span>
</span></span><span style="display:flex;"><span>  deploy <span style="color:#66d9ef">do</span>
</span></span><span style="display:flex;"><span>    invoke <span style="color:#e6db74">:&#39;git:clone&#39;</span>
</span></span><span style="display:flex;"><span>    invoke <span style="color:#e6db74">:&#39;deploy:link_shared_paths&#39;</span>
</span></span><span style="display:flex;"><span>    queue <span style="color:#e6db74">&#34;bundle install&#34;</span>
</span></span><span style="display:flex;"><span>    invoke <span style="color:#e6db74">:&#39;rails:db_migrate&#39;</span>
</span></span><span style="display:flex;"><span>    invoke <span style="color:#e6db74">:&#39;rails:assets_precompile&#39;</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>    to <span style="color:#e6db74">:launch</span> <span style="color:#66d9ef">do</span>
</span></span><span style="display:flex;"><span>      queue <span style="color:#e6db74">&#39;touch tmp/restart.txt&#39;</span>
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">end</span>
</span></span><span style="display:flex;"><span>  <span style="color:#66d9ef">end</span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">end</span>
</span></span></code></pre></div><p>Note that I don&rsquo;t use provided bundle:install command – instead I&rsquo;m linking my custom bundler configuration. I&rsquo;m aware this is very specific configuration with some weird workarounds, moreover if you&rsquo;re planning of using whole tasks I just recommend forking the project on github and adjusting it to your needs.</p>]]></content:encoded></item></channel></rss>