<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
	<channel>
		<title><![CDATA[Rails Forum - Ruby on Rails Help and Discussion Forum - Best practices for open sourcing your rails app and using git]]></title>
		<link>http://railsforum.com/viewtopic.php?id=39909</link>
		<description><![CDATA[The most recent posts in Best practices for open sourcing your rails app and using git.]]></description>
		<lastBuildDate>Thu, 03 Jan 2013 17:42:07 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: Best practices for open sourcing your rails app and using git]]></title>
			<link>http://railsforum.com/viewtopic.php?pid=158012#p158012</link>
			<description><![CDATA[<p>I&#039;ve handled secrets on Heroku using Heroku&#039;s config variables.&nbsp; This requires tweaking the Rails configuration code to read an environment variable, and then setting the environment variable in production and development.</p><p>In the rails configuration:</p><div class="codebox"><pre><code>config.secret_token = ENV[&#039;MYAPP_SECRET_TOKEN&#039;]</code></pre></div><p>You could improve that by, for example, raising an exception if the environment variable is empty.</p><p>Then, to configure your Heroku app, run the heroku config command:</p><div class="codebox"><pre><code>$ heroku config:set MYAPP_SECRET_TOKEN=some-random-secret</code></pre></div><p>In a development environment, simply set the environment variable in your shell:</p><div class="codebox"><pre><code>$ export MYAPP_SECRET_TOKEN=some-random-secret</code></pre></div><p>If you have many variables, you might wish to save the export command(s) in a file that is gitignored and source it:</p><div class="codebox"><pre><code>$ source secret_variables.sh</code></pre></div><p>Since the secrets are never checked in anywhere, you eliminate the risk of accidentally merging them into the wrong branch.</p>]]></description>
			<author><![CDATA[dummy@example.com (marcelcary)]]></author>
			<pubDate>Thu, 03 Jan 2013 17:42:07 +0000</pubDate>
			<guid>http://railsforum.com/viewtopic.php?pid=158012#p158012</guid>
		</item>
		<item>
			<title><![CDATA[Best practices for open sourcing your rails app and using git]]></title>
			<link>http://railsforum.com/viewtopic.php?pid=127637#p127637</link>
			<description><![CDATA[<p>I want to:</p><p>* Use git as my version control<br />* Work in development branches and merge them into master<br />* Frequently push changes to a public, open source git repository (eg Github)<br />* Be able to deploy to Heroku</p><p>The problem:</p><p>By default, any secrets (eg &quot;config/initializers/secret_token.rb&quot;) are present in my repository. Simply including them in .gitignore makes deploying to Heroku difficult, as Heroku needs to compile their slug from a branch of my git repository (and those secret files need to be present).</p><p>Looking at this link (<a href="http://groups.google.com/group/heroku/browse_thread/thread/d7b1aecb42696568/26d5249204c70574">http://groups.google.com/group/heroku/b &#133; 9204c70574</a>), the solution is to include secret files in the .gitignore of the Master branch, and then create a Deploy branch that does not ignore secret files. You work in Master, and then when you&#039;re ready to deploy, you do the following:</p><div class="codebox"><pre><code>git checkout deploy
git merge master
git push heroku deploy:master</code></pre></div><p>This seems like an ok solution, but breaks when you want to work on a local server. Because your Master or Development/Topic branches do not include and secret files, running:</p><div class="codebox"><pre><code>rails server</code></pre></div><p>Will produce the following error:</p><div class="codebox"><pre><code>A secret is required to generate an integrity hash for cookie session data. Use config.secret_token = &quot;some secret phrase of at least 30 characters&quot;in config/application.rb</code></pre></div><p>I can&#039;t just checkout the Deploy branch, because then I won&#039;t be able to edit code while the server is running.</p><p>So my solution for now is to have a Master branch that contains everything (plus other development branches) and then a Public branch created like so:</p><div class="codebox"><pre><code>git checkout -b public
git rm some_secret_file
git filter-branch --index-filter &#039;git update-index --remove some_secret_file&#039; public
echo &quot;some_secret_file&quot; &gt;&gt; .gitignore
git add .gitignore
git commit -m &quot;remove secret files&quot;
git remote add origin git@git.......
git push origin public</code></pre></div><p>Then when hacking away:</p><div class="codebox"><pre><code>git checkout master
do something nifty
git add something
git commit -m &quot;add something nifty&quot;
git checkout public
git merge master
git push origin publich</code></pre></div><p>I think this basically solves the problem, but I&#039;m concerned that if I ever modify .gitignore in master and then merge it into public that the secret files will some sneak on to Github.</p><p>This scenario seems common, but I have yet to find any information on it. Does this setup seem reasonable? Has anyone found a better way to do this?</p><p>Thanks much!</p>]]></description>
			<author><![CDATA[dummy@example.com (th.edore)]]></author>
			<pubDate>Sun, 11 Jul 2010 21:23:59 +0000</pubDate>
			<guid>http://railsforum.com/viewtopic.php?pid=127637#p127637</guid>
		</item>
	</channel>
</rss>
